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(); }
public function makeContextMenuAction() { $id = $this->_getParam('id'); $menu = array(); $epochNow = time(); $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); try { $instance = new Application_Model_ShowInstance($id); } catch (Exception $e) { $this->view->show_error = true; return false; } $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); $isDJ = $user->isHostOfShow($instance->getShowId()); $showStartLocalDT = Application_Common_DateHelper::ConvertToLocalDateTime($instance->getShowInstanceStart()); $showEndLocalDT = Application_Common_DateHelper::ConvertToLocalDateTime($instance->getShowInstanceEnd()); if ($instance->isRecorded() && $epochNow > $showEndLocalDT->getTimestamp()) { $file = $instance->getRecordedFile(); $fileId = $file->getId(); $menu["view_recorded"] = array("name" => "View Recorded File Metadata", "icon" => "overview", "url" => "/library/edit-file-md/id/" . $fileId); } if ($epochNow < $showStartLocalDT->getTimestamp()) { if (($isAdminOrPM || $isDJ) && !$instance->isRecorded() && !$instance->isRebroadcast()) { $menu["schedule"] = array("name" => "Add / Remove Content", "icon" => "add-remove-content", "url" => "/showbuilder/builder-dialog/"); $menu["clear"] = array("name" => "Remove All Content", "icon" => "remove-all-content", "url" => "/schedule/clear-show"); } } if (!$instance->isRecorded()) { $menu["content"] = array("name" => "Show Content", "icon" => "overview", "url" => "/schedule/show-content-dialog"); } if ($showEndLocalDT->getTimestamp() <= $epochNow && $instance->isRecorded() && Application_Model_Preference::GetUploadToSoundcloudOption()) { $file = $instance->getRecordedFile(); $fileId = $file->getId(); $scid = $instance->getSoundCloudFileId(); if ($scid > 0) { $url = $file->getSoundCloudLinkToFile(); $menu["soundcloud_view"] = array("name" => "View on Soundcloud", "icon" => "soundcloud", "url" => $url); } $text = is_null($scid) ? 'Upload to SoundCloud' : 'Re-upload to SoundCloud'; $menu["soundcloud_upload"] = array("name" => $text, "icon" => "soundcloud"); } if ($showStartLocalDT->getTimestamp() <= $epochNow && $epochNow < $showEndLocalDT->getTimestamp() && $isAdminOrPM) { if ($instance->isRecorded()) { $menu["cancel_recorded"] = array("name" => "Cancel Current Show", "icon" => "delete"); } else { if (!$instance->isRebroadcast()) { $menu["edit"] = array("name" => "Edit Show", "icon" => "edit", "_type" => "all", "url" => "/Schedule/populate-show-form"); } $menu["cancel"] = array("name" => "Cancel Current Show", "icon" => "delete"); } } if ($epochNow < $showStartLocalDT->getTimestamp()) { if (!$instance->isRebroadcast() && $isAdminOrPM) { $menu["edit"] = array("name" => "Edit Show", "icon" => "edit", "_type" => "all", "url" => "/Schedule/populate-show-form"); } if ($instance->getShow()->isRepeating() && $isAdminOrPM) { //create delete sub menu. $menu["del"] = array("name" => "Delete", "icon" => "delete", "items" => array()); $menu["del"]["items"]["single"] = array("name" => "Delete This Instance", "icon" => "delete", "url" => "/schedule/delete-show"); $menu["del"]["items"]["following"] = array("name" => "Delete This Instance and All Following", "icon" => "delete", "url" => "/schedule/cancel-show"); } elseif ($isAdminOrPM) { $menu["del"] = array("name" => "Delete", "icon" => "delete", "url" => "/schedule/delete-show"); } } $this->view->items = $menu; }