diff --git a/airtime_mvc/application/controllers/NowplayingController.php b/airtime_mvc/application/controllers/NowplayingController.php index 742cd1db3..42e317983 100644 --- a/airtime_mvc/application/controllers/NowplayingController.php +++ b/airtime_mvc/application/controllers/NowplayingController.php @@ -22,9 +22,20 @@ class NowplayingController extends Zend_Controller_Action public function getDataGridDataAction() { + $iTotal = 5; + $iFilteredTotal = 5; + + $output = array( + "sEcho" => intval($this->_request->getParam('sEcho')), + "iTotalRecords" => $iTotal, + "iTotalDisplayRecords" => $iFilteredTotal + ); + $viewType = $this->_request->getParam('view'); $dateString = $this->_request->getParam('date'); - $this->view->entries = Application_Model_Nowplaying::GetDataGridData($viewType, $dateString); + $output["aaData"] = Application_Model_Nowplaying::GetDataGridData($viewType, $dateString); + + die(json_encode($output)); } public function livestreamAction() diff --git a/airtime_mvc/application/models/Nowplaying.php b/airtime_mvc/application/models/Nowplaying.php index a8b4e7e8f..84c3f9ccd 100644 --- a/airtime_mvc/application/models/Nowplaying.php +++ b/airtime_mvc/application/models/Nowplaying.php @@ -145,6 +145,27 @@ class Application_Model_Nowplaying } */ + public static function CreateHeaderRow($p_showName, $p_showStart, $p_showEnd){ + return array("h", $p_showName, $p_showStart, $p_showEnd, "", "", "", "", "", "", ""); + } + + public static function CreateDatatableRows($p_dbRows){ + + $dataTablesRows = array(); + + foreach ($p_dbRows as $dbRow){ + $dataTablesRows[] = array('a', $dbRow['show_starts'], $dbRow['show_starts'], $dbRow['show_ends'], + $dbRow['clip_length'], $dbRow['track_title'], $dbRow['artist_name'], $dbRow['album_title'], + $dbRow['playlist_name'], $dbRow['playlist_name'], $dbRow['show_name']); + } + + return $dataTablesRows; + } + + public static function CreateGapRow($p_gapTime){ + return array("g", $p_gapTime, "", "", "", "", "", "", "", "", ""); + } + public static function GetDataGridData($viewType, $dateString){ if ($viewType == "now"){ @@ -163,24 +184,31 @@ class Application_Model_Nowplaying $endCutoff = $date->getNowDayEndDiff(); } - $showInstances = Show::GetShowsInstancesInRange($timeNow, $startCutoff, $endCutoff); + $data = array(); - $output = array( - "sEcho" => intval($_GET['sEcho']), - "iTotalRecords" => $iTotal, - "iTotalDisplayRecords" => $iFilteredTotal, - "aaData" => array() - ); + $showIds = ShowInstance::GetShowsInstancesIdsInRange($timeNow, $startCutoff, $endCutoff); + foreach ($showIds as $showId){ + $instanceId = $showId['id']; - foreach ($showInstances as $si){ - $rows = $si->getShowContent(); - foreach ($rows as $row){ - $output['aaData'][] = $row; - } - $output['aaData'][] = $si->getShowEndGap(); + $si = new ShowInstance($instanceId); + + $showId->getShowId(); + $show = new Show($showId); + + //append show header row + $data[] = Application_Model_Nowplaying::CreateHeaderRow($show->getName(), $si->getShowStart(), $si->getShowEnd()); + + $scheduledItems = $si->getScheduleItemsInRange($timeNow, $startCutoff, $endCutoff); + $dataTablesRows = Application_Model_Nowplaying::CreateDatatableRows($scheduledItems); + + //append show audio item rows + $data = array_merge($data, $dataTablesRows); + + //append show gap time row + $gapTime = $si->getShowEndGapTime(); + $data[] = Application_Model_Nowplaying::CreateGapRow($gapTime); } - return $output; + return $data; } - } diff --git a/airtime_mvc/application/models/Shows.php b/airtime_mvc/application/models/Shows.php index a9c4008d4..5fcd967ff 100644 --- a/airtime_mvc/application/models/Shows.php +++ b/airtime_mvc/application/models/Shows.php @@ -1636,8 +1636,8 @@ class ShowInstance { return $items; } - - public static function GetShowsInstancesInRange($p_timeNow, $p_start, $p_end) + + public static function GetShowsInstancesIdsInRange($p_timeNow, $p_start, $p_end) { global $CC_DBC; @@ -1650,13 +1650,52 @@ class ShowInstance { ."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); + return $rows; + } + + public function getScheduleItemsInRange($timeNow, $start, $end) + { + global $CC_DBC; + + $instanceId = $this->_instanceId; + + $sql = "SELECT" + ." si.starts as show_starts," + ." si.ends as show_ends," + ." si.rebroadcast as rebroadcast," + ." st.starts as item_starts," + ." st.ends as item_ends," + ." st.clip_length as clip_length," + ." ft.track_title as track_title," + ." ft.artist_name as artist_name," + ." ft.album_title as album_title," + ." s.name as show_name," + ." si.id as instance_id," + ." pt.name as playlist_name" + ." FROM $CC_CONFIG[showInstances] si" + ." LEFT JOIN $CC_CONFIG[scheduleTable] st" + ." ON st.instance_id = si.id" + ." LEFT JOIN $CC_CONFIG[playListTable] pt" + ." ON st.playlist_id = pt.id" + ." LEFT JOIN $CC_CONFIG[filesTable] ft" + ." 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'))" + //checking for st.starts IS NULL so that the query also returns shows that do not have any items scheduled. + ." AND (st.starts < si.ends OR st.starts IS NULL)" + ." AND si.id = $instanceId" + ." ORDER BY si.starts, st.starts"; - $showInstances = array(); - foreach ($rows as $row){ - $shows[] = new ShowInstance($row['id']); - } - return $showInstances; + return $CC_DBC->GetAll($sql); + } + + public function getShowEndGapTime(){ + return 5; } } @@ -1693,41 +1732,6 @@ class Show_DAL { return $rows; } - public static function GetShowsInRange($timeNow, $start, $end) - { - global $CC_CONFIG, $CC_DBC; - $sql = "SELECT" - ." si.starts as show_starts," - ." si.ends as show_ends," - ." si.rebroadcast as rebroadcast," - ." st.starts as item_starts," - ." st.ends as item_ends," - ." st.clip_length as clip_length," - ." ft.track_title as track_title," - ." ft.artist_name as artist_name," - ." ft.album_title as album_title," - ." s.name as show_name," - ." si.id as instance_id," - ." pt.name as playlist_name" - ." FROM $CC_CONFIG[showInstances] si" - ." LEFT JOIN $CC_CONFIG[scheduleTable] st" - ." ON st.instance_id = si.id" - ." LEFT JOIN $CC_CONFIG[playListTable] pt" - ." ON st.playlist_id = pt.id" - ." LEFT JOIN $CC_CONFIG[filesTable] ft" - ." 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'))" - //checking for st.starts IS NULL so that the query also returns shows that do not have any items scheduled. - ." AND (st.starts < si.ends OR st.starts IS NULL)" - ." ORDER BY si.starts, st.starts"; - - return $CC_DBC->GetAll($sql); - } - public static function GetShowsByDayOfWeek($day){ //DOW FROM TIMESTAMP //The day of the week (0 - 6; Sunday is 0) (for timestamp values only) @@ -1748,8 +1752,6 @@ class Show_DAL { ." AND EXTRACT(WEEK FROM si.starts) = EXTRACT(WEEK FROM localtimestamp)" ." ORDER BY si.starts"; - //echo $sql; - return $CC_DBC->GetAll($sql); } }