CC-3359: Now Playing -> Day view has a bug with supporting UTC time

-fixed
This commit is contained in:
Martin Konecny 2012-03-02 16:32:16 -05:00
parent 82812e15a5
commit df22ab21a6
3 changed files with 45 additions and 32 deletions

View File

@ -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'];

View File

@ -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;
}
}
}

View File

@ -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;