From fb793ff3e1fc69781351c31b60d0fcd10547a6b6 Mon Sep 17 00:00:00 2001 From: drigato Date: Thu, 12 Dec 2013 13:01:33 -0500 Subject: [PATCH 1/5] CC-5634: Can add/remove content to a linked show while one instance is currently playing Fixed by removing option from context menu --- .../application/services/CalendarService.php | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/airtime_mvc/application/services/CalendarService.php b/airtime_mvc/application/services/CalendarService.php index 04cf9776b..1591fe4b3 100644 --- a/airtime_mvc/application/services/CalendarService.php +++ b/airtime_mvc/application/services/CalendarService.php @@ -82,15 +82,25 @@ 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(); + $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 && (count($currentShow) > 0 && $currentShow[0]["id"] != $this->ccShow->getDbId())) { + + $menu["schedule"] = array( + "name"=> _("Add / Remove Content"), + "icon" => "add-remove-content", + "url" => $baseUrl."showbuilder/builder-dialog/"); + } + } if ($now < $start && ($isAdminOrPM || $isHostOfShow) && From f37b9a3796b7d97526e5affbf4bc8e7712900d94 Mon Sep 17 00:00:00 2001 From: drigato Date: Thu, 12 Dec 2013 13:23:20 -0500 Subject: [PATCH 2/5] CC-5634: Can add/remove content to a linked show while one instance is currently playing small logic fix --- airtime_mvc/application/services/CalendarService.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/application/services/CalendarService.php b/airtime_mvc/application/services/CalendarService.php index 1591fe4b3..41ad7c17c 100644 --- a/airtime_mvc/application/services/CalendarService.php +++ b/airtime_mvc/application/services/CalendarService.php @@ -83,6 +83,7 @@ class Application_Service_CalendarService // 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 @@ -93,7 +94,7 @@ class Application_Service_CalendarService "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 && (count($currentShow) > 0 && $currentShow[0]["id"] != $this->ccShow->getDbId())) { + } elseif ($showIsLinked && $currentShowId != $this->ccShow->getDbId()) { $menu["schedule"] = array( "name"=> _("Add / Remove Content"), From a96c2551efe9f37d4bb71c73468c25343a3e5723 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Thu, 12 Dec 2013 13:28:51 -0500 Subject: [PATCH 3/5] CC-5627 : Check all Application_Common_DateHelper calculations that use timezone. * Fixed GetPlayOrderRange to be consistently return everything in UTC. * ApiController liveInfoAction now returns everything consistently in the station timezone. This fixes negative remaining time that could occur in the embeddable JS Airtime widgets if you were logged in to Airtime while you viewed your website. (The widgets display in the browser's local time.) * ScheduleController getCurrentPlaylistAction() returns everything consistently in the user timezone now. --- airtime_mvc/application/common/DateHelper.php | 23 +++++++++++++++++++ .../application/controllers/ApiController.php | 9 ++++++++ .../controllers/ScheduleController.php | 8 ++++++- airtime_mvc/application/models/Schedule.php | 20 ++++++++-------- 4 files changed, 48 insertions(+), 12 deletions(-) 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..f77282926 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -263,6 +263,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 +277,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 +289,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"); diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index 596cbe4fc..2a4a442ea 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"]; From 1577b7c41e84328d0a6124753377795d11188eeb Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Thu, 12 Dec 2013 16:39:20 -0500 Subject: [PATCH 4/5] CC-5627: Check all Application_Common_DateHelper calculations that use timezone. * Use the user timezone in eventFeedAction(), will fix a bug where shows at the edge of a week can disappear from the calendar if the user timezone is not the same as the station timezone. --- airtime_mvc/application/controllers/ScheduleController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index f77282926..518abee1f 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, From d0474f424709010711b0138ea723e3eb22d7dfea Mon Sep 17 00:00:00 2001 From: drigato Date: Thu, 12 Dec 2013 16:47:55 -0500 Subject: [PATCH 5/5] Changed function title when editing a repeating instance Removed a function call we don't need when editing a repeating instance --- airtime_mvc/application/controllers/ScheduleController.php | 2 +- airtime_mvc/application/services/ShowService.php | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index 518abee1f..91d56bd74 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -437,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/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index 54ccd2ba6..9545fdb37 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();