diff --git a/.zfproject.xml b/.zfproject.xml index 1e30ef1c8..c93acc463 100644 --- a/.zfproject.xml +++ b/.zfproject.xml @@ -111,6 +111,7 @@ + diff --git a/application/Bootstrap.php b/application/Bootstrap.php index da674ae27..8c4d878f3 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -60,8 +60,8 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $view->headScript()->appendFile('/js/libs/jquery.stickyPanel.js','text/javascript'); //scripts for now playing bar - //$this->view->headScript()->appendFile('/js/playlist/helperfunctions.js','text/javascript'); - //$this->view->headScript()->appendFile('/js/playlist/playlist.js','text/javascript'); + $this->view->headScript()->appendFile('/js/playlist/helperfunctions.js','text/javascript'); + $this->view->headScript()->appendFile('/js/playlist/playlist.js','text/javascript'); $view->headScript()->appendFile('/js/airtime/common/common.js','text/javascript'); } diff --git a/application/controllers/NowplayingController.php b/application/controllers/NowplayingController.php index ead833224..21741574b 100644 --- a/application/controllers/NowplayingController.php +++ b/application/controllers/NowplayingController.php @@ -18,8 +18,8 @@ class NowplayingController extends Zend_Controller_Action public function getDataGridDataAction() { - //$this->view->entries = json_encode(Application_Model_Nowplaying::GetDataGridData()); - $this->view->entries = Application_Model_Nowplaying::GetDataGridData(); + $viewType = $this->_request->getParam('view'); + $this->view->entries = Application_Model_Nowplaying::GetDataGridData($viewType); } public function livestreamAction() diff --git a/application/models/DateHelper.php b/application/models/DateHelper.php new file mode 100644 index 000000000..6dff44715 --- /dev/null +++ b/application/models/DateHelper.php @@ -0,0 +1,47 @@ +_timestamp = date("U"); + } + + function getDate(){ + return date("Y-m-d H:i:s", $this->_timestamp); + } + + function getNowDayStartDiff(){ + $dayStartTS = strtotime(date("Y-m-d", $this->_timestamp)); + return $this->_timestamp - $dayStartTS; + } + + function getNowDayEndDiff(){ + $dayEndTS = strtotime(date("Y-m-d", $this->_timestamp+(86400))); + return $dayEndTS - $this->_timestamp; + } + + public static function ConvertMSToHHMMSSmm($time){ + $hours = floor($time / 3600000); + $time -= 3600000*$hours; + + $minutes = floor($time / 60000); + $time -= 60000*$minutes; + + $seconds = floor($time / 1000); + $time -= 1000*$seconds; + + $ms = $time; + + if (strlen($hours) == 1) + $hours = "0".$hours; + if (strlen($minutes) == 1) + $minutes = "0".$minutes; + if (strlen($seconds) == 1) + $seconds = "0".$seconds; + + return $hours.":".$minutes.":".$seconds.".".$ms; + } +} + diff --git a/application/models/Nowplaying.php b/application/models/Nowplaying.php index 8b02c0f74..17b904e1c 100644 --- a/application/models/Nowplaying.php +++ b/application/models/Nowplaying.php @@ -15,7 +15,7 @@ class Application_Model_Nowplaying if (count($endDate) > 1) $epochEndMS += $endDate[1]; - $blankRow = array(array("b", "-", "-", "-", TimeDateHelper::ConvertMSToHHMMSSmm($epochEndMS - $epochStartMS), "-", "-", "-", "-" , "-", "", "")); + $blankRow = array(array("b", "-", "-", "-", Application_Model_DateHelper::ConvertMSToHHMMSSmm($epochEndMS - $epochStartMS), "-", "-", "-", "-" , "-", "", "")); array_splice($rows, $i, 0, $blankRow); return $rows; } @@ -42,7 +42,7 @@ class Application_Model_Nowplaying return $rows; } - public static function GetDataGridData(){ + public static function GetDataGridData($viewType){ $columnHeaders = array(array("sTitle"=>"type", "bVisible"=>false), array("sTitle"=>"Date"), @@ -52,44 +52,52 @@ class Application_Model_Nowplaying array("sTitle"=>"Song"), array("sTitle"=>"Artist"), array("sTitle"=>"Album"), - array("sTitle"=>"Creator"), array("sTitle"=>"Playlist"), + array("sTitle"=>"Show"), array("sTitle"=>"bgcolor", "bVisible"=>false), array("sTitle"=>"group_id", "bVisible"=>false)); - $timeNow = Schedule::GetSchedulerTime(); + $date = Schedule::GetSchedulerTime(); + $timeNow = $date->getDate(); $currentShow = Schedule::GetCurrentShow($timeNow); - + $groupIDs = array(); + if (count($currentShow) > 0){ - $dbRows = Schedule::GetCurrentShowGroupIDs($currentShow[0]["id"]); - $groupIDs = array(); + $dbRows = Show_DAL::GetShowGroupIDs($currentShow[0]["id"]); foreach ($dbRows as $row){ array_push($groupIDs, $row["group_id"]); } } - - $previous = Schedule::Get_Scheduled_Item_Data($timeNow, -1, 1, "60 seconds"); - $current = Schedule::Get_Scheduled_Item_Data($timeNow, 0); - $next = Schedule::Get_Scheduled_Item_Data($timeNow, 1, 10, "48 hours"); + + if ($viewType == "now"){ + $previous = Schedule::Get_Scheduled_Item_Data($timeNow, -1, 1, "60 seconds"); + $current = Schedule::Get_Scheduled_Item_Data($timeNow, 0); + $next = Schedule::Get_Scheduled_Item_Data($timeNow, 1, 10, "24 hours"); + } else { + + $previous = Schedule::Get_Scheduled_Item_Data($timeNow, -1, "ALL", $date->getNowDayStartDiff()." seconds"); + $current = Schedule::Get_Scheduled_Item_Data($timeNow, 0); + $next = Schedule::Get_Scheduled_Item_Data($timeNow, 1, "ALL", $date->getNowDayEndDiff()." seconds"); + } $rows = array(); foreach ($previous as $item){ $color = (count($currentShow) > 0) && in_array($item["group_id"], $groupIDs) ? "x" : ""; array_push($rows, array("p", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"], - $item["album_title"], "x" , $item["name"], $color, $item["group_id"])); + $item["album_title"], $item["name"], $item["show_name"], $color, $item["group_id"])); } foreach ($current as $item){ array_push($rows, array("c", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"], - $item["album_title"], "x" , $item["name"], "", $item["group_id"])); + $item["album_title"], $item["name"], $item["show_name"], "", $item["group_id"])); } foreach ($next as $item){ $color = (count($currentShow) > 0) && in_array($item["group_id"], $groupIDs) ? "x" : ""; array_push($rows, array("n", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"], - $item["album_title"], "x" , $item["name"], $color, $item["group_id"])); + $item["album_title"], $item["name"], $item["show_name"], $color, $item["group_id"])); } $rows = Application_Model_Nowplaying::FindGaps($rows); @@ -99,30 +107,3 @@ class Application_Model_Nowplaying } } -class TimeDateHelper -{ - - public static function ConvertMSToHHMMSSmm($time){ - $hours = floor($time / 3600000); - $time -= 3600000*$hours; - - $minutes = floor($time / 60000); - $time -= 60000*$minutes; - - $seconds = floor($time / 1000); - $time -= 1000*$seconds; - - $ms = $time; - - if (strlen($hours) == 1) - $hours = "0".$hours; - if (strlen($minutes) == 1) - $minutes = "0".$minutes; - if (strlen($seconds) == 1) - $seconds = "0".$seconds; - - return $hours.":".$minutes.":".$seconds.".".$ms; - } -} - - diff --git a/application/models/Schedule.php b/application/models/Schedule.php index 12f661cda..9a08f26ee 100644 --- a/application/models/Schedule.php +++ b/application/models/Schedule.php @@ -446,7 +446,8 @@ class Schedule { * @return date Current server time. */ public static function GetSchedulerTime() { - return date("Y-m-d H:i:s"); + $date = new Application_Model_DateHelper; + return $date; } /** @@ -462,7 +463,8 @@ class Schedule { return "{}"; } - $timeNow = Schedule::GetSchedulerTime(); + $date = Schedule::GetSchedulerTime(); + $timeNow = $date->getDate(); return array("schedulerTime"=>gmdate("Y-m-d H:i:s"), "previous"=>Schedule::Get_Scheduled_Item_Data($timeNow, -1, $prev, "24 hours"), "current"=>Schedule::Get_Scheduled_Item_Data($timeNow, 0), @@ -497,15 +499,17 @@ class Schedule { */ public static function Get_Scheduled_Item_Data($timeNow, $timePeriod=0, $count = 0, $interval="0 hours"){ global $CC_CONFIG, $CC_DBC; - $sql = "SELECT pt.name, ft.track_title, ft.artist_name, ft.album_title, st.starts, st.ends, st.clip_length, st.group_id" - ." FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt" + $sql = "SELECT DISTINCT pt.name, ft.track_title, ft.artist_name, ft.album_title, st.starts, st.ends, st.clip_length, st.group_id, show.name as show_name" + ." FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt, $CC_CONFIG[showSchedule] ss, $CC_CONFIG[showTable] show" ." WHERE st.playlist_id = pt.id" - ." AND st.file_id = ft.id"; + ." AND st.file_id = ft.id" + ." AND st.group_id = ss.group_id" + ." AND ss.show_id = show.id"; if ($timePeriod < 0){ $sql .= " AND st.ends < TIMESTAMP '$timeNow'" ." AND st.ends > (TIMESTAMP '$timeNow' - INTERVAL '$interval')" - ." ORDER BY st.starts DESC" + ." ORDER BY st.starts" ." LIMIT $count"; } else if ($timePeriod == 0){ $sql .= " AND st.starts < TIMESTAMP '$timeNow'" @@ -516,13 +520,12 @@ class Schedule { ." ORDER BY st.starts" ." LIMIT $count"; } - + $rows = $CC_DBC->GetAll($sql); return $rows; } /* - public static function GetPreviousItems($timeNow, $prevCount = 1, $prevInterval="24 hours"){ global $CC_CONFIG, $CC_DBC; $sql = "SELECT pt.name, ft.track_title, ft.artist_name, ft.album_title, st.starts, st.ends, st.clip_length, st.group_id" @@ -602,18 +605,6 @@ class Schedule { return $rows; } - - - public static function GetCurrentShowGroupIDs($showID){ - global $CC_CONFIG, $CC_DBC; - - $sql = "SELECT group_id" - ." FROM $CC_CONFIG[showSchedule]" - ." WHERE show_id = $showID"; - - $rows = $CC_DBC->GetAll($sql); - return $rows; - } /** * Convert a time string in the format "YYYY-MM-DD HH:mm:SS" diff --git a/application/models/Shows.php b/application/models/Shows.php index f3c6d13eb..a2c3f7243 100644 --- a/application/models/Shows.php +++ b/application/models/Shows.php @@ -652,3 +652,38 @@ class Show { return StoredFile::searchPlaylistsForSchedule($length, $datatables); } } + +/* Show Data Access Layer */ +class Show_DAL{ + + /* Given a group_id, get all show data related to + * id. This is useful in the case where you have an item + * in the schedule table and you want to find out more about + * the show it is in without joining the schedule and show tables + * (which causes problems with duplicate items) + */ + public static function GetShowData($group_id){ + global $CC_DBC; + + $sql="SELECT * FROM cc_show_schedule as ss, cc_show as s" + ." WHERE ss.show_id = s.id" + ." AND ss.group_id = $group_id" + ." LIMIT 1"; + + return $CC_DBC->GetOne($sql); + } + + /* Given a show ID, this function returns what group IDs + * are present in this show. */ + public static function GetShowGroupIDs($showID){ + global $CC_CONFIG, $CC_DBC; + + $sql = "SELECT group_id" + ." FROM $CC_CONFIG[showSchedule]" + ." WHERE show_id = $showID"; + + $rows = $CC_DBC->GetAll($sql); + return $rows; + } + +} diff --git a/application/views/scripts/nowplaying/index.phtml b/application/views/scripts/nowplaying/index.phtml index 11d775d98..b7faa8336 100644 --- a/application/views/scripts/nowplaying/index.phtml +++ b/application/views/scripts/nowplaying/index.phtml @@ -1 +1,2 @@ +
Now View | Day View
diff --git a/public/js/playlist/nowplayingdatagrid.js b/public/js/playlist/nowplayingdatagrid.js index a96c3e890..51cb4e8b5 100644 --- a/public/js/playlist/nowplayingdatagrid.js +++ b/public/js/playlist/nowplayingdatagrid.js @@ -45,12 +45,35 @@ function notifySongEnd(){ createDataGrid(); } +/* +function updateDataGrid(){ + var table = $('#nowplayingtable'); + //table.dataTable().fnClearTable(); + + for (var i=0; i' ); $('#nowplayingtable').dataTable( { @@ -59,8 +82,9 @@ function createDataGrid(){ "bFilter": false, "bInfo": false, "bLengthChange": false, + "bPaginate": false, "aaData": datagridData.rows, - "aoColumns": datagridData.columnHeaders, + "aoColumns": columns, "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { if (aData[aData.length-2] != "") $(nRow).attr("style", "background-color:#166622"); @@ -71,20 +95,30 @@ function createDataGrid(){ return nRow; } } ); + + setTimeout(init2, 5000); +} + +var viewType = "now" //"day"; +function setViewType(type){ + if (type == 0){ + viewType = "now"; + } else { + viewType = "day"; + } + init2(); } function init2(){ - $.ajax({ url: "/Nowplaying/get-data-grid-data/format/json", dataType:"json", success:function(data){ + $.ajax({ url: "/Nowplaying/get-data-grid-data/format/json/view/" + viewType, dataType:"json", success:function(data){ datagridData = data.entries; - createDataGrid(); + createDataGrid(); }}); if (typeof registerSongEndListener == 'function' && !registered){ registered = true; registerSongEndListener(notifySongEnd); } - - setTimeout(init2, 5000); } $(document).ready(function() {