diff --git a/airtime_mvc/application/common/DateHelper.php b/airtime_mvc/application/common/DateHelper.php index 823151c2f..07ef3bd18 100644 --- a/airtime_mvc/application/common/DateHelper.php +++ b/airtime_mvc/application/common/DateHelper.php @@ -45,6 +45,29 @@ class Application_Common_DateHelper return gmdate("H:i:s", $this->_dateTime); } + /** Get the abbreviated timezone for the currently logged in user. + * @return A string containing the short form of the timezone set in the preferences for the current user (eg. EST, CEST, etc.) + */ + public static function getUserTimezoneAbbreviation() + { + return self::getTimezoneAbbreviation(Application_Model_Preference::GetUserTimezone()); + } + + /** Get the abbreviated timezone string of the timezone the station is set to. + * @return A string containing the short form of the station's timezone (eg. EST, CEST, etc.) + */ + public static function getStationTimezoneAbbreviation() + { + return self::getTimezoneAbbreviation(Application_Model_Preference::GetDefaultTimezone()); + } + + private static function getTimezoneAbbreviation($fullTimeZoneName) + { + $timeZone = new DateTimeZone($fullTimeZoneName); + $now = new DateTime("now", $timeZone); + return $now->format("T"); + } + public static function getUserTimezoneOffset() { $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone()); diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index da671cd80..65306306a 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -185,6 +185,7 @@ class ApiController extends Zend_Controller_Action } } + //Used by the SaaS monitoring public function onAirLightAction() { $this->view->layout()->disableLayout(); @@ -286,6 +287,14 @@ class ApiController extends Zend_Controller_Action $next["name"] = htmlspecialchars($next["name"]); } + //For consistency, all times here are being sent in the station timezone, which + //seems to be what we've normalized everything to. + + //Convert the UTC scheduler time ("now") to the station timezone. + $result["schedulerTime"] = Application_Common_DateHelper::UTCStringToStationTimezoneString($result["schedulerTime"]); + $result["timezone"] = Application_Common_DateHelper::getStationTimezoneAbbreviation(); + $result["timezoneOffset"] = Application_Common_DateHelper::getStationTimezoneOffset(); + //Convert from UTC to station time for Web Browser. Application_Common_DateHelper::convertTimestamps($result["currentShow"], array("starts", "ends", "start_timestamp", "end_timestamp"), diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index 9737d6231..91d56bd74 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -116,9 +116,11 @@ class ScheduleController extends Zend_Controller_Action $service_user = new Application_Service_UserService(); $currentUser = $service_user->getCurrentUser(); - $start = new DateTime($this->_getParam('start', null)); + $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone()); + + $start = new DateTime($this->_getParam('start', null), $userTimezone); $start->setTimezone(new DateTimeZone("UTC")); - $end = new DateTime($this->_getParam('end', null)); + $end = new DateTime($this->_getParam('end', null), $userTimezone); $end->setTimezone(new DateTimeZone("UTC")); $events = &Application_Model_Show::getFullCalendarEvents($start, $end, @@ -263,6 +265,8 @@ class ScheduleController extends Zend_Controller_Action $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"]); @@ -275,7 +279,7 @@ class ScheduleController extends Zend_Controller_Action $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"), @@ -287,6 +291,10 @@ class ScheduleController extends Zend_Controller_Action "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"); @@ -429,7 +437,7 @@ class ScheduleController extends Zend_Controller_Action if ($service_showForm->validateShowForms($forms, $data, $validateStartDate, $originalShowStartDateTime, true, $data["add_show_instance_id"])) { - $service_show->createShowFromRepeatingInstance($data); + $service_show->editRepeatingShowInstance($data); $this->view->addNewShow = true; $this->view->newForm = $this->view->render('schedule/add-show-form.phtml'); diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index f672181e4..4b2cf044e 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -65,6 +65,8 @@ SQL; */ 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"); @@ -72,12 +74,8 @@ SQL; return array(); } - $displayTimeZone = new DateTimeZone(Application_Model_Preference::GetTimezone()); - $displayNow = new DateTime("now", $displayTimeZone); + $utcNow = new DateTime("now", new DateTimeZone("UTC")); - $utcNow = clone $displayNow; - $utcNow->setTimezone(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; @@ -85,14 +83,14 @@ SQL; $results = self::GetPrevCurrentNext($previousShowID, $currentShowID, $nextShowID, $utcNow); $range = array("env"=>APPLICATION_ENV, - "schedulerTime"=> $displayNow->format("Y-m-d H:i:s"), + "schedulerTime"=> $utcNow->format("Y-m-d H:i:s"), + //Previous, current, next songs! "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), + //Current and next shows "currentShow"=>$shows['currentShow'], "nextShow"=>$shows['nextShow'], - "timezone"=> $displayNow->format("T"), - "timezoneOffset"=> $displayNow->format("Z") ); return $range; @@ -831,18 +829,18 @@ SQL; { $CC_CONFIG = Config::getConfig(); - $scheduleTimeZone = new DateTimeZone('UTC'); + $utcTimeZone = new DateTimeZone('UTC'); /* if $p_fromDateTime and $p_toDateTime function parameters are null, then set range * from "now" to "now + 24 hours". */ if (is_null($p_fromDateTime)) { - $t1 = new DateTime("@".time(), $scheduleTimeZone); + $t1 = new DateTime("@".time(), $utcTimeZone); $range_start = $t1->format("Y-m-d H:i:s"); } else { $range_start = Application_Model_Schedule::PypoTimeToAirtimeTime($p_fromDateTime); } if (is_null($p_fromDateTime)) { - $t2 = new DateTime("@".time(), $scheduleTimeZone); + $t2 = new DateTime("@".time(), $utcTimeZone); $cache_ahead_hours = $CC_CONFIG["cache_ahead_hours"]; diff --git a/airtime_mvc/application/services/CalendarService.php b/airtime_mvc/application/services/CalendarService.php index 04cf9776b..41ad7c17c 100644 --- a/airtime_mvc/application/services/CalendarService.php +++ b/airtime_mvc/application/services/CalendarService.php @@ -82,15 +82,26 @@ class Application_Service_CalendarService // Show content can be modified from the calendar if: // the user is admin or hosting the show, // the show is not recorded - - if ($now < $end && ($isAdminOrPM || $isHostOfShow) && - !$this->ccShowInstance->isRecorded() ) { - - $menu["schedule"] = array( - "name"=> _("Add / Remove Content"), - "icon" => "add-remove-content", - "url" => $baseUrl."showbuilder/builder-dialog/"); - + $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) && diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index cb0314d3f..9b756337b 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -41,7 +41,7 @@ class Application_Service_ShowService $this->isUpdate = $isUpdate; } - public function createShowFromRepeatingInstance($showData) { + public function editRepeatingShowInstance($showData) { $service_user = new Application_Service_UserService(); $currentUser = $service_user->getCurrentUser(); @@ -108,9 +108,6 @@ class Application_Service_ShowService */ $this->setCcShowDays($showData); - // DO WE NEED THIS? - $this->setCcShowHosts($showData); - /* * We need to find the new show day rule we just created by passing * in the first show and start time in case multiple single @@ -196,8 +193,8 @@ class Application_Service_ShowService $this->deleteRebroadcastInstances(); - //$this->deleteCcShowDays(); $this->deleteCcShowHosts(); + if ($this->isRebroadcast) { //delete entry in cc_show_rebroadcast $this->deleteCcShowRebroadcasts();