示例#1
0
 public function moveShow($deltaDay, $deltaMin)
 {
     if ($this->getShow()->isRepeating()) {
         return "Can't drag and drop repeating shows";
     }
     $today_timestamp = time();
     $startsDateTime = new DateTime($this->getShowInstanceStart(), new DateTimeZone("UTC"));
     $endsDateTime = new DateTime($this->getShowInstanceEnd(), new DateTimeZone("UTC"));
     if ($today_timestamp > $startsDateTime->getTimestamp()) {
         return "Can't move a past show";
     }
     //the user is moving the show on the calendar from the perspective of local time.
     //incase a show is moved across a time change border offsets should be added to the localtime
     //stamp and then converted back to UTC to avoid show time changes!
     $startsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
     $endsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
     $newStartsDateTime = self::addDeltas($startsDateTime, $deltaDay, $deltaMin);
     $newEndsDateTime = self::addDeltas($endsDateTime, $deltaDay, $deltaMin);
     //convert our new starts/ends to UTC.
     $newStartsDateTime->setTimezone(new DateTimeZone("UTC"));
     $newEndsDateTime->setTimezone(new DateTimeZone("UTC"));
     if ($today_timestamp > $newStartsDateTime->getTimestamp()) {
         return "Can't move show into past";
     }
     //check if show is overlapping
     $overlapping = Application_Model_Schedule::checkOverlappingShows($newStartsDateTime, $newEndsDateTime, true, $this->getShowInstanceId());
     if ($overlapping) {
         return "Cannot schedule overlapping shows";
     }
     if ($this->isRecorded()) {
         //rebroadcasts should start at max 1 hour after a recorded show has ended.
         $minRebroadcastStart = self::addDeltas($newEndsDateTime, 0, 60);
         //check if we are moving a recorded show less than 1 hour before any of its own rebroadcasts.
         $rebroadcasts = CcShowInstancesQuery::create()->filterByDbOriginalShow($this->_instanceId)->filterByDbStarts($minRebroadcastStart->format('Y-m-d H:i:s'), Criteria::LESS_THAN)->find();
         if (count($rebroadcasts) > 0) {
             return "Can't move a recorded show less than 1 hour before its rebroadcasts.";
         }
     }
     if ($this->isRebroadcast()) {
         try {
             $recordedShow = new Application_Model_ShowInstance($this->_showInstance->getDbOriginalShow());
         } catch (Exception $e) {
             $this->_showInstance->delete();
             return "Show was deleted because recorded show does not exist!";
         }
         $recordEndDateTime = new DateTime($recordedShow->getShowInstanceEnd(), new DateTimeZone("UTC"));
         $newRecordEndDateTime = self::addDeltas($recordEndDateTime, 0, 60);
         if ($newStartsDateTime->getTimestamp() < $newRecordEndDateTime->getTimestamp()) {
             return "Must wait 1 hour to rebroadcast.";
         }
     }
     $this->setShowStart($newStartsDateTime);
     $this->setShowEnd($newEndsDateTime);
     $this->correctScheduleStartTimes();
     $show = new Application_Model_Show($this->getShowId());
     if (!$show->isRepeating() && is_null($this->isRebroadcast())) {
         $show->setShowFirstShow($newStartsDateTime);
         $show->setShowLastShow($newEndsDateTime);
     }
     Application_Model_RabbitMq::PushSchedule();
 }