From df22ab21a6d2ce81c2993f8874f968ebf0e3b619 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Fri, 2 Mar 2012 16:32:16 -0500 Subject: [PATCH] CC-3359: Now Playing -> Day view has a bug with supporting UTC time -fixed --- airtime_mvc/application/models/Nowplaying.php | 51 +++++++++++-------- airtime_mvc/application/models/Schedule.php | 10 ++-- .../application/models/ShowInstance.php | 16 +++--- 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/airtime_mvc/application/models/Nowplaying.php b/airtime_mvc/application/models/Nowplaying.php index b3a45c539..cff2598ef 100644 --- a/airtime_mvc/application/models/Nowplaying.php +++ b/airtime_mvc/application/models/Nowplaying.php @@ -67,40 +67,51 @@ class Application_Model_Nowplaying return array("r", "", "", "", $p_showInstance->getName(), "", "", "", "", "", ""); } - public static function GetDataGridData($viewType, $dateString){ - if ($viewType == "now"){ - $dateTime = new DateTime("now", new DateTimeZone("UTC")); - $timeNow = $dateTime->format("Y-m-d H:i:s"); + /* + * The purpose of this function is to return an array of scheduled + * items. There are two parameters. $p_viewType can be either "now" + * or "day". If "now", we show all scheduled items in the near future. + * + * If "day" we need to find what day was requested by the user, and return + * scheduled items for that day. + * + * $p_dateString is only used when $p_viewType is "day" it is in the format + * "2012-12-31". In this case it tells us which day to use. + */ + public static function GetDataGridData($p_viewType, $p_dateString){ + + if ($p_viewType == "now"){ + $start_dt = new DateTime("now", new DateTimeZone("UTC")); + $end_dt = clone $start_dt; - $startCutoff = 60; - $endCutoff = 86400; //60*60*24 - seconds in a day + $start_dt->sub(new DateInterval("PT60S")); + $end_dt->add(new DateInterval("PT24H")); } else { - $time = date("H:i:s"); - $utcDate = Application_Model_DateHelper::ConvertToUtcDateTimeString($dateString." ".$time); + Logging::log("HIII"); - $date = new Application_Model_DateHelper; - $date->setDate($utcDate); + //convert to UTC + $utc_dt = Application_Model_DateHelper::ConvertToUtcDateTime($p_dateString); + $start_dt = $utc_dt; - $timeNow = $date->getUtcTimestamp(); - - $startCutoff = $date->getNowDayStartDiff(); - $endCutoff = $date->getNowDayEndDiff(); + $end_dt = clone $utc_dt; + $end_dt->add(new DateInterval("PT24H")); } - - $data = array(); - - $showIds = Application_Model_ShowInstance::GetShowsInstancesIdsInRange($timeNow, $startCutoff, $endCutoff); - + $starts = $start_dt->format("Y-m-d H:i:s"); + $ends = $end_dt->format("Y-m-d H:i:s"); + + $showIds = Application_Model_ShowInstance::GetShowsInstancesIdsInRange($starts, $ends); + //get all the pieces to be played between the start cut off and the end cut off. - $scheduledItems = Application_Model_Schedule::getScheduleItemsInRange($timeNow, $startCutoff, $endCutoff); + $scheduledItems = Application_Model_Schedule::getScheduleItemsInRange($starts, $ends); $orderedScheduledItems; foreach ($scheduledItems as $scheduledItem){ $orderedScheduledItems[$scheduledItem['instance_id']][] = $scheduledItem; } + $data = array(); foreach ($showIds as $showId){ $instanceId = $showId['id']; diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index 8321627a6..cc12a5a47 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -354,7 +354,7 @@ class Application_Model_Schedule { } - public static function getScheduleItemsInRange($timeNow, $start, $end) + public static function getScheduleItemsInRange($starts, $ends) { global $CC_DBC, $CC_CONFIG; @@ -380,9 +380,9 @@ class Application_Model_Schedule { ." ON st.file_id = ft.id" ." LEFT JOIN ".$CC_CONFIG["showTable"]." s" ." ON si.show_id = s.id" - ." WHERE ((si.starts < TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends > TIMESTAMP '$timeNow' - INTERVAL '$start seconds')" - ." OR (si.starts > TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends < TIMESTAMP '$timeNow' + INTERVAL '$end seconds')" - ." OR (si.starts < TIMESTAMP '$timeNow' + INTERVAL '$end seconds' AND si.ends > TIMESTAMP '$timeNow' + INTERVAL '$end seconds'))" + ." WHERE ((si.starts < TIMESTAMP '$starts' AND si.ends > TIMESTAMP '$starts')" + ." OR (si.starts > TIMESTAMP '$starts' AND si.ends < TIMESTAMP '$ends')" + ." OR (si.starts < TIMESTAMP '$ends' AND si.ends > TIMESTAMP '$ends'))" ." AND (st.starts < si.ends)" ." ORDER BY si.id, si.starts, st.starts"; @@ -670,4 +670,4 @@ class Application_Model_Schedule { } $p_view->addNewShow = true; } -} \ No newline at end of file +} diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index 0fbaa4666..bd7cc7b27 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -700,20 +700,22 @@ class Application_Model_ShowInstance { return $items; } - public static function GetShowsInstancesIdsInRange($p_timeNow, $p_start, $p_end) + public static function GetShowsInstancesIdsInRange($p_start, $p_end) { global $CC_DBC; $sql = "SELECT id FROM cc_show_instances AS si " ."WHERE modified_instance != TRUE AND (" - ."(si.starts < TIMESTAMP '$p_timeNow' - INTERVAL '$p_start seconds' " - ."AND si.ends > TIMESTAMP '$p_timeNow' - INTERVAL '$p_start seconds') " - ."OR (si.starts > TIMESTAMP '$p_timeNow' - INTERVAL '$p_start seconds' " - ."AND si.ends < TIMESTAMP '$p_timeNow' + INTERVAL '$p_end seconds') " - ."OR (si.starts < TIMESTAMP '$p_timeNow' + INTERVAL '$p_end seconds' " - ."AND si.ends > TIMESTAMP '$p_timeNow' + INTERVAL '$p_end seconds') " + ."(si.starts < TIMESTAMP '$p_start'" + ."AND si.ends > TIMESTAMP '$p_start') " + ."OR (si.starts > TIMESTAMP '$p_start' " + ."AND si.ends < TIMESTAMP '$p_end') " + ."OR (si.starts < TIMESTAMP '$p_end' " + ."AND si.ends > TIMESTAMP '$p_end') " .") " ." ORDER BY si.starts"; + + Logging::debug($sql); $rows = $CC_DBC->GetAll($sql); return $rows;