From 276607c302ef9a0c9699867c315d5f0148b667f8 Mon Sep 17 00:00:00 2001 From: Yuchen Wang Date: Thu, 24 Nov 2011 13:54:58 -0500 Subject: [PATCH] CC-3104: Timezone issues in the widget For a previous ticket, I changed the code so that both "Today's Program" widget and "Now Playing" widget both use the liveInfoAction, but forgot that for "Now Playing" widget, it retrieves the shows within next 48 hours instead of within end of day today... Fixed by passing GET parameters to liveInfoAction, specify whether we want to retrieve shows within an interval or end of day. Also added a GET parameter for specifying the number of shows to display. --- .../application/controllers/ApiController.php | 32 +++++++++++++++++-- airtime_mvc/application/models/DateHelper.php | 2 +- airtime_mvc/application/models/Show.php | 4 +-- widgets/js/jquery.showinfo.js | 16 +++++++--- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 7a4e81f4d..d70476e06 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -172,6 +172,21 @@ class ApiController extends Zend_Controller_Action return; } + /** + * Retrieve the currently playing show as well as upcoming shows. + * Number of shows returned and the time interval in which to + * get the next shows can be configured as post parameters. + * + * TODO: in the future, make interval length a parameter instead of hardcode to 48 + * + * Possible parameters: + * type - Can have values of "endofday" or "interval". If set to "endofday", + * the function will retrieve shows from now to end of day. + * If set to "interval", shows in the next 48 hours will be retrived. + * Default is "interval". + * limit - How many shows to retrieve + * Default is "5". + */ public function liveInfoAction() { if (Application_Model_Preference::GetAllow3rdPartyApi()){ @@ -181,11 +196,24 @@ class ApiController extends Zend_Controller_Action $date = new Application_Model_DateHelper; $utcTimeNow = $date->getUtcTimestamp(); + $utcTimeEnd = ""; // if empty, GetNextShows will use interval instead of end of day + + $request = $this->getRequest(); + $type = $request->getParam('type'); + if($type == "endofday") { + // make GetNextShows use end of day + $utcTimeEnd = Application_Model_DateHelper::GetDayEndTimestampInUtc(); + } + + $limit = $request->getParam('limit'); + if($limit == "") { + $limit = "5"; + } $result = array("env"=>APPLICATION_ENV, "schedulerTime"=>gmdate("Y-m-d H:i:s"), "currentShow"=>Application_Model_Show::GetCurrentShow($utcTimeNow), - "nextShow"=>Application_Model_Show::GetNextShows($utcTimeNow, 5), + "nextShow"=>Application_Model_Show::GetNextShows($utcTimeNow, $limit, $utcTimeEnd), "timezone"=> date("T"), "timezoneOffset"=> date("Z")); @@ -219,7 +247,7 @@ class ApiController extends Zend_Controller_Action $result = array(); for ($i=0; $i<7; $i++){ $utcDayEnd = Application_Model_DateHelper::GetDayEndTimestamp($utcDayStart); - $shows = Application_Model_Show::GetNextShows($utcDayStart, 0, $utcDayEnd); + $shows = Application_Model_Show::GetNextShows($utcDayStart, "0", $utcDayEnd); $utcDayStart = $utcDayEnd; Application_Model_Show::ConvertToLocalTimeZone($shows, array("starts", "ends", "start_timestamp", "end_timestamp")); diff --git a/airtime_mvc/application/models/DateHelper.php b/airtime_mvc/application/models/DateHelper.php index c223a909f..3ebc6f51d 100644 --- a/airtime_mvc/application/models/DateHelper.php +++ b/airtime_mvc/application/models/DateHelper.php @@ -84,7 +84,7 @@ class Application_Model_DateHelper public static function GetDayEndTimestampInUtc($time = "") { $dayEndTimestamp = Application_Model_DateHelper::GetDayEndTimestamp($time); - return Application_Model_DateHelper::ConvertToUtcDateTime($dayEndTimestamp); + return Application_Model_DateHelper::ConvertToUtcDateTimeString($dayEndTimestamp); } /** diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 799c98e08..f44855d46 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1556,7 +1556,7 @@ class Application_Model_Show { * @param String $timeEnd - interval end time (in UTC) * @return array - the next $limit number of shows within the time interval */ - public static function GetNextShows($timeStart, $limit = 0, $timeEnd = "") + public static function GetNextShows($timeStart, $limit = "0", $timeEnd = "") { global $CC_CONFIG, $CC_DBC; @@ -1577,7 +1577,7 @@ class Application_Model_Show { ." ORDER BY si.starts"; // defaults to retrieve all shows within the interval if $limit not set - if($limit != 0) { + if($limit != "0") { $sql = $sql . " LIMIT $limit"; } diff --git a/widgets/js/jquery.showinfo.js b/widgets/js/jquery.showinfo.js index 1c75b7918..d1bdd7f3f 100644 --- a/widgets/js/jquery.showinfo.js +++ b/widgets/js/jquery.showinfo.js @@ -52,9 +52,13 @@ } function getServerData(){ - $.ajax({ url: options.sourceDomain + "api/live-info/", dataType:"jsonp", success:function(data){ + $.ajax({url: options.sourceDomain + "api/live-info/", + data: {type:"endofday",limit:"5"}, + dataType: "jsonp", + success:function(data) { processData(data); - }, error:airtimeScheduleJsonpError}); + }, + error: airtimeScheduleJsonpError}); setTimeout(getServerData, options.updatePeriod*1000); } }); @@ -130,9 +134,13 @@ } function getServerData(){ - $.ajax({ url: options.sourceDomain + "api/live-info/", dataType:"jsonp", success:function(data){ + $.ajax({url: options.sourceDomain + "api/live-info/", + data: {type:"interval",limit:"5"}, + dataType: "jsonp", + success: function(data) { processData(data); - }, error:airtimeScheduleJsonpError}); + }, + error: airtimeScheduleJsonpError}); setTimeout(getServerData, options.updatePeriod*1000); } });