From 71023a52b3a5721332f625b33cf3b37da783d778 Mon Sep 17 00:00:00 2001 From: mkonecny Date: Tue, 1 Feb 2011 20:28:38 -0500 Subject: [PATCH] -fixed bug CC-1837 -show progress-bar will now update even when an audio item is not playing --- application/models/Nowplaying.php | 42 +++-- application/models/Schedule.php | 189 +++++++++++--------- application/views/scripts/error/error.phtml | 1 - public/index.php | 4 + public/js/playlist/playlist.js | 135 +++++++------- 5 files changed, 201 insertions(+), 170 deletions(-) diff --git a/application/models/Nowplaying.php b/application/models/Nowplaying.php index 611e01b72..c5cd4ba9a 100644 --- a/application/models/Nowplaying.php +++ b/application/models/Nowplaying.php @@ -4,11 +4,7 @@ class Application_Model_Nowplaying { public static function GetDataGridData(){ - $timeNow = Schedule::GetSchedulerTime(); - $previous = Schedule::GetPreviousItems($timeNow, 1); - $current = Schedule::GetCurrentlyPlaying($timeNow); - $next = Schedule::GetNextItems($timeNow, 10); - + $columnHeaders = array(array("sTitle"=>"type", "bVisible"=>false), array("sTitle"=>"Date"), array("sTitle"=>"Start"), @@ -21,30 +17,44 @@ class Application_Model_Nowplaying array("sTitle"=>"Playlist"), array("sTitle"=>"bgcolor", "bVisible"=>false), array("sTitle"=>"group_id", "bVisible"=>false)); - $rows = array(); - $current_group_id = -1; - if (count($current) != 0){ - $current_group_id = $current[0]["group_id"]; - } + $timeNow = Schedule::GetSchedulerTime(); + $currentShow = Schedule::GetCurrentShow($timeNow); - 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"], "x" , $item["name"], ($item["group_id"] == $current_group_id ? $item["background_color"] : ""), $item["group_id"])); + if (count($currentShow) > 0){ + $dbRows = Schedule::GetCurrentShowGroupIDs($currentShow[0]["id"]); + $groupIDs = array(); + + foreach ($dbRows as $row){ + array_push($groupIDs, $row["group_id"]); + } } + $previous = Schedule::GetPreviousItems($timeNow, 1); + $current = Schedule::GetCurrentlyPlaying($timeNow); + $next = Schedule::GetNextItems($timeNow, 10); + + $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"])); + } 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["background_color"], $item["group_id"])); + $item["album_title"], "x" , $item["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"], ($item["group_id"] == $current_group_id ? $item["background_color"] : ""), $item["group_id"])); + $item["album_title"], "x" , $item["name"], $color, $item["group_id"])); } + $data = array("columnHeaders"=>$columnHeaders, "rows"=>$rows); - return array("columnHeaders"=>$columnHeaders, "rows"=>$rows); + return $data; } } diff --git a/application/models/Schedule.php b/application/models/Schedule.php index 62bf121b2..c519d74b3 100644 --- a/application/models/Schedule.php +++ b/application/models/Schedule.php @@ -170,12 +170,12 @@ class ScheduleGroup { return $this->add($startTime, $p_audioFileId); } - public function addPlaylistAfter($p_groupId, $p_playlistId) { + public function addPlaylistAfter($p_groupId, $p_playlistId) { global $CC_CONFIG, $CC_DBC; // Get the end time for the given entry $sql = "SELECT MAX(ends) FROM ".$CC_CONFIG["scheduleTable"] ." WHERE group_id=$p_groupId"; - + $startTime = $CC_DBC->GetOne($sql); return $this->add($startTime, null, $p_playlistId); } @@ -278,80 +278,80 @@ class Schedule { return ($count == '0'); } - public static function getTimeUnScheduledInRange($s_datetime, $e_datetime) { - global $CC_CONFIG, $CC_DBC; + public static function getTimeUnScheduledInRange($s_datetime, $e_datetime) { + global $CC_CONFIG, $CC_DBC; - $sql = "SELECT timestamp '{$s_datetime}' > timestamp '{$e_datetime}'"; - $isNextDay = $CC_DBC->GetOne($sql); + $sql = "SELECT timestamp '{$s_datetime}' > timestamp '{$e_datetime}'"; + $isNextDay = $CC_DBC->GetOne($sql); - if($isNextDay === 't') { - $sql = "SELECT date '{$e_datetime}' + interval '1 day'"; - $e_datetime = $CC_DBC->GetOne($sql); - } + if($isNextDay === 't') { + $sql = "SELECT date '{$e_datetime}' + interval '1 day'"; + $e_datetime = $CC_DBC->GetOne($sql); + } - $sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]." - WHERE (starts >= '{$s_datetime}') - AND (ends <= '{$e_datetime}')"; + $sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]." + WHERE (starts >= '{$s_datetime}') + AND (ends <= '{$e_datetime}')"; - $time = $CC_DBC->GetOne($sql); + $time = $CC_DBC->GetOne($sql); - if(is_null($time)) - $time = 0; + if(is_null($time)) + $time = 0; - $sql = "SELECT TIMESTAMP '{$e_datetime}' - TIMESTAMP '{$s_datetime}'"; - $length = $CC_DBC->GetOne($sql); + $sql = "SELECT TIMESTAMP '{$e_datetime}' - TIMESTAMP '{$s_datetime}'"; + $length = $CC_DBC->GetOne($sql); - $sql = "SELECT INTERVAL '{$length}' - INTERVAL '{$time}'"; - $time_left =$CC_DBC->GetOne($sql); + $sql = "SELECT INTERVAL '{$length}' - INTERVAL '{$time}'"; + $time_left =$CC_DBC->GetOne($sql); - return $time_left; - } + return $time_left; + } - public static function getTimeScheduledInRange($s_datetime, $e_datetime) { - global $CC_CONFIG, $CC_DBC; + public static function getTimeScheduledInRange($s_datetime, $e_datetime) { + global $CC_CONFIG, $CC_DBC; - $sql = "SELECT timestamp '{$s_datetime}' > timestamp '{$e_datetime}'"; - $isNextDay = $CC_DBC->GetOne($sql); + $sql = "SELECT timestamp '{$s_datetime}' > timestamp '{$e_datetime}'"; + $isNextDay = $CC_DBC->GetOne($sql); - if($isNextDay === 't') { - $sql = "SELECT date '{$e_datetime}' + interval '1 day'"; - $e_datetime = $CC_DBC->GetOne($sql); - } + if($isNextDay === 't') { + $sql = "SELECT date '{$e_datetime}' + interval '1 day'"; + $e_datetime = $CC_DBC->GetOne($sql); + } - $sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]." - WHERE (starts >= '{$s_datetime}') - AND (ends <= '{$e_datetime}')"; + $sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]." + WHERE (starts >= '{$s_datetime}') + AND (ends <= '{$e_datetime}')"; - $res = $CC_DBC->GetOne($sql); + $res = $CC_DBC->GetOne($sql); - if(is_null($res)) - return 0; + if(is_null($res)) + return 0; - return $res; - } + return $res; + } - public static function getPercentScheduledInRange($s_datetime, $e_datetime) { + public static function getPercentScheduledInRange($s_datetime, $e_datetime) { - $time = Schedule::getTimeScheduledInRange($s_datetime, $e_datetime); + $time = Schedule::getTimeScheduledInRange($s_datetime, $e_datetime); - $con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME); + $con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME); $sql = "SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '{$s_datetime}')"; - $r = $con->query($sql); - $s_epoch = $r->fetchColumn(0); + $r = $con->query($sql); + $s_epoch = $r->fetchColumn(0); - $sql = "SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '{$e_datetime}')"; - $r = $con->query($sql); - $e_epoch = $r->fetchColumn(0); + $sql = "SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '{$e_datetime}')"; + $r = $con->query($sql); + $e_epoch = $r->fetchColumn(0); - $sql = "SELECT EXTRACT(EPOCH FROM INTERVAL '{$time}')"; - $r = $con->query($sql); - $i_epoch = $r->fetchColumn(0); + $sql = "SELECT EXTRACT(EPOCH FROM INTERVAL '{$time}')"; + $r = $con->query($sql); + $i_epoch = $r->fetchColumn(0); - $percent = ceil(($i_epoch / ($e_epoch - $s_epoch)) * 100); + $percent = ceil(($i_epoch / ($e_epoch - $s_epoch)) * 100); - return $percent; - } + return $percent; + } // public function onAddTrackToPlaylist($playlistId, $audioTrackId) { // @@ -387,7 +387,7 @@ class Schedule { * "end"/"ends" (aliases to the same thing) as YYYY-MM-DD HH:MM:SS.nnnnnn * "group_id"/"id" (aliases to the same thing) * "clip_length" (for audio clips this is the length of the audio clip, - * for playlists this is the length of the entire playlist) + * for playlists this is the length of the entire playlist) * "name" (playlist only) * "creator" (playlist only) * "file_id" (audioclip only) @@ -401,7 +401,7 @@ class Schedule { * @param boolean $p_playlistsOnly * Retrieve playlists as a single item. * @return array - * Returns empty array if nothing found + * Returns empty array if nothing found */ public static function GetItems($p_fromDateTime, $p_toDateTime, $p_playlistsOnly = true) { global $CC_CONFIG, $CC_DBC; @@ -472,24 +472,23 @@ class Schedule { } $timeNow = Schedule::GetSchedulerTime(); - return array("schedulerTime"=>gmdate("Y-m-d H:i:s"),"previous"=>Schedule::GetPreviousItems($timeNow), - "current"=>Schedule::GetCurrentlyPlaying($timeNow), + return array("schedulerTime"=>gmdate("Y-m-d H:i:s"), + "previous"=>Schedule::GetPreviousItems($timeNow), + "current"=>Schedule::GetCurrentlyPlaying($timeNow), "next"=>Schedule::GetNextItems($timeNow), + "showStartEndTime"=>Schedule::GetCurrentShow($timeNow), "timezone"=> date("T"), "timezoneOffset"=> date("Z")); } public static function GetPreviousItems($timeNow, $prevCount = 1){ 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, sdt.start_time, sdt.end_time, showt.background_color" - ." FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt, $CC_CONFIG[showSchedule] sst, $CC_CONFIG[showDays] sdt, $CC_CONFIG[showTable] showt" + $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" ." WHERE st.ends < TIMESTAMP '$timeNow'" ." AND st.ends > (TIMESTAMP '$timeNow' - INTERVAL '24 hours')" ." AND st.playlist_id = pt.id" ." AND st.file_id = ft.id" - ." AND st.group_id = sst.group_id" - ." AND sdt.show_id = sst.show_id" - ." AND showt.id = sst.show_id" ." ORDER BY st.starts DESC" ." LIMIT $prevCount"; $rows = $CC_DBC->GetAll($sql); @@ -499,40 +498,60 @@ class Schedule { public static function GetCurrentlyPlaying($timeNow){ 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, sdt.start_time, sdt.end_time, showt.background_color" + $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, $CC_CONFIG[showSchedule] sst, $CC_CONFIG[showDays] sdt, $CC_CONFIG[showTable] showt" + ."$CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt" ." WHERE st.starts < TIMESTAMP '$timeNow'" ." AND st.ends > TIMESTAMP '$timeNow'" ." AND st.playlist_id = pt.id" - ." AND st.file_id = ft.id" - ." AND st.group_id = sst.group_id" - ." AND sdt.show_id = sst.show_id" - ." AND showt.id = sst.show_id"; + ." AND st.file_id = ft.id"; $rows = $CC_DBC->GetAll($sql); return $rows; } public static function GetNextItems($timeNow, $nextCount = 1) { 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, sdt.start_time, sdt.end_time, showt.background_color" - ." FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt, $CC_CONFIG[showSchedule] sst, $CC_CONFIG[showDays] sdt, $CC_CONFIG[showTable] showt" + $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" ." WHERE st.starts > TIMESTAMP '$timeNow'" ." AND st.ends < (TIMESTAMP '$timeNow' + INTERVAL '24 hours')" ." AND st.playlist_id = pt.id" ." AND st.file_id = ft.id" - ." AND st.group_id = sst.group_id" - ." AND sdt.show_id = sst.show_id" - ." AND showt.id = sst.show_id" ." ORDER BY st.starts" ." LIMIT $nextCount"; $rows = $CC_DBC->GetAll($sql); return $rows; } - public static function GetStatus() { - + public static function GetCurrentShow($timeNow) { + global $CC_CONFIG, $CC_DBC; + + $timestamp = preg_split("/ /", $timeNow); + $date = $timestamp[0]; + $time = $timestamp[1]; + + $sql = "SELECT current_date + sd.start_time as start_timestamp, current_date + sd.end_time as end_timestamp, s.name, s.id" + ." FROM $CC_CONFIG[showDays] sd, $CC_CONFIG[showTable] s" + ." WHERE sd.show_id = s.id" + ." AND sd.first_show <= DATE '$date'" + ." AND sd.start_time <= TIME '$time'" + ." AND sd.last_show > DATE '$date'" + ." AND sd.end_time > TIME '$time'"; + + $rows = $CC_DBC->GetAll($sql); + 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" @@ -637,9 +656,9 @@ class Schedule { * Export the schedule in json formatted for pypo (the liquidsoap scheduler) * * @param string $range - * In the format "YYYY-MM-DD HH:mm:ss" + * In the format "YYYY-MM-DD HH:mm:ss" * @param string $source - * In the format "YYYY-MM-DD HH:mm:ss" + * In the format "YYYY-MM-DD HH:mm:ss" */ public static function ExportRangeAsJson($p_fromDateTime, $p_toDateTime) { @@ -675,8 +694,8 @@ class Schedule { $playlists[$pkey]['schedule_id'] = $dx['group_id']; $playlists[$pkey]['user_id'] = 0; $playlists[$pkey]['id'] = $dx["playlist_id"]; - $playlists[$pkey]['start'] = Schedule::CcTimeToPypoTime($dx["start"]); - $playlists[$pkey]['end'] = Schedule::CcTimeToPypoTime($dx["end"]); + $playlists[$pkey]['start'] = Schedule::CcTimeToPypoTime($dx["start"]); + $playlists[$pkey]['end'] = Schedule::CcTimeToPypoTime($dx["end"]); } } @@ -697,13 +716,13 @@ class Schedule { $cueOut = Schedule::WallTimeToMillisecs($item["cue_out"]); } $medias[] = array( - 'id' => $storedFile->getGunid(), //$item["file_id"], - 'uri' => $uri, - 'fade_in' => Schedule::WallTimeToMillisecs($item["fade_in"]), - 'fade_out' => Schedule::WallTimeToMillisecs($item["fade_out"]), - 'fade_cross' => 0, - 'cue_in' => Schedule::WallTimeToMillisecs($item["cue_in"]), - 'cue_out' => $cueOut, + 'id' => $storedFile->getGunid(), //$item["file_id"], + 'uri' => $uri, + 'fade_in' => Schedule::WallTimeToMillisecs($item["fade_in"]), + 'fade_out' => Schedule::WallTimeToMillisecs($item["fade_out"]), + 'fade_cross' => 0, + 'cue_in' => Schedule::WallTimeToMillisecs($item["cue_in"]), + 'cue_out' => $cueOut, 'export_source' => 'scheduler' ); } diff --git a/application/views/scripts/error/error.phtml b/application/views/scripts/error/error.phtml index b3f063642..feea0c563 100644 --- a/application/views/scripts/error/error.phtml +++ b/application/views/scripts/error/error.phtml @@ -8,7 +8,6 @@

An error occurred

message ?>

-

diff --git a/public/index.php b/public/index.php index 8e689eb9b..cf8059bb9 100644 --- a/public/index.php +++ b/public/index.php @@ -1,5 +1,9 @@ 100){ - showPercentDone = 0; - $('#on-air-info').attr("class", "on-air-info off"); - } else { - $('#on-air-info').attr("class", "on-air-info on"); - } - $('#progress-show').attr("style", "width:"+showPercentDone+"%"); - } + if (showStartPosixTime != 0){ + var showPercentDone = (estimatedSchedulePosixTime - showStartPosixTime)/showLengthMs*100; + if (showPercentDone < 0 || showPercentDone > 100){ + showPercentDone = 0; + $('#on-air-info').attr("class", "on-air-info off"); + } else { + $('#on-air-info').attr("class", "on-air-info on"); + } + $('#progress-show').attr("style", "width:"+showPercentDone+"%"); + } - var songPercentDone = 0; - if (currentSong.length > 0){ - songPercentDone = (estimatedSchedulePosixTime - currentSong[0].songStartPosixTime)/currentSong[0].songLengthMs*100; - if (songPercentDone < 0 || songPercentDone > 100){ - songPercentDone = 0; - currentSong = new Array(); - } - } - $('#progress-bar').attr("style", "width:"+songPercentDone+"%"); + var songPercentDone = 0; + if (currentSong.length > 0){ + songPercentDone = (estimatedSchedulePosixTime - currentSong[0].songStartPosixTime)/currentSong[0].songLengthMs*100; + if (songPercentDone < 0 || songPercentDone > 100){ + songPercentDone = 0; + currentSong = new Array(); + } + } + $('#progress-bar').attr("style", "width:"+songPercentDone+"%"); - //calculate how much time left to next song if there is any - if (nextSongs.length > 0 && nextSongPrepare){ - if (nextSongs[0].songStartPosixTime - estimatedSchedulePosixTime < serverUpdateInterval){ - nextSongPrepare = false; - setTimeout(newSongStart, nextSongs[0].songStartPosixTime - estimatedSchedulePosixTime); - } - } + //calculate how much time left to next song if there is any + if (nextSongs.length > 0 && nextSongPrepare){ + if (nextSongs[0].songStartPosixTime - estimatedSchedulePosixTime < serverUpdateInterval){ + nextSongPrepare = false; + setTimeout(newSongStart, nextSongs[0].songStartPosixTime - estimatedSchedulePosixTime); + } + } - updatePlaybar(); - } - setTimeout(secondsTimer, uiUpdateInterval); + updatePlaybar(); } function updatePlaybar(){ @@ -149,9 +141,8 @@ function updatePlaybar(){ /* Column 1 update */ $('#playlist').text("Current Show:"); - for (var i=0; i currentItem[i].end_time){ - //start_time is greater than end_time, so we rolled through midnight. - currentItem[i].showEndPosixTime += (1000*3600*24); //add 24 hours - } - currentItem[i].showLengthMs = currentItem[i].showEndPosixTime - currentItem[i].showStartPosixTime; - - if (bUpdateGlobalValues){ - updateGlobalValues(currentItem[i]); - } } } +function updateGlobalValues(obj){ + if (obj.showStartEndTime.length > 0){ + showStartPosixTime = convertDateToPosixTime(obj.showStartEndTime[0].start_timestamp); + showEndPosixTime = convertDateToPosixTime(obj.showStartEndTime[0].end_timestamp); + showLengthMs = showEndPosixTime - showStartPosixTime; + currentShowName = obj.showStartEndTime[0].name; + } +} + function parseItems(obj){ var schedulePosixTime = convertDateToPosixTime(obj.schedulerTime); schedulePosixTime += parseInt(obj.timezoneOffset)*1000; @@ -193,18 +180,29 @@ function parseItems(obj){ previousSongs = obj.previous; currentSong = obj.current; nextSongs = obj.next; + + updateGlobalValues(obj); - calcAdditionalData(previousSongs, false); - calcAdditionalData(currentSong, true); - calcAdditionalData(nextSongs, false); + calcAdditionalData(previousSongs); + calcAdditionalData(currentSong); + calcAdditionalData(nextSongs); - if (estimatedSchedulePosixTime == -1){ + if (localRemoteTimeOffset == null){ var date = new Date(); localRemoteTimeOffset = date.getTime() - schedulePosixTime; - estimatedSchedulePosixTime = schedulePosixTime; } } + +function getScheduleFromServerDebug(){ + $.ajax({ url: "/Schedule/get-current-playlist/format/json", dataType:"text", success:function(data){ + alert(data); + }}); + setTimeout(getScheduleFromServer, serverUpdateInterval); +} + + + function getScheduleFromServer(){ $.ajax({ url: "/Schedule/get-current-playlist/format/json", dataType:"json", success:function(data){ parseItems(data.entries); @@ -212,12 +210,14 @@ function getScheduleFromServer(){ setTimeout(getScheduleFromServer, serverUpdateInterval); } + function init() { //begin producer "thread" getScheduleFromServer(); - + //getScheduleFromServerDebug(); + //begin consumer "thread" - updateProgressBarValue(); + secondsTimer(); } function popup(mylink){ @@ -233,6 +233,5 @@ function popup(mylink){ } $(document).ready(function() { - //initialize the playlist bar in the included playlist.js init(); });