Created function to create repeating show instances

Created function to create rebroadcast show instances
This commit is contained in:
denise 2013-03-08 11:19:03 -05:00
parent af622eb4b8
commit 4a86da5f87
3 changed files with 118 additions and 22 deletions

View File

@ -173,6 +173,7 @@ class Application_Service_ScheduleService
$repeatType = ($showData['add_show_repeats']) ? $showData['add_show_repeat_type'] : -1; $repeatType = ($showData['add_show_repeats']) ? $showData['add_show_repeat_type'] : -1;
$isRecorded = (isset($showData['add_show_record']) && $showData['add_show_record']) ? 1 : 0; $isRecorded = (isset($showData['add_show_record']) && $showData['add_show_record']) ? 1 : 0;
$isRebroadcast = (isset($showData['add_show_rebroadcast']) && $showData['add_show_rebroadcast']) ? 1 : 0;
$showData["add_show_duration"] = $this->formatShowDuration( $showData["add_show_duration"] = $this->formatShowDuration(
$showData["add_show_duration"]); $showData["add_show_duration"]);
@ -194,7 +195,7 @@ class Application_Service_ScheduleService
$this->service_show->createShowHosts($showData, $showId); $this->service_show->createShowHosts($showData, $showId);
//create ccShowInstances //create ccShowInstances
$this->service_showInstances->createShowInstances($showId); $this->service_showInstances->delegateShowInstanceCreation($showId, $isRebroadcast);
} }
} }

View File

@ -16,9 +16,9 @@ class Application_Service_ShowInstanceService
/** /**
* *
* Receives a cc_show id and determines whether to create a * Receives a cc_show id and determines whether to create a
* single show_instance or repeating show instances * single show instance or repeating show instances
*/ */
public function createShowInstances($showId) public function delegateShowInstanceCreation($showId, $isRebroadcast)
{ {
$populateUntil = $this->service_show->getPopulateShowUntilDateTIme(); $populateUntil = $this->service_show->getPopulateShowUntilDateTIme();
@ -26,31 +26,32 @@ class Application_Service_ShowInstanceService
foreach ($showDays as $day) { foreach ($showDays as $day) {
switch ($day["repeat_type"]) { switch ($day["repeat_type"]) {
case self::NO_REPEAT: case self::NO_REPEAT:
$this->createNonRepeatingShowInstance($day, $populateUntil); $this->createNonRepeatingShowInstance($day, $populateUntil, $isRebroadcast);
break; break;
case self::REPEAT_WEEKLY: case self::REPEAT_WEEKLY:
$this->createRepeatingShowInstances($day, $populateUntil, "P7D"); $this->createWeeklyRepeatingShowInstances($day, $populateUntil, "P7D", $isRebroadcast);
break; break;
case self::REPEAT_BI_WEEKLY: case self::REPEAT_BI_WEEKLY:
$this->createRepeatingShowInstances($day, $populateUntil, "P14D"); $this->createWeeklyRepeatingShowInstances($day, $populateUntil, "P14D", $isRebroadcast);
break; break;
case self::REPEAT_MONTHLY_MONTHLY: case self::REPEAT_MONTHLY_MONTHLY:
$this->createRepeatingShowInstances($day, $populateUntil, "P1M"); $this->createMonthlyRepeatingShowInstances($day, $populateUntil, "P1M", $isRebroadcast);
break; break;
case self::REPEAT_MONTHLY_WEEKLY: case self::REPEAT_MONTHLY_WEEKLY:
// do something here // do something here
break; break;
} }
} }
Application_Model_RabbitMq::PushSchedule();
} }
/** /**
* *
* Enter description here ... * Sets a single cc_show_instance table row
* @param $showDay * @param $showDay
* @param $populateUntil * @param $populateUntil
*/ */
private function createNonRepeatingShowInstance($showDay, $populateUntil) private function createNonRepeatingShowInstance($showDay, $populateUntil, $isRebroadcast)
{ {
$start = $showDay["first_show"]." ".$showDay["start_time"]; $start = $showDay["first_show"]." ".$showDay["start_time"];
@ -58,16 +59,82 @@ class Application_Service_ShowInstanceService
$start, $showDay["duration"], $showDay["timezone"]); $start, $showDay["duration"], $showDay["timezone"]);
if ($utcStartDateTime->getTimestamp() < $populateUntil->getTimestamp()) { if ($utcStartDateTime->getTimestamp() < $populateUntil->getTimestamp()) {
$currentUtcTimestamp = gmdate("Y-m-d H:i:s");
$ccShowInstance = new CcShowInstances(); $ccShowInstance = new CcShowInstances();
if ($ccShowInstance->getTimestamp() > $currentUtcTimestamp) { $ccShowInstance->setDbShowId($showDay["show_id"]);
$ccShowInstance->setDbShowId($showDay["show_id"]); $ccShowInstance->setDbStarts($utcStartDateTime);
$ccShowInstance->setDbEnds($utcEndDateTime);
$ccShowInstance->setDbRecord($showDay["record"]);
$ccShowInstance->save();
if ($isRebroadcast) {
self::createRebroadcastShowInstances($showDay, $start, $ccShowInstance->getDbId());
}
}
}
/**
*
* Sets multiple cc_show_instances table rows
* @param unknown_type $showDay
* @param unknown_type $populateUntil
* @param unknown_type $repeatInterval
* @param unknown_type $isRebroadcast
*/
private function createWeeklyRepeatingShowInstances($showDay, $populateUntil,
$repeatInterval, $isRebroadcast)
{
$show_id = $showDay["show_id"];
$next_pop_date = $showDay["next_pop_date"];
$first_show = $showDay["first_show"]; //non-UTC
$last_show = $showDay["last_show"]; //non-UTC
$start_time = $showDay["start_time"]; //non-UTC
$duration = $showDay["duration"];
$day = $showDay["day"];
$record = $showDay["record"];
$timezone = $showDay["timezone"];
$currentUtcTimestamp = gmdate("Y-m-d H:i:s");
if (isset($next_pop_date)) {
$start = $next_pop_date." ".$start_time;
} else {
$start = $first_show." ".$start_time;
}
/*
* Create a DatePeriod object in the user's local time
* It will get converted to UTC right before the show instance
* gets created
*/
$period = new DatePeriod(new DateTime($start, new DateTimeZone($timezone)),
new DateInterval($repeatInterval), $populateUntil);
$utcStartDateTime = Application_Common_DateHelper::ConvertToUtcDateTime($start, $timezone);
//convert $last_show into a UTC DateTime object, or null if there is no last show.
$utcLastShowDateTime = $last_show ? Application_Common_DateHelper::ConvertToUtcDateTime($last_show, $timezone) : null;
foreach ($period as $date) {
/*
* Make sure start date is less than populate until date AND
* last show date is null OR start date is less than last show date
*/
if ($utcStartDateTime->getTimestamp() <= $populateUntil->getTimestamp() &&
is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp()) {
list($utcStartDateTime, $utcEndDateTime) = $this->service_show->createUTCStartEndDateTime(
$date->format("Y-m-d H:i:s"), $duration, $timezone);
$ccShowInstance = new CcShowInstances();
$ccShowInstance->setDbShowId($show_id);
$ccShowInstance->setDbStarts($utcStartDateTime); $ccShowInstance->setDbStarts($utcStartDateTime);
$ccShowInstance->setDbEnds($utcEndDateTime); $ccShowInstance->setDbEnds($utcEndDateTime);
$ccShowInstance->setDbRecord($showDay["record"]); $ccShowInstance->setDbRecord($record);
$ccShowInstance->save(); $ccShowInstance->save();
} }
if ($isRebroadcast) {
self::createRebroadcastShowInstances($showDay, $date->format("Y-m-d"), $ccShowInstance->getDbId());
}
} }
} }
@ -75,11 +142,39 @@ class Application_Service_ShowInstanceService
* *
* Enter description here ... * Enter description here ...
* @param $showDay * @param $showDay
* @param $populateUntil
* @param $repeatInterval
*/ */
private function createRepeatingShowInstances($showDay, $populateUntil, $repeatInterval) private function createRebroadcastShowInstances($showDay, $showStartDate, $instanceId)
{ {
Logging::info("repeating"); $currentUtcTimestamp = gmdate("Y-m-d H:i:s");
$showId = $showDay["show_id"];
$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id=:show_id";
$rebroadcasts = Application_Common_Database::prepareAndExecute($sql,
array( ':show_id' => $showId ), 'all');
foreach ($rebroadcasts as $rebroadcast) {
$days = explode(" ", $rebroadcast["day_offset"]);
$time = explode(":", $rebroadcast["start_time"]);
$offset = array("days"=>$days[0], "hours"=>$time[0], "mins"=>$time[1]);
list($utcStartDateTime, $utcEndDateTime) = $this->service_show->createUTCStartEndDateTime(
$showStartDate, $showDay["duration"], $showDay["timezone"], $offset);
if ($utcStartDateTime->format("Y-m-d H:i:s") > $currentUtcTimestamp) {
$ccShowInstance = new CcShowInstances();
$ccShowInstance->setDbShowId($showId);
$ccShowInstance->setDbStarts($utcStartDateTime);
$ccShowInstance->setDbEnds($utcEndDateTime);
$ccShowInstance->setDbRecord(0);
$ccShowInstance->setDbRebroadcast(1);
$ccShowInstance->setDbOriginalShow($instanceId);
$ccShowInstance->save();
}
}
}
private function deleteRebroadcastShowInstances()
{
} }
} }

View File

@ -6,7 +6,7 @@ class Application_Service_ShowService
/** /**
* *
* Enter description here ... * Sets the fields for a cc_show table row
* @param $ccShow * @param $ccShow
* @param $showData * @param $showData
*/ */
@ -29,7 +29,7 @@ class Application_Service_ShowService
/** /**
* *
* Enter description here ... * Sets the fields for a cc_show_days table row
* @param $showData * @param $showData
* @param $showId * @param $showId
* @param $userId * @param $userId
@ -107,7 +107,7 @@ class Application_Service_ShowService
/** /**
* *
* Enter description here ... * Sets the fields for a cc_show_rebroadcast table row
* @param $showData * @param $showData
* @param $showId * @param $showId
* @param $repeatType * @param $repeatType
@ -144,7 +144,7 @@ class Application_Service_ShowService
/** /**
* *
* Enter description here ... * Sets the fields for a cc_show_hosts table row
* @param $showData * @param $showData
* @param $showId * @param $showId
*/ */