CC-4961: Show linking
Refactored some more show instance creation functions
This commit is contained in:
parent
c29e11fa0f
commit
af622eb4b8
|
@ -1310,7 +1310,7 @@ SQL;
|
|||
}
|
||||
}
|
||||
|
||||
Application_Model_Show::populateShowUntil($showId);
|
||||
/*Application_Model_Show::populateShowUntil($showId);*/
|
||||
Application_Model_RabbitMq::PushSchedule();
|
||||
|
||||
return $showId;
|
||||
|
@ -1323,7 +1323,7 @@ SQL;
|
|||
*
|
||||
* @param int $p_showId
|
||||
*/
|
||||
public static function populateShowUntil($p_showId)
|
||||
/*public static function populateShowUntil($p_showId)
|
||||
{
|
||||
$con = Propel::getConnection();
|
||||
$date = Application_Model_Preference::GetShowsPopulatedUntil();
|
||||
|
@ -1344,7 +1344,7 @@ SQL;
|
|||
foreach ($res as $showDaysRow) {
|
||||
Application_Model_Show::populateShow($showDaysRow, $p_populateUntilDateTime);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* We are going to use cc_show_days as a template, to generate Show Instances. This function
|
||||
|
@ -1357,7 +1357,7 @@ SQL;
|
|||
* @param DateTime $p_populateUntilDateTime
|
||||
* DateTime object in UTC time.
|
||||
*/
|
||||
private static function populateShow($p_showDaysRow, $p_populateUntilDateTime)
|
||||
/*private static function populateShow($p_showDaysRow, $p_populateUntilDateTime)
|
||||
{
|
||||
// TODO : use constants instead of int values here? or maybe php will
|
||||
// get enum types by the time somebody gets around to fix this. -- RG
|
||||
|
@ -1371,7 +1371,7 @@ SQL;
|
|||
Application_Model_Show::populateRepeatingShow($p_showDaysRow, $p_populateUntilDateTime, 'P1M');
|
||||
}
|
||||
Application_Model_RabbitMq::PushSchedule();
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Creates a single show instance. If the show is recorded, it may have multiple
|
||||
|
|
|
@ -2,6 +2,14 @@
|
|||
|
||||
class Application_Service_ScheduleService
|
||||
{
|
||||
private $service_show;
|
||||
private $service_showInstances;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service_show = new Application_Service_ShowService();
|
||||
$this->service_showInstances = new Application_Service_ShowInstanceService();
|
||||
}
|
||||
/*
|
||||
* Form stuff begins here
|
||||
* Typically I would keep form creation and validation
|
||||
|
@ -170,27 +178,23 @@ class Application_Service_ScheduleService
|
|||
$showData["add_show_duration"]);
|
||||
|
||||
if ($isAdminOrPM) {
|
||||
$service_show = new Application_Service_ShowService();
|
||||
$service_showInstances = new Application_Service_ShowInstanceService();
|
||||
|
||||
//create ccShow
|
||||
$ccShow = new CcShow();
|
||||
$ccShow = $service_show->setShow($ccShow, $showData);
|
||||
$ccShow = $this->service_show->setShow($ccShow, $showData);
|
||||
$showId = $ccShow->getDbId();
|
||||
|
||||
//create ccShowDay
|
||||
$service_show->createShowDays(
|
||||
//create ccShowDays
|
||||
$this->service_show->createShowDays(
|
||||
$showData, $showId, $user->getId(), $repeatType, $isRecorded);
|
||||
|
||||
//create ccShowRebroadcast
|
||||
$service_show->createShowRebroadcast($showData, $showId, $repeatType, $isRecorded);
|
||||
//create ccShowRebroadcasts
|
||||
$this->service_show->createShowRebroadcasts($showData, $showId, $repeatType, $isRecorded);
|
||||
|
||||
//create ccShowHosts
|
||||
$service_show->createShowHosts($showData, $showId);
|
||||
$this->service_show->createShowHosts($showData, $showId);
|
||||
|
||||
$populateShowsUntil = $service_show->getPopulateShowUntilDateTIme();
|
||||
//create ccShowInstances
|
||||
$service_showInstances->createShowInstances($showId, $populateShowsUntil);
|
||||
$this->service_showInstances->createShowInstances($showId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,85 @@
|
|||
<?php
|
||||
class Application_Service_ShowInstanceService
|
||||
{
|
||||
public function createShowInstances($showId, $populateUntil)
|
||||
private $service_show;
|
||||
const NO_REPEAT = -1;
|
||||
const REPEAT_WEEKLY = 0;
|
||||
const REPEAT_BI_WEEKLY = 1;
|
||||
const REPEAT_MONTHLY_MONTHLY = 2;
|
||||
const REPEAT_MONTHLY_WEEKLY = 3;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
$this->service_show = new Application_Service_ShowService();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Receives a cc_show id and determines whether to create a
|
||||
* single show_instance or repeating show instances
|
||||
*/
|
||||
public function createShowInstances($showId)
|
||||
{
|
||||
$populateUntil = $this->service_show->getPopulateShowUntilDateTIme();
|
||||
|
||||
$showDays = $this->service_show->getShowDays($showId);
|
||||
foreach ($showDays as $day) {
|
||||
switch ($day["repeat_type"]) {
|
||||
case self::NO_REPEAT:
|
||||
$this->createNonRepeatingShowInstance($day, $populateUntil);
|
||||
break;
|
||||
case self::REPEAT_WEEKLY:
|
||||
$this->createRepeatingShowInstances($day, $populateUntil, "P7D");
|
||||
break;
|
||||
case self::REPEAT_BI_WEEKLY:
|
||||
$this->createRepeatingShowInstances($day, $populateUntil, "P14D");
|
||||
break;
|
||||
case self::REPEAT_MONTHLY_MONTHLY:
|
||||
$this->createRepeatingShowInstances($day, $populateUntil, "P1M");
|
||||
break;
|
||||
case self::REPEAT_MONTHLY_WEEKLY:
|
||||
// do something here
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param $showDay
|
||||
* @param $populateUntil
|
||||
*/
|
||||
private function createNonRepeatingShowInstance($showDay, $populateUntil)
|
||||
{
|
||||
$start = $showDay["first_show"]." ".$showDay["start_time"];
|
||||
|
||||
list($utcStartDateTime, $utcEndDateTime) = $this->service_show->createUTCStartEndDateTime(
|
||||
$start, $showDay["duration"], $showDay["timezone"]);
|
||||
|
||||
if ($utcStartDateTime->getTimestamp() < $populateUntil->getTimestamp()) {
|
||||
$currentUtcTimestamp = gmdate("Y-m-d H:i:s");
|
||||
|
||||
$ccShowInstance = new CcShowInstances();
|
||||
if ($ccShowInstance->getTimestamp() > $currentUtcTimestamp) {
|
||||
$ccShowInstance->setDbShowId($showDay["show_id"]);
|
||||
$ccShowInstance->setDbStarts($utcStartDateTime);
|
||||
$ccShowInstance->setDbEnds($utcEndDateTime);
|
||||
$ccShowInstance->setDbRecord($showDay["record"]);
|
||||
$ccShowInstance->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param $showDay
|
||||
* @param $populateUntil
|
||||
* @param $repeatInterval
|
||||
*/
|
||||
private function createRepeatingShowInstances($showDay, $populateUntil, $repeatInterval)
|
||||
{
|
||||
Logging::info("repeating");
|
||||
}
|
||||
}
|
|
@ -2,8 +2,13 @@
|
|||
|
||||
class Application_Service_ShowService
|
||||
{
|
||||
const MAX_REBROADCAST_DATES = 10;
|
||||
|
||||
/**
|
||||
* Sets a cc_show entry
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param $ccShow
|
||||
* @param $showData
|
||||
*/
|
||||
public function setShow($ccShow, $showData)
|
||||
{
|
||||
|
@ -23,7 +28,13 @@ class Application_Service_ShowService
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates new cc_show_days entries
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param $showData
|
||||
* @param $showId
|
||||
* @param $userId
|
||||
* @param $repeatType
|
||||
* @param $isRecorded
|
||||
*/
|
||||
public function createShowDays($showData, $showId, $userId, $repeatType, $isRecorded)
|
||||
{
|
||||
|
@ -95,14 +106,17 @@ class Application_Service_ShowService
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates new cc_show_rebroadcast entries
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param $showData
|
||||
* @param $showId
|
||||
* @param $repeatType
|
||||
* @param $isRecorded
|
||||
*/
|
||||
public function createShowRebroadcast($showData, $showId, $repeatType, $isRecorded)
|
||||
public function createShowRebroadcasts($showData, $showId, $repeatType, $isRecorded)
|
||||
{
|
||||
define("MAX_REBROADCAST_DATES", 10);
|
||||
|
||||
if (($isRecorded && $showData['add_show_rebroadcast']) && ($repeatType != -1)) {
|
||||
for ($i=1; $i<=MAX_REBROADCAST_DATES; $i++) {
|
||||
for ($i=1; $i<=self::MAX_REBROADCAST_DATES; $i++) {
|
||||
if ($showData['add_show_rebroadcast_date_'.$i]) {
|
||||
$showRebroad = new CcShowRebroadcast();
|
||||
$showRebroad->setDbDayOffset($showData['add_show_rebroadcast_date_'.$i]);
|
||||
|
@ -112,7 +126,7 @@ class Application_Service_ShowService
|
|||
}
|
||||
}
|
||||
} elseif ($isRecorded && $showData['add_show_rebroadcast'] && ($repeatType == -1)) {
|
||||
for ($i=1; $i<=MAX_REBROADCAST_DATES; $i++) {
|
||||
for ($i=1; $i<=self::MAX_REBROADCAST_DATES; $i++) {
|
||||
if ($showData['add_show_rebroadcast_date_absolute_'.$i]) {
|
||||
$rebroadcastDate = new DateTime($showData["add_show_rebroadcast_date_absolute_$i"]);
|
||||
$startDate = new DateTime($showData['add_show_start_date']);
|
||||
|
@ -129,7 +143,10 @@ class Application_Service_ShowService
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates cc_show_hosts entries
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param $showData
|
||||
* @param $showId
|
||||
*/
|
||||
public function createShowHosts($showData, $showId)
|
||||
{
|
||||
|
@ -174,4 +191,39 @@ class Application_Service_ShowService
|
|||
return Application_Common_Database::prepareAndExecute(
|
||||
$sql, array(":show_id" => $showId), 'all');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param $localStart timestring format "Y-m-d H:i:s" (not UTC)
|
||||
* @param $duration string time interval (h)h:(m)m(:ss)
|
||||
* @param $timezone string "Europe/Prague"
|
||||
* @param $offset array (days, hours, mins) used for rebroadcast shows
|
||||
*
|
||||
* @return array of 2 DateTime objects, start/end time of the show in UTC
|
||||
*/
|
||||
public function createUTCStartEndDateTime($localStart, $duration, $timezone=null, $offset=null)
|
||||
{
|
||||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||
$user = new Application_Model_User($userInfo->id);
|
||||
$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
|
||||
|
||||
if (!isset($timezone)) {
|
||||
$timezone = Application_Model_Preference::GetUserTimezone($user->getId());
|
||||
}
|
||||
|
||||
$startDateTime = new DateTime($localStart, new DateTimeZone($timezone));
|
||||
if (isset($offset)) {
|
||||
$startDateTime->add(new DateInterval("P{$offset["days"]}DT{$offset["hours"]}H{$offset["mins"]}M"));
|
||||
}
|
||||
//convert time to UTC
|
||||
$startDateTime->setTimezone(new DateTimeZone('UTC'));
|
||||
|
||||
$endDateTime = clone $startDateTime;
|
||||
$duration = explode(":", $duration);
|
||||
list($hours, $mins) = array_slice($duration, 0, 2);
|
||||
$endDateTime->add(new DateInterval("PT{$hours}H{$mins}M"));
|
||||
|
||||
return array($startDateTime, $endDateTime);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue