From 1492dcf2836cbd5c11d2e9c25a5f99403617ec2e Mon Sep 17 00:00:00 2001 From: mkonecny Date: Thu, 5 May 2011 00:28:34 -0400 Subject: [PATCH] cc-2229-refactor-now-playing-code -initial check-in --- airtime_mvc/application/models/Nowplaying.php | 42 ++++++++++++++++++- airtime_mvc/application/models/Shows.php | 22 ++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/application/models/Nowplaying.php b/airtime_mvc/application/models/Nowplaying.php index 6df81c310..a8b4e7e8f 100644 --- a/airtime_mvc/application/models/Nowplaying.php +++ b/airtime_mvc/application/models/Nowplaying.php @@ -2,7 +2,7 @@ class Application_Model_Nowplaying { - +/* public static function FindBeginningOfShow($rows){ $numRows = count($rows); @@ -143,4 +143,44 @@ class Application_Model_Nowplaying $timeNow = $date->getTimestamp(); return array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$data); } +*/ + + public static function GetDataGridData($viewType, $dateString){ + + if ($viewType == "now"){ + $date = new DateHelper; + $timeNow = $date->getTimestamp(); + + $startCutoff = 60; + $endCutoff = 86400; //60*60*24 - seconds in a day + } else { + $date = new DateHelper; + $time = $date->getTime(); + $date->setDate($dateString." ".$time); + $timeNow = $date->getTimestamp(); + + $startCutoff = $date->getNowDayStartDiff(); + $endCutoff = $date->getNowDayEndDiff(); + } + + $showInstances = Show::GetShowsInstancesInRange($timeNow, $startCutoff, $endCutoff); + + $output = array( + "sEcho" => intval($_GET['sEcho']), + "iTotalRecords" => $iTotal, + "iTotalDisplayRecords" => $iFilteredTotal, + "aaData" => array() + ); + + foreach ($showInstances as $si){ + $rows = $si->getShowContent(); + foreach ($rows as $row){ + $output['aaData'][] = $row; + } + $output['aaData'][] = $si->getShowEndGap(); + } + + return $output; + } + } diff --git a/airtime_mvc/application/models/Shows.php b/airtime_mvc/application/models/Shows.php index d7f985e7b..a9c4008d4 100644 --- a/airtime_mvc/application/models/Shows.php +++ b/airtime_mvc/application/models/Shows.php @@ -1636,6 +1636,28 @@ class ShowInstance { return $items; } + + public static function GetShowsInstancesInRange($p_timeNow, $p_start, $p_end) + { + global $CC_DBC; + + $sql = "SELECT id FROM cc_show_instances AS si " + ."WHERE (" + ."(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') " + .")"; + $rows = $CC_DBC->GetAll($sql); + + $showInstances = array(); + foreach ($rows as $row){ + $shows[] = new ShowInstance($row['id']); + } + return $showInstances; + } } /* Show Data Access Layer */