function createTestShow($showNumber, $showTime, $duration = "1:00") { $data = array(); $strTime = $showTime->format("Y-m-d H:i"); echo "Adding show: {$strTime}\n"; $data['add_show_name'] = 'automated show ' . $showNumber; $data['add_show_start_date'] = $showTime->format("Y-m-d"); $data['add_show_start_time'] = $showTime->format("H:i"); $data['add_show_duration'] = $duration; $data['add_show_no_end'] = 0; $data['add_show_repeats'] = 0; $data['add_show_description'] = 'automated show'; $data['add_show_url'] = 'http://www.OfirGal.com'; $data['add_show_color'] = ""; $data['add_show_genre'] = "Ofir"; $data['add_show_background_color'] = ""; $data['add_show_record'] = 0; $data['add_show_hosts'] = ""; $showId = Application_Model_Show::create($data); //echo "show created, ID: $showId\n"; // populating the show with a playlist $instances = Application_Model_Show::getShows($showTime, $showTime); $instance = array_pop($instances); $show = new Application_Model_ShowInstance($instance["instance_id"]); //echo "Adding playlist to show instance ".$show->getShowInstanceId()."\n"; $show->scheduleShow(array(1)); //echo "done\n"; //$show->scheduleShow(array($playlist->getId())); }
public static function SendMessageToShowRecorder($event_type) { $exchange = 'airtime-pypo'; $now = new DateTime("@" . time()); //in UTC timezone $end_timestamp = new DateTime("@" . (time() + 3600 * 2)); //in UTC timezone $temp = array(); $temp['event_type'] = $event_type; $temp['server_timezone'] = Application_Model_Preference::GetTimezone(); if ($event_type == "update_recorder_schedule") { $temp['shows'] = Application_Model_Show::getShows($now, $end_timestamp, $onlyRecord = true); } $data = json_encode($temp); self::sendMessage($exchange, $data); }
/** * Returns data related to the scheduled items. * * @param int $p_prev * @param int $p_next * @return date */ public static function GetPlayOrderRange($p_prev = 1, $p_next = 1) { //Everything in this function must be done in UTC. You will get a swift kick in the pants if you mess that up. if (!is_int($p_prev) || !is_int($p_next)) { //must enter integers to specify ranges Logging::info("Invalid range parameters: {$p_prev} or {$p_next}"); return array(); } $utcNow = new DateTime("now", new DateTimeZone("UTC")); $shows = Application_Model_Show::getPrevCurrentNext($utcNow); $previousShowID = count($shows['previousShow']) > 0 ? $shows['previousShow'][0]['instance_id'] : null; $currentShowID = count($shows['currentShow']) > 0 ? $shows['currentShow'][0]['instance_id'] : null; $nextShowID = count($shows['nextShow']) > 0 ? $shows['nextShow'][0]['instance_id'] : null; $results = self::GetPrevCurrentNext($previousShowID, $currentShowID, $nextShowID, $utcNow); $range = array("env" => APPLICATION_ENV, "schedulerTime" => $utcNow->format("Y-m-d H:i:s"), "previous" => $results['previous'] != null ? $results['previous'] : (count($shows['previousShow']) > 0 ? $shows['previousShow'][0] : null), "current" => $results['current'] != null ? $results['current'] : (count($shows['currentShow']) > 0 && $shows['currentShow'][0]['record'] == 1 ? $shows['currentShow'][0] : null), "next" => $results['next'] != null ? $results['next'] : (count($shows['nextShow']) > 0 ? $shows['nextShow'][0] : null), "currentShow" => $shows['currentShow'], "nextShow" => $shows['nextShow']); return $range; }
public function switchSourceAction() { $sourcename = $this->_getParam('sourcename'); $current_status = $this->_getParam('status'); $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); $show = Application_Model_Show::getCurrentShow(); $show_id = isset($show[0]['id']) ? $show[0]['id'] : 0; $source_connected = Application_Model_Preference::GetSourceStatus($sourcename); if ($user->canSchedule($show_id) && ($source_connected || $sourcename == 'scheduled_play' || $current_status == "on")) { $change_status_to = "on"; if (strtolower($current_status) == "on") { $change_status_to = "off"; } $data = array("sourcename" => $sourcename, "status" => $change_status_to); Application_Model_RabbitMq::SendMessageToPypo("switch_source", $data); if (strtolower($current_status) == "on") { Application_Model_Preference::SetSourceSwitchStatus($sourcename, "off"); $this->view->status = "OFF"; //Log table updates Application_Model_LiveLog::SetEndTime($sourcename == 'scheduled_play' ? 'S' : 'L', new DateTime("now", new DateTimeZone('UTC'))); } else { Application_Model_Preference::SetSourceSwitchStatus($sourcename, "on"); $this->view->status = "ON"; //Log table updates Application_Model_LiveLog::SetNewLogTime($sourcename == 'scheduled_play' ? 'S' : 'L', new DateTime("now", new DateTimeZone('UTC'))); } } else { if ($source_connected) { $this->view->error = _("You don't have permission to switch source."); } else { if ($sourcename == 'scheduled_play') { $this->view->error = _("You don't have permission to disconnect source."); } else { $this->view->error = _("There is no source connected to this input."); } } } }
public function init() { // retrieves the length limit for each char field // and store to assoc array $maxLens = Application_Model_Show::getMaxLengths(); // Hidden element to indicate whether the show is new or // whether we are updating an existing show. $this->addElement('hidden', 'add_show_id', array('decorators' => array('ViewHelper'))); // Hidden element to indicate the instance id of the show // being edited. $this->addElement('hidden', 'add_show_instance_id', array('decorators' => array('ViewHelper'))); // Add name element $this->addElement('text', 'add_show_name', array('label' => 'Name:', 'class' => 'input_text', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array('NotEmpty'), 'value' => 'Untitled Show', 'validators' => array(array('StringLength', false, array(0, $maxLens['name']))))); // Add URL element $this->addElement('text', 'add_show_url', array('label' => 'URL:', 'class' => 'input_text', 'required' => false, 'filters' => array('StringTrim'), 'validators' => array('NotEmpty', array('StringLength', false, array(0, $maxLens['url']))))); // Add genre element $this->addElement('text', 'add_show_genre', array('label' => 'Genre:', 'class' => 'input_text', 'required' => false, 'filters' => array('StringTrim'), 'validators' => array(array('StringLength', false, array(0, $maxLens['genre']))))); // Add the description element $this->addElement('textarea', 'add_show_description', array('label' => 'Description:', 'required' => false, 'class' => 'input_text_area', 'validators' => array(array('StringLength', false, array(0, $maxLens['description']))))); $descText = $this->getElement('add_show_description'); $descText->setDecorators(array(array('ViewScript', array('viewScript' => 'form/add-show-block.phtml', 'class' => 'block-display')))); }
public function resizeShow($deltaDay, $deltaMin) { $con = Propel::getConnection(); $hours = $deltaMin / 60; $hours = $hours > 0 ? floor($hours) : ceil($hours); $mins = abs($deltaMin % 60); $today_timestamp = gmdate("Y-m-d H:i:s"); $starts = $this->getShowInstanceStart(); $ends = $this->getShowInstanceEnd(); if (strtotime($today_timestamp) > strtotime($starts)) { return "can't resize a past show"; } //$sql = "SELECT timestamp '{$ends}' + interval '{$deltaDay} days' + interval '{$hours}:{$mins}'"; $sql = "SELECT timestamp :ends + interval :deltaDays + interval :deltaTime"; $now_ends = Application_Common_Database::prepareAndExecute($sql, array(':ends' => $ends, ':deltaDays' => "{$deltaDay} days", ':deltaTime' => "{$hours}:{$mins}"), 'column'); //only need to check overlap if show increased in size. if (strtotime($new_ends) > strtotime($ends)) { $utcStartDateTime = new DateTime($ends, new DateTimeZone("UTC")); $utcEndDateTime = new DateTime($new_ends, new DateTimeZone("UTC")); $overlap = Application_Model_Show::getShows($utcStartDateTime, $utcEndDateTime); if (count($overlap) > 0) { // TODO : fix ghetto error handling -- RG return "Should not overlap shows"; } } //with overbooking no longer need to check already scheduled content still fits. //must update length of all rebroadcast instances. if ($this->isRecorded()) { $sql = <<<SQL UPDATE cc_show_instances SET ends = (ends + interval :deltaDays + interval :interval) WHERE rebroadcast = 1 AND instance_id = :instanceId; SQL; Application_Common_Database::prepareAndExecute($sql, array(':deltaDays' => "{$deltaDay} days", ':interval' => "{$hours}:{$mins}", ':instanceId' => $this->_instanceId), 'execute'); } $this->setShowEnd($new_ends); Application_Model_RabbitMq::PushSchedule(); }
/** * * Enter description here ... */ public function makeContextMenu() { $menu = array(); $now = time(); $baseUrl = Application_Common_OsPath::getBaseDir(); $isAdminOrPM = $this->currentUser->isAdminOrPM(); $isHostOfShow = $this->currentUser->isHostOfShow($this->ccShow->getDbId()); //DateTime objects in UTC $startDT = $this->ccShowInstance->getDbStarts(null); $endDT = $this->ccShowInstance->getDbEnds(null); //timestamps $start = $startDT->getTimestamp(); $end = $endDT->getTimestamp(); //show has ended if ($now > $end) { if ($this->ccShowInstance->isRecorded()) { $ccFile = $this->ccShowInstance->getCcFiles(); if (!isset($ccFile)) { $menu["error when recording"] = array("name" => _("Record file doesn't exist"), "icon" => "error"); } else { $menu["view_recorded"] = array("name" => _("View Recorded File Metadata"), "icon" => "overview", "url" => $baseUrl . "library/edit-file-md/id/" . $ccFile->getDbId()); } //recorded show can be uploaded to soundcloud if (Application_Model_Preference::GetUploadToSoundcloudOption()) { $scid = $ccFile->getDbSoundcloudId(); if ($scid > 0) { $menu["soundcloud_view"] = array("name" => _("View on Soundcloud"), "icon" => "soundcloud", "url" => $ccFile->getDbSoundcloudLinkToFile()); } $text = is_null($scid) ? _('Upload to SoundCloud') : _('Re-upload to SoundCloud'); $menu["soundcloud_upload"] = array("name" => $text, "icon" => "soundcloud"); } } else { $menu["content"] = array("name" => _("Show Content"), "icon" => "overview", "url" => $baseUrl . "schedule/show-content-dialog"); } } else { // Show content can be modified from the calendar if: // the user is admin or hosting the show, // the show is not recorded $currentShow = Application_Model_Show::getCurrentShow(); $currentShowId = count($currentShow) == 1 ? $currentShow[0]["id"] : null; $showIsLinked = $this->ccShow->isLinked(); if ($now < $end && ($isAdminOrPM || $isHostOfShow) && !$this->ccShowInstance->isRecorded()) { //if the show is not linked the user can add/remove content if (!$showIsLinked) { $menu["schedule"] = array("name" => _("Add / Remove Content"), "icon" => "add-remove-content", "url" => $baseUrl . "showbuilder/builder-dialog/"); //if the show is linked and it's not currently playing the user can add/remove content } elseif ($showIsLinked && $currentShowId != $this->ccShow->getDbId()) { $menu["schedule"] = array("name" => _("Add / Remove Content"), "icon" => "add-remove-content", "url" => $baseUrl . "showbuilder/builder-dialog/"); } } if ($now < $start && ($isAdminOrPM || $isHostOfShow) && !$this->ccShowInstance->isRecorded()) { $menu["clear"] = array("name" => _("Remove All Content"), "icon" => "remove-all-content", "url" => $baseUrl . "schedule/clear-show"); } //"Show Content" should be a menu item at all times except when //the show is recorded if (!$this->ccShowInstance->isRecorded()) { $menu["content"] = array("name" => _("Show Content"), "icon" => "overview", "url" => $baseUrl . "schedule/show-content-dialog"); } //show is currently playing and user is admin if ($start <= $now && $now < $end && $isAdminOrPM) { if ($this->ccShowInstance->isRecorded()) { $menu["cancel_recorded"] = array("name" => _("Cancel Current Show"), "icon" => "delete"); } else { $menu["cancel"] = array("name" => _("Cancel Current Show"), "icon" => "delete"); } } $excludeIds = $this->ccShow->getEditedRepeatingInstanceIds(); $isRepeating = $this->ccShow->isRepeating(); $populateInstance = false; if ($isRepeating && in_array($this->ccShowInstance->getDbId(), $excludeIds)) { $populateInstance = true; } if (!$this->ccShowInstance->isRebroadcast() && $isAdminOrPM) { if ($isRepeating) { if ($populateInstance) { $menu["edit"] = array("name" => _("Edit This Instance"), "icon" => "edit", "url" => $baseUrl . "Schedule/populate-repeating-show-instance-form"); } else { $menu["edit"] = array("name" => _("Edit"), "icon" => "edit", "items" => array()); $menu["edit"]["items"]["all"] = array("name" => _("Edit Show"), "icon" => "edit", "url" => $baseUrl . "Schedule/populate-show-form"); $menu["edit"]["items"]["instance"] = array("name" => _("Edit This Instance"), "icon" => "edit", "url" => $baseUrl . "Schedule/populate-repeating-show-instance-form"); } } else { $menu["edit"] = array("name" => _("Edit Show"), "icon" => "edit", "_type" => "all", "url" => $baseUrl . "Schedule/populate-show-form"); } } //show hasn't started yet and user is admin if ($now < $start && $isAdminOrPM) { //show is repeating so give user the option to delete all //repeating instances or just the one if ($isRepeating) { $menu["del"] = array("name" => _("Delete"), "icon" => "delete", "items" => array()); $menu["del"]["items"]["single"] = array("name" => _("Delete This Instance"), "icon" => "delete", "url" => $baseUrl . "schedule/delete-show-instance"); $menu["del"]["items"]["following"] = array("name" => _("Delete This Instance and All Following"), "icon" => "delete", "url" => $baseUrl . "schedule/delete-show"); } elseif ($populateInstance) { $menu["del"] = array("name" => _("Delete"), "icon" => "delete", "url" => $baseUrl . "schedule/delete-show-instance"); } else { $menu["del"] = array("name" => _("Delete"), "icon" => "delete", "url" => $baseUrl . "schedule/delete-show"); } } } return $menu; }
public function cancelShowAction() { $user = Application_Model_User::getCurrentUser(); if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { $showInstanceId = $this->_getParam('id'); try { $showInstance = new Application_Model_ShowInstance($showInstanceId); } catch (Exception $e) { $this->view->show_error = true; return false; } $show = new Application_Model_Show($showInstance->getShowId()); $show->cancelShow($showInstance->getShowInstanceStart()); $this->view->show_id = $showInstance->getShowId(); } }
public function checkLiveStreamAuthAction() { $request = $this->getRequest(); $username = $request->getParam('username'); $password = $request->getParam('password'); $djtype = $request->getParam('djtype'); if ($djtype == 'master') { //check against master if ($username == Application_Model_Preference::GetLiveStreamMasterUsername() && $password == Application_Model_Preference::GetLiveStreamMasterPassword()) { $this->view->msg = true; } else { $this->view->msg = false; } } elseif ($djtype == "dj") { //check against show dj auth $showInfo = Application_Model_Show::getCurrentShow(); // there is current playing show if (isset($showInfo[0]['id'])) { $current_show_id = $showInfo[0]['id']; $CcShow = CcShowQuery::create()->findPK($current_show_id); // get custom pass info from the show $custom_user = $CcShow->getDbLiveStreamUser(); $custom_pass = $CcShow->getDbLiveStreamPass(); // get hosts ids $show = new Application_Model_Show($current_show_id); $hosts_ids = $show->getHostsIds(); // check against hosts auth if ($CcShow->getDbLiveStreamUsingAirtimeAuth()) { foreach ($hosts_ids as $host) { $h = new Application_Model_User($host['subjs_id']); if ($username == $h->getLogin() && md5($password) == $h->getPassword()) { $this->view->msg = true; return; } } } // check against custom auth if ($CcShow->getDbLiveStreamUsingCustomAuth()) { if ($username == $custom_user && $password == $custom_pass) { $this->view->msg = true; } else { $this->view->msg = false; } } else { $this->view->msg = false; } } else { // no show is currently playing $this->view->msg = false; } } }
public function hasBeenUpdatedSince($timestamp, $instances) { $outdated = false; $shows = Application_Model_Show::getShows($this->startDT, $this->endDT); $include = array(); if ($this->opts["showFilter"] !== 0) { $include[] = $this->opts["showFilter"]; } elseif ($this->opts["myShows"] === 1) { $include = $this->getUsersShows(); } $currentInstances = array(); foreach ($shows as $show) { if (empty($include) || in_array($show["show_id"], $include)) { $currentInstances[] = $show["instance_id"]; if (isset($show["last_scheduled"])) { $dt = new DateTime($show["last_scheduled"], new DateTimeZone("UTC")); } else { $dt = new DateTime($show["created"], new DateTimeZone("UTC")); } //check if any of the shows have a more recent timestamp. $showTimeStamp = intval($dt->format("U")); if ($timestamp < $showTimeStamp) { $outdated = true; break; } } } //see if the displayed show instances have changed. (deleted, //empty schedule etc) if ($outdated === false && count($instances) !== count($currentInstances)) { Logging::debug("show instances have changed."); $outdated = true; } return $outdated; }
/** * * @param DateTime $start * -in UTC time * @param DateTime $end * -in UTC time * @param boolean $editable */ public static function &getFullCalendarEvents($p_start, $p_end, $p_editable = false) { $events = array(); $interval = $p_start->diff($p_end); $days = $interval->format('%a'); $shows = Application_Model_Show::getShows($p_start, $p_end); $content_count = Application_Model_ShowInstance::getContentCount($p_start, $p_end); $isFull = Application_Model_ShowInstance::getIsFull($p_start, $p_end); $displayTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone()); $utcTimezone = new DateTimeZone("UTC"); $now = new DateTime("now", $utcTimezone); foreach ($shows as &$show) { $options = array(); //only bother calculating percent for week or day view. if (intval($days) <= 7) { $options["percent"] = Application_Model_Show::getPercentScheduled($show["starts"], $show["ends"], $show["time_filled"]); } if (isset($show["parent_starts"])) { $parentStartsDT = new DateTime($show["parent_starts"], $utcTimezone); } $startsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["starts"], $utcTimezone); $endsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["ends"], $utcTimezone); if ($p_editable) { if ($show["record"] && $now > $startsDT) { $options["editable"] = false; } elseif ($show["rebroadcast"] && $now > $parentStartsDT) { $options["editable"] = false; } elseif ($now < $endsDT) { $options["editable"] = true; } } $startsDT->setTimezone($displayTimezone); $endsDT->setTimezone($displayTimezone); $options["show_empty"] = array_key_exists($show['instance_id'], $content_count) ? 0 : 1; if (array_key_exists($show['instance_id'], $isFull)) { $options["show_partial_filled"] = !$isFull[$show['instance_id']]; } else { $options["show_partial_filled"] = true; } $event = array(); $event["id"] = intval($show["instance_id"]); $event["title"] = $show["name"]; $event["start"] = $startsDT->format("Y-m-d H:i:s"); $event["end"] = $endsDT->format("Y-m-d H:i:s"); $event["allDay"] = false; $event["showId"] = intval($show["show_id"]); $event["linked"] = intval($show["linked"]); $event["record"] = intval($show["record"]); $event["rebroadcast"] = intval($show["rebroadcast"]); $event["soundcloud_id"] = is_null($show["soundcloud_id"]) ? -1 : $show["soundcloud_id"]; //for putting the now playing icon on the show. if ($now > $startsDT && $now < $endsDT) { $event["nowPlaying"] = true; } else { $event["nowPlaying"] = false; } //event colouring if ($show["color"] != "") { $event["textColor"] = "#" . $show["color"]; } if ($show["background_color"] != "") { $event["color"] = "#" . $show["background_color"]; } foreach ($options as $key => $value) { $event[$key] = $value; } $events[] = $event; } return $events; }
public function getCurrentPlaylistAction() { $range = Application_Model_Schedule::GetPlayOrderRange(); $show = Application_Model_Show::getCurrentShow(); /* Convert all UTC times to localtime before sending back to user. */ $range["schedulerTime"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["schedulerTime"]); if (isset($range["previous"])) { $range["previous"]["starts"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["previous"]["starts"]); $range["previous"]["ends"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["previous"]["ends"]); } if (isset($range["current"])) { $range["current"]["starts"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["current"]["starts"]); $range["current"]["ends"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["current"]["ends"]); } if (isset($range["next"])) { $range["next"]["starts"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["next"]["starts"]); $range["next"]["ends"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["next"]["ends"]); } Application_Common_DateHelper::convertTimestamps($range["currentShow"], array("starts", "ends", "start_timestamp", "end_timestamp"), "user"); Application_Common_DateHelper::convertTimestamps($range["nextShow"], array("starts", "ends", "start_timestamp", "end_timestamp"), "user"); //TODO: Add timezone and timezoneOffset back into the ApiController's results. $range["timezone"] = Application_Common_DateHelper::getUserTimezoneAbbreviation(); $range["timezoneOffset"] = Application_Common_DateHelper::getUserTimezoneOffset(); $source_status = array(); $switch_status = array(); $live_dj = Application_Model_Preference::GetSourceStatus("live_dj"); $master_dj = Application_Model_Preference::GetSourceStatus("master_dj"); $scheduled_play_switch = Application_Model_Preference::GetSourceSwitchStatus("scheduled_play"); $live_dj_switch = Application_Model_Preference::GetSourceSwitchStatus("live_dj"); $master_dj_switch = Application_Model_Preference::GetSourceSwitchStatus("master_dj"); //might not be the correct place to implement this but for now let's just do it here $source_status['live_dj_source'] = $live_dj; $source_status['master_dj_source'] = $master_dj; $this->view->source_status = $source_status; $switch_status['live_dj_source'] = $live_dj_switch; $switch_status['master_dj_source'] = $master_dj_switch; $switch_status['scheduled_play'] = $scheduled_play_switch; $this->view->switch_status = $switch_status; $this->view->entries = $range; $this->view->show_name = isset($show[0]) ? $show[0]["name"] : ""; }
public static function addUpdateShow($data, $controller, $validateStartDate, $originalStartDate = null, $update = false, $instanceId = null) { $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); $isSaas = Application_Model_Preference::GetPlanLevel() != 'disabled'; $record = false; $formWhat = new Application_Form_AddShowWhat(); $formWho = new Application_Form_AddShowWho(); $formWhen = new Application_Form_AddShowWhen(); $formRepeats = new Application_Form_AddShowRepeats(); $formStyle = new Application_Form_AddShowStyle(); $formLive = new Application_Form_AddShowLiveStream(); $formWhat->removeDecorator('DtDdWrapper'); $formWho->removeDecorator('DtDdWrapper'); $formWhen->removeDecorator('DtDdWrapper'); $formRepeats->removeDecorator('DtDdWrapper'); $formStyle->removeDecorator('DtDdWrapper'); $formLive->removeDecorator('DtDdWrapper'); $what = $formWhat->isValid($data); $when = $formWhen->isValid($data); $live = $formLive->isValid($data); if ($when) { $when = $formWhen->checkReliantFields($data, $validateStartDate, $originalStartDate, $update, $instanceId); } //The way the following code works is that is parses the hour and //minute from a string with the format "1h 20m" or "2h" or "36m". //So we are detecting whether an hour or minute value exists via strpos //and then parse appropriately. A better way to do this in the future is //actually pass the format from javascript in the format hh:mm so we don't //have to do this extra String parsing. $hPos = strpos($data["add_show_duration"], 'h'); $mPos = strpos($data["add_show_duration"], 'm'); $hValue = 0; $mValue = 0; if ($hPos !== false) { $hValue = trim(substr($data["add_show_duration"], 0, $hPos)); } if ($mPos !== false) { $hPos = $hPos === false ? 0 : $hPos + 1; $mValue = trim(substr($data["add_show_duration"], $hPos, -1)); } $data["add_show_duration"] = $hValue . ":" . $mValue; if (!$isSaas) { $formRecord = new Application_Form_AddShowRR(); $formAbsoluteRebroadcast = new Application_Form_AddShowAbsoluteRebroadcastDates(); $formRebroadcast = new Application_Form_AddShowRebroadcastDates(); $formRecord->removeDecorator('DtDdWrapper'); $formAbsoluteRebroadcast->removeDecorator('DtDdWrapper'); $formRebroadcast->removeDecorator('DtDdWrapper'); $record = $formRecord->isValid($data); } if ($data["add_show_repeats"]) { $repeats = $formRepeats->isValid($data); if ($repeats) { $repeats = $formRepeats->checkReliantFields($data); } if (!$isSaas) { $formAbsoluteRebroadcast->reset(); //make it valid, results don't matter anyways. $rebroadAb = 1; if ($data["add_show_rebroadcast"]) { $rebroad = $formRebroadcast->isValid($data); if ($rebroad) { $rebroad = $formRebroadcast->checkReliantFields($data); } } else { $rebroad = 1; } } } else { $repeats = 1; if (!$isSaas) { $formRebroadcast->reset(); //make it valid, results don't matter anyways. $rebroad = 1; if ($data["add_show_rebroadcast"]) { $rebroadAb = $formAbsoluteRebroadcast->isValid($data); if ($rebroadAb) { $rebroadAb = $formAbsoluteRebroadcast->checkReliantFields($data); } } else { $rebroadAb = 1; } } } $who = $formWho->isValid($data); $style = $formStyle->isValid($data); if ($what && $when && $repeats && $who && $style && $live) { if (!$isSaas) { if ($record && $rebroadAb && $rebroad) { if ($isAdminOrPM) { Application_Model_Show::create($data); } //send back a new form for the user. Application_Model_Schedule::createNewFormSections($controller->view); //$controller->view->newForm = $controller->view->render('schedule/add-show-form.phtml'); return true; } else { $controller->view->what = $formWhat; $controller->view->when = $formWhen; $controller->view->repeats = $formRepeats; $controller->view->who = $formWho; $controller->view->style = $formStyle; $controller->view->rr = $formRecord; $controller->view->absoluteRebroadcast = $formAbsoluteRebroadcast; $controller->view->rebroadcast = $formRebroadcast; $controller->view->live = $formLive; //$controller->view->addNewShow = !$editShow; //$controller->view->form = $controller->view->render('schedule/add-show-form.phtml'); return false; } } else { if ($isAdminOrPM) { Application_Model_Show::create($data); } //send back a new form for the user. Application_Model_Schedule::createNewFormSections($controller->view); //$controller->view->newForm = $controller->view->render('schedule/add-show-form.phtml'); return true; } } else { $controller->view->what = $formWhat; $controller->view->when = $formWhen; $controller->view->repeats = $formRepeats; $controller->view->who = $formWho; $controller->view->style = $formStyle; $controller->view->live = $formLive; if (!$isSaas) { $controller->view->rr = $formRecord; $controller->view->absoluteRebroadcast = $formAbsoluteRebroadcast; $controller->view->rebroadcast = $formRebroadcast; } //$controller->view->addNewShow = !$editShow; //$controller->view->form = $controller->view->render('schedule/add-show-form.phtml'); return false; } }
/** * * @param DateTime $start * -in UTC time * @param DateTime $end * -in UTC time * @param boolean $editable */ public static function &getFullCalendarEvents($p_start, $p_end, $p_editable = false) { $events = array(); $interval = $p_start->diff($p_end); $days = $interval->format('%a'); $shows = Application_Model_Show::getShows($p_start, $p_end); $nowEpoch = time(); $content_count = Application_Model_ShowInstance::getContentCount($p_start, $p_end); $timezone = date_default_timezone_get(); foreach ($shows as $show) { $options = array(); //only bother calculating percent for week or day view. if (intval($days) <= 7) { $options["percent"] = Application_Model_Show::getPercentScheduled($show["starts"], $show["ends"], $show["time_filled"]); } $utc = new DateTimeZone("UTC"); if (isset($show["parent_starts"])) { $parentStartsDT = new DateTime($show["parent_starts"], $utc); $parentStartsEpoch = intval($parentStartsDT->format("U")); } $startsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["starts"], $utc); $endsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["ends"], $utc); $startsEpochStr = $startsDT->format("U"); $endsEpochStr = $endsDT->format("U"); $startsEpoch = intval($startsEpochStr); $endsEpoch = intval($endsEpochStr); $startsDT->setTimezone(new DateTimeZone($timezone)); $endsDT->setTimezone(new DateTimeZone($timezone)); if ($p_editable) { if ($show["record"] && $nowEpoch > $startsEpoch) { $options["editable"] = false; } elseif ($show["rebroadcast"] && $nowEpoch > $parentStartsEpoch) { $options["editable"] = false; } elseif ($nowEpoch < $endsEpoch) { $options["editable"] = true; } } $showInstance = new Application_Model_ShowInstance($show["instance_id"]); $options["show_empty"] = array_key_exists($show['instance_id'], $content_count) ? 0 : 1; $events[] =& self::makeFullCalendarEvent($show, $options, $startsDT, $endsDT, $startsEpochStr, $endsEpochStr); } return $events; }
public function getShowList($startDT, $endDT) { $user = Application_Model_User::getCurrentUser(); $shows = Application_Model_Show::getShows($startDT, $endDT); Logging::info($startDT->format("Y-m-d H:i:s")); Logging::info($endDT->format("Y-m-d H:i:s")); Logging::info($shows); //need to filter the list to only their shows if ($user->isHost()) { $showIds = array(); foreach ($shows as $show) { $showIds[] = $show["show_id"]; } $showIds = array_unique($showIds); Logging::info($showIds); $hostRecords = CcShowHostsQuery::create()->filterByDbHost($user->getId())->filterByDbShow($showIds)->find($this->con); $filteredShowIds = array(); foreach ($hostRecords as $record) { $filteredShowIds[] = $record->getDbShow(); } Logging::info($filteredShowIds); $filteredShows = array(); foreach ($shows as $show) { if (in_array($show["show_id"], $filteredShowIds)) { $filteredShows[] = $show; } } } else { $filteredShows = $shows; } $timezoneUTC = new DateTimeZone("UTC"); $timezoneLocal = new DateTimeZone($this->timezone); foreach ($filteredShows as &$result) { //need to display the results in the station's timezone. $dateTime = new DateTime($result["starts"], $timezoneUTC); $dateTime->setTimezone($timezoneLocal); $result["starts"] = $dateTime->format("Y-m-d H:i:s"); $dateTime = new DateTime($result["ends"], $timezoneUTC); $dateTime->setTimezone($timezoneLocal); $result["ends"] = $dateTime->format("Y-m-d H:i:s"); } return $filteredShows; }