Example #1
0
 /**
  * Creates a 1 or more than 1 show instances (user has stated this show repeats). If the show
  * is recorded, it may have multiple rebroadcast dates, and so this function will create
  * those as well.
  *
  * @param array $p_showRow
  *        A row from cc_show_days table
  * @param DateTime $p_populateUntilDateTime
  *        DateTime object in UTC time. "shows_populated_until" date YY-mm-dd in cc_pref
  * @param string $p_interval
  *        Period of time between repeating shows (in php DateInterval notation 'P7D')
  */
 private static function populateRepeatingShow($p_showDaysRow, $p_populateUntilDateTime, $p_interval)
 {
     $show_id = $p_showDaysRow["show_id"];
     $next_pop_date = $p_showDaysRow["next_pop_date"];
     $first_show = $p_showDaysRow["first_show"];
     //non-UTC
     $last_show = $p_showDaysRow["last_show"];
     //non-UTC
     $start_time = $p_showDaysRow["start_time"];
     //non-UTC
     $duration = $p_showDaysRow["duration"];
     $day = $p_showDaysRow["day"];
     $record = $p_showDaysRow["record"];
     $timezone = $p_showDaysRow["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;
     }
     $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;
     $sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id=:show_id";
     $rebroadcasts = Application_Common_Database::prepareAndExecute($sql, array(':show_id' => $show_id), 'all');
     $show = new Application_Model_Show($show_id);
     while ($utcStartDateTime->getTimestamp() <= $p_populateUntilDateTime->getTimestamp() && (is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp())) {
         list($utcStartDateTime, $utcEndDateTime) = self::createUTCStartEndDateTime($start, $duration, $timezone);
         if ($show->hasInstanceOnDate($utcStartDateTime)) {
             $ccShowInstance = $show->getInstanceOnDate($utcStartDateTime);
             if ($ccShowInstance->getDbModifiedInstance()) {
                 //show instance on this date has been deleted.
                 list($start, $utcStartDateTime) = self::advanceRepeatingDate($p_interval, $start, $timezone);
                 continue;
             }
             $newInstance = false;
         } else {
             $ccShowInstance = new CcShowInstances();
             $newInstance = true;
         }
         /* When editing the start/end time of a repeating show, we don't want to
          * change shows that started in the past. So check the start time.
          */
         if ($newInstance || $ccShowInstance->getDbStarts() > $currentUtcTimestamp) {
             $ccShowInstance->setDbShowId($show_id);
             $ccShowInstance->setDbStarts($utcStartDateTime);
             $ccShowInstance->setDbEnds($utcEndDateTime);
             $ccShowInstance->setDbRecord($record);
             $ccShowInstance->save();
         }
         $show_instance_id = $ccShowInstance->getDbId();
         $showInstance = new Application_Model_ShowInstance($show_instance_id);
         /* If we are updating a show then make sure that the scheduled content within
          * the show is updated to the correct time. */
         if (!$newInstance) {
             $showInstance->correctScheduleStartTimes();
         }
         $showInstance->deleteRebroadcasts();
         self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
         list($start, $utcStartDateTime) = self::advanceRepeatingDate($p_interval, $start, $timezone);
     }
     Application_Model_Show::setNextPop($start, $show_id, $day);
 }