Merge branch '2.5.x' of github.com:sourcefabric/Airtime into 2.5.x

This commit is contained in:
Naomi 2013-12-12 17:18:17 -05:00
commit bbccc2e7d3
6 changed files with 75 additions and 29 deletions

View File

@ -45,6 +45,29 @@ class Application_Common_DateHelper
return gmdate("H:i:s", $this->_dateTime); 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() public static function getUserTimezoneOffset()
{ {
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone()); $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());

View File

@ -185,6 +185,7 @@ class ApiController extends Zend_Controller_Action
} }
} }
//Used by the SaaS monitoring
public function onAirLightAction() public function onAirLightAction()
{ {
$this->view->layout()->disableLayout(); $this->view->layout()->disableLayout();
@ -286,6 +287,14 @@ class ApiController extends Zend_Controller_Action
$next["name"] = htmlspecialchars($next["name"]); $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. //Convert from UTC to station time for Web Browser.
Application_Common_DateHelper::convertTimestamps($result["currentShow"], Application_Common_DateHelper::convertTimestamps($result["currentShow"],
array("starts", "ends", "start_timestamp", "end_timestamp"), array("starts", "ends", "start_timestamp", "end_timestamp"),

View File

@ -116,9 +116,11 @@ class ScheduleController extends Zend_Controller_Action
$service_user = new Application_Service_UserService(); $service_user = new Application_Service_UserService();
$currentUser = $service_user->getCurrentUser(); $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")); $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")); $end->setTimezone(new DateTimeZone("UTC"));
$events = &Application_Model_Show::getFullCalendarEvents($start, $end, $events = &Application_Model_Show::getFullCalendarEvents($start, $end,
@ -263,6 +265,8 @@ class ScheduleController extends Zend_Controller_Action
$show = Application_Model_Show::getCurrentShow(); $show = Application_Model_Show::getCurrentShow();
/* Convert all UTC times to localtime before sending back to user. */ /* Convert all UTC times to localtime before sending back to user. */
$range["schedulerTime"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["schedulerTime"]);
if (isset($range["previous"])) { if (isset($range["previous"])) {
$range["previous"]["starts"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["previous"]["starts"]); $range["previous"]["starts"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["previous"]["starts"]);
$range["previous"]["ends"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["previous"]["ends"]); $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"]["starts"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["next"]["starts"]);
$range["next"]["ends"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["next"]["ends"]); $range["next"]["ends"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["next"]["ends"]);
} }
Application_Common_DateHelper::convertTimestamps( Application_Common_DateHelper::convertTimestamps(
$range["currentShow"], $range["currentShow"],
array("starts", "ends", "start_timestamp", "end_timestamp"), array("starts", "ends", "start_timestamp", "end_timestamp"),
@ -287,6 +291,10 @@ class ScheduleController extends Zend_Controller_Action
"user" "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(); $source_status = array();
$switch_status = array(); $switch_status = array();
$live_dj = Application_Model_Preference::GetSourceStatus("live_dj"); $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, if ($service_showForm->validateShowForms($forms, $data, $validateStartDate,
$originalShowStartDateTime, true, $data["add_show_instance_id"])) { $originalShowStartDateTime, true, $data["add_show_instance_id"])) {
$service_show->createShowFromRepeatingInstance($data); $service_show->editRepeatingShowInstance($data);
$this->view->addNewShow = true; $this->view->addNewShow = true;
$this->view->newForm = $this->view->render('schedule/add-show-form.phtml'); $this->view->newForm = $this->view->render('schedule/add-show-form.phtml');

View File

@ -65,6 +65,8 @@ SQL;
*/ */
public static function GetPlayOrderRange($p_prev = 1, $p_next = 1) 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)) { if (!is_int($p_prev) || !is_int($p_next)) {
//must enter integers to specify ranges //must enter integers to specify ranges
Logging::info("Invalid range parameters: $p_prev or $p_next"); Logging::info("Invalid range parameters: $p_prev or $p_next");
@ -72,12 +74,8 @@ SQL;
return array(); return array();
} }
$displayTimeZone = new DateTimeZone(Application_Model_Preference::GetTimezone()); $utcNow = new DateTime("now", new DateTimeZone("UTC"));
$displayNow = new DateTime("now", $displayTimeZone);
$utcNow = clone $displayNow;
$utcNow->setTimezone(new DateTimeZone("UTC"));
$shows = Application_Model_Show::getPrevCurrentNext($utcNow); $shows = Application_Model_Show::getPrevCurrentNext($utcNow);
$previousShowID = count($shows['previousShow'])>0?$shows['previousShow'][0]['instance_id']:null; $previousShowID = count($shows['previousShow'])>0?$shows['previousShow'][0]['instance_id']:null;
$currentShowID = count($shows['currentShow'])>0?$shows['currentShow'][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); $results = self::GetPrevCurrentNext($previousShowID, $currentShowID, $nextShowID, $utcNow);
$range = array("env"=>APPLICATION_ENV, $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), "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), "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), "next"=> $results['next'] !=null?$results['next']:(count($shows['nextShow'])>0?$shows['nextShow'][0]:null),
//Current and next shows
"currentShow"=>$shows['currentShow'], "currentShow"=>$shows['currentShow'],
"nextShow"=>$shows['nextShow'], "nextShow"=>$shows['nextShow'],
"timezone"=> $displayNow->format("T"),
"timezoneOffset"=> $displayNow->format("Z")
); );
return $range; return $range;
@ -831,18 +829,18 @@ SQL;
{ {
$CC_CONFIG = Config::getConfig(); $CC_CONFIG = Config::getConfig();
$scheduleTimeZone = new DateTimeZone('UTC'); $utcTimeZone = new DateTimeZone('UTC');
/* if $p_fromDateTime and $p_toDateTime function parameters are null, /* if $p_fromDateTime and $p_toDateTime function parameters are null,
then set range * from "now" to "now + 24 hours". */ then set range * from "now" to "now + 24 hours". */
if (is_null($p_fromDateTime)) { 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"); $range_start = $t1->format("Y-m-d H:i:s");
} else { } else {
$range_start = Application_Model_Schedule::PypoTimeToAirtimeTime($p_fromDateTime); $range_start = Application_Model_Schedule::PypoTimeToAirtimeTime($p_fromDateTime);
} }
if (is_null($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"]; $cache_ahead_hours = $CC_CONFIG["cache_ahead_hours"];

View File

@ -82,15 +82,26 @@ class Application_Service_CalendarService
// Show content can be modified from the calendar if: // Show content can be modified from the calendar if:
// the user is admin or hosting the show, // the user is admin or hosting the show,
// the show is not recorded // the show is not recorded
$currentShow = Application_Model_Show::getCurrentShow();
if ($now < $end && ($isAdminOrPM || $isHostOfShow) && $currentShowId = count($currentShow) == 1 ? $currentShow[0]["id"] : null;
!$this->ccShowInstance->isRecorded() ) { $showIsLinked = $this->ccShow->isLinked();
if ($now < $end && ($isAdminOrPM || $isHostOfShow) && !$this->ccShowInstance->isRecorded()) {
$menu["schedule"] = array( //if the show is not linked the user can add/remove content
"name"=> _("Add / Remove Content"), if (!$showIsLinked) {
"icon" => "add-remove-content",
"url" => $baseUrl."showbuilder/builder-dialog/"); $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) && if ($now < $start && ($isAdminOrPM || $isHostOfShow) &&

View File

@ -41,7 +41,7 @@ class Application_Service_ShowService
$this->isUpdate = $isUpdate; $this->isUpdate = $isUpdate;
} }
public function createShowFromRepeatingInstance($showData) { public function editRepeatingShowInstance($showData) {
$service_user = new Application_Service_UserService(); $service_user = new Application_Service_UserService();
$currentUser = $service_user->getCurrentUser(); $currentUser = $service_user->getCurrentUser();
@ -108,9 +108,6 @@ class Application_Service_ShowService
*/ */
$this->setCcShowDays($showData); $this->setCcShowDays($showData);
// DO WE NEED THIS?
$this->setCcShowHosts($showData);
/* /*
* We need to find the new show day rule we just created by passing * 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 * in the first show and start time in case multiple single
@ -196,8 +193,8 @@ class Application_Service_ShowService
$this->deleteRebroadcastInstances(); $this->deleteRebroadcastInstances();
//$this->deleteCcShowDays();
$this->deleteCcShowHosts(); $this->deleteCcShowHosts();
if ($this->isRebroadcast) { if ($this->isRebroadcast) {
//delete entry in cc_show_rebroadcast //delete entry in cc_show_rebroadcast
$this->deleteCcShowRebroadcasts(); $this->deleteCcShowRebroadcasts();