From 416c6ceb1099b189c1e5de361a910a995532846e Mon Sep 17 00:00:00 2001 From: martin Date: Sun, 13 Feb 2011 15:35:41 -0500 Subject: [PATCH] -fixed bug where a song would appear as current song and next song simultaneously. -show background color switching on the list-view should now be instant. --- application/models/Nowplaying.php | 16 ++++++++++------ application/models/Schedule.php | 11 ++++------- application/models/Shows.php | 2 +- public/js/playlist/nowplayingdatagrid.js | 19 ++++++++++--------- public/js/playlist/playlist.js | 21 ++++----------------- 5 files changed, 29 insertions(+), 40 deletions(-) diff --git a/application/models/Nowplaying.php b/application/models/Nowplaying.php index 966470528..43d6bdc4b 100644 --- a/application/models/Nowplaying.php +++ b/application/models/Nowplaying.php @@ -75,23 +75,27 @@ class Application_Model_Nowplaying foreach ($previous as $item){ array_push($rows, array("p", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"], - $item["album_title"], $item["name"], $item["show_name"], $item["current_show"], $item["group_id"])); + $item["album_title"], $item["name"], $item["show_name"], $item["instance_id"], $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"], $item["name"], $item["show_name"], $item["current_show"], $item["group_id"])); + $item["album_title"], $item["name"], $item["show_name"], $item["instance_id"], $item["group_id"])); } foreach ($next as $item){ array_push($rows, array("n", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"], - $item["album_title"], $item["name"], $item["show_name"], $item["current_show"], $item["group_id"])); + $item["album_title"], $item["name"], $item["show_name"], $item["instance_id"], $item["group_id"])); } - + + $rows = Application_Model_Nowplaying::FindGaps($rows); - $data = array("rows"=>$rows); + + $date = new Application_Model_DateHelper; + $timeNow = $date->getDate(); + + $data = array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$rows); return $data; } } - diff --git a/application/models/Schedule.php b/application/models/Schedule.php index 018c52504..87ff2193b 100644 --- a/application/models/Schedule.php +++ b/application/models/Schedule.php @@ -469,11 +469,8 @@ class Schedule { */ public static function Get_Scheduled_Item_Data($timeStamp, $timePeriod=0, $count = 0, $interval="0 hours"){ global $CC_CONFIG, $CC_DBC; - - $date = new Application_Model_DateHelper; - $timeNow = $date->getDate(); - - $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, (si.starts <= TIMESTAMP '$timeNow' AND si.ends > TIMESTAMP '$timeNow') as current_show" + + $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, st.instance_id" ." FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt, $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] show" ." WHERE st.playlist_id = pt.id" ." AND st.file_id = ft.id" @@ -487,9 +484,9 @@ class Schedule { ." LIMIT $count"; } else if ($timePeriod == 0){ $sql .= " AND st.starts <= TIMESTAMP '$timeStamp'" - ." AND st.ends > TIMESTAMP '$timeStamp'"; + ." AND st.ends >= TIMESTAMP '$timeStamp'"; } else if ($timePeriod > 0){ - $sql .= " AND st.starts >= TIMESTAMP '$timeStamp'" + $sql .= " AND st.starts > TIMESTAMP '$timeStamp'" ." AND st.starts < (TIMESTAMP '$timeStamp' + INTERVAL '$interval')" ." ORDER BY st.starts" ." LIMIT $count"; diff --git a/application/models/Shows.php b/application/models/Shows.php index 27ab6b101..c6902fa80 100644 --- a/application/models/Shows.php +++ b/application/models/Shows.php @@ -733,7 +733,7 @@ class Show_DAL{ $date = $timestamp[0]; $time = $timestamp[1]; - $sql = "SELECT si.starts as start_timestamp, si.ends as end_timestamp, s.name, s.id" + $sql = "SELECT si.starts as start_timestamp, si.ends as end_timestamp, s.name, s.id, si.id as instance_id" ." FROM $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s" ." WHERE si.show_id = s.id" ." AND si.starts <= TIMESTAMP '$timeNow'" diff --git a/public/js/playlist/nowplayingdatagrid.js b/public/js/playlist/nowplayingdatagrid.js index f5863ad1e..98cd108bb 100644 --- a/public/js/playlist/nowplayingdatagrid.js +++ b/public/js/playlist/nowplayingdatagrid.js @@ -1,5 +1,5 @@ -var registered = false; var datagridData = null; +var currentShowInstanceID = -1; function getDateText(obj){ var str = obj.aData[ obj.iDataColumn ].toString(); @@ -32,7 +32,7 @@ function changeTimePrecision(str){ return str; } -function notifySongEnd(){ +function notifySongStart(){ for (var i=0; i 0) + currentShowInstanceID = datagridData.currentShow[0].instance_id; updateDataTable(); }}); } @@ -95,13 +102,7 @@ function getData(){ function init2(){ getData(); - if (typeof registerSongEndListener == 'function' && !registered){ - registered = true; - registerSongEndListener(notifySongEnd); - } - setTimeout(init2, 5000); - } function redirect(url){ @@ -124,7 +125,7 @@ function createDataGrid(){ "bPaginate": false, "aoColumns": columns, "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { - if (aData[aData.length-2] == "t") + if (aData[aData.length-2] == currentShowInstanceID) $(nRow).addClass("playing-list"); if (aData[0] == "c") $(nRow).attr("class", "playing-song"); diff --git a/public/js/playlist/playlist.js b/public/js/playlist/playlist.js index 697707bd5..17e48082f 100644 --- a/public/js/playlist/playlist.js +++ b/public/js/playlist/playlist.js @@ -13,8 +13,6 @@ var currentElem; var serverUpdateInterval = 5000; var uiUpdateInterval = 200; -var songEndFunc; - //set to "development" if we are developing :). Useful to disable alerts //when entering production mode. var APPLICATION_ENV = ""; @@ -25,20 +23,6 @@ var APPLICATION_ENV = ""; var nextSongPrepare = true; var nextShowPrepare = true; -/* Another script can register its function here - * when it wishes to know when a song ends. */ -function registerSongEndListener(func){ - songEndFunc = func; -} - -function notifySongEndListener(){ - if (typeof songEndFunc == "function"){ - //create a slight delay in execution to allow the browser - //to update the display. - setTimeout(songEndFunc, 50); - } -} - function getTrackInfo(song){ var str = ""; @@ -66,12 +50,15 @@ function newSongStart(){ nextSongPrepare = true; currentSong[0] = nextSongs.shift(); - notifySongEndListener(); + notifySongStart(); } function nextShowStart(){ nextShowPrepare = true; currentShow[0] = nextShow.shift(); + + //call function in nowplayingdatagrid.js + notifyShowStart(currentShow[0]); } /* Called every "uiUpdateInterval" mseconds. */