示例#1
0
文件: Show.php 项目: nidzix/Airtime
 /**
  * Creates a single show instance. 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.
  */
 private static function populateNonRepeatingShow($p_showRow, $p_populateUntilDateTime)
 {
     $show_id = $p_showRow["show_id"];
     $first_show = $p_showRow["first_show"];
     //non-UTC
     $start_time = $p_showRow["start_time"];
     //non-UTC
     $duration = $p_showRow["duration"];
     $record = $p_showRow["record"];
     $timezone = $p_showRow["timezone"];
     $start = $first_show . " " . $start_time;
     //start & end UTC DateTimes for the show.
     list($utcStartDateTime, $utcEndDateTime) = Application_Model_Show::createUTCStartEndDateTime($start, $duration, $timezone);
     if ($utcStartDateTime->getTimestamp() < $p_populateUntilDateTime->getTimestamp()) {
         $currentUtcTimestamp = gmdate("Y-m-d H:i:s");
         $show = new Application_Model_Show($show_id);
         if ($show->hasInstance()) {
             $ccShowInstance = $show->getInstance();
             $newInstance = false;
         } else {
             $ccShowInstance = new CcShowInstances();
             $newInstance = true;
         }
         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 (!$newInstance) {
             $showInstance->correctScheduleStartTimes();
         }
         $sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id=:show_id";
         $rebroadcasts = Application_Common_Database::prepareAndExecute($sql, array(':show_id' => $show_id), 'all');
         if ($showInstance->isRecorded()) {
             $showInstance->deleteRebroadcasts();
             self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
         }
     }
 }