-fixed bug CC-1837

-show progress-bar will now update even when an audio item is not playing
This commit is contained in:
mkonecny 2011-02-01 20:28:38 -05:00
parent be79b21c37
commit 71023a52b3
5 changed files with 201 additions and 170 deletions

View File

@ -4,10 +4,6 @@ class Application_Model_Nowplaying
{ {
public static function GetDataGridData(){ 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), $columnHeaders = array(array("sTitle"=>"type", "bVisible"=>false),
array("sTitle"=>"Date"), array("sTitle"=>"Date"),
@ -21,30 +17,44 @@ class Application_Model_Nowplaying
array("sTitle"=>"Playlist"), array("sTitle"=>"Playlist"),
array("sTitle"=>"bgcolor", "bVisible"=>false), array("sTitle"=>"bgcolor", "bVisible"=>false),
array("sTitle"=>"group_id", "bVisible"=>false)); array("sTitle"=>"group_id", "bVisible"=>false));
$timeNow = Schedule::GetSchedulerTime();
$currentShow = Schedule::GetCurrentShow($timeNow);
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(); $rows = array();
$current_group_id = -1;
if (count($current) != 0){
$current_group_id = $current[0]["group_id"];
}
foreach ($previous as $item){ 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"], 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"])); $item["album_title"], "x" , $item["name"], $color, $item["group_id"]));
} }
foreach ($current as $item){ foreach ($current as $item){
array_push($rows, array("c", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"], 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){ 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"], 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;
} }
} }

View File

@ -472,24 +472,23 @@ class Schedule {
} }
$timeNow = Schedule::GetSchedulerTime(); $timeNow = Schedule::GetSchedulerTime();
return array("schedulerTime"=>gmdate("Y-m-d H:i:s"),"previous"=>Schedule::GetPreviousItems($timeNow), return array("schedulerTime"=>gmdate("Y-m-d H:i:s"),
"previous"=>Schedule::GetPreviousItems($timeNow),
"current"=>Schedule::GetCurrentlyPlaying($timeNow), "current"=>Schedule::GetCurrentlyPlaying($timeNow),
"next"=>Schedule::GetNextItems($timeNow), "next"=>Schedule::GetNextItems($timeNow),
"showStartEndTime"=>Schedule::GetCurrentShow($timeNow),
"timezone"=> date("T"), "timezone"=> date("T"),
"timezoneOffset"=> date("Z")); "timezoneOffset"=> date("Z"));
} }
public static function GetPreviousItems($timeNow, $prevCount = 1){ public static function GetPreviousItems($timeNow, $prevCount = 1){
global $CC_CONFIG, $CC_DBC; 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" ." FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt"
." WHERE st.ends < TIMESTAMP '$timeNow'" ." WHERE st.ends < TIMESTAMP '$timeNow'"
." AND st.ends > (TIMESTAMP '$timeNow' - INTERVAL '24 hours')" ." AND st.ends > (TIMESTAMP '$timeNow' - INTERVAL '24 hours')"
." AND st.playlist_id = pt.id" ." AND st.playlist_id = pt.id"
." AND st.file_id = ft.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" ." ORDER BY st.starts DESC"
." LIMIT $prevCount"; ." LIMIT $prevCount";
$rows = $CC_DBC->GetAll($sql); $rows = $CC_DBC->GetAll($sql);
@ -499,39 +498,59 @@ class Schedule {
public static function GetCurrentlyPlaying($timeNow){ public static function GetCurrentlyPlaying($timeNow){
global $CC_CONFIG, $CC_DBC; 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," ." 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'" ." WHERE st.starts < TIMESTAMP '$timeNow'"
." AND st.ends > TIMESTAMP '$timeNow'" ." AND st.ends > TIMESTAMP '$timeNow'"
." AND st.playlist_id = pt.id" ." AND st.playlist_id = pt.id"
." AND st.file_id = ft.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";
$rows = $CC_DBC->GetAll($sql); $rows = $CC_DBC->GetAll($sql);
return $rows; return $rows;
} }
public static function GetNextItems($timeNow, $nextCount = 1) { public static function GetNextItems($timeNow, $nextCount = 1) {
global $CC_CONFIG, $CC_DBC; 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" ." FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt"
." WHERE st.starts > TIMESTAMP '$timeNow'" ." WHERE st.starts > TIMESTAMP '$timeNow'"
." AND st.ends < (TIMESTAMP '$timeNow' + INTERVAL '24 hours')" ." AND st.ends < (TIMESTAMP '$timeNow' + INTERVAL '24 hours')"
." AND st.playlist_id = pt.id" ." AND st.playlist_id = pt.id"
." AND st.file_id = ft.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" ." ORDER BY st.starts"
." LIMIT $nextCount"; ." LIMIT $nextCount";
$rows = $CC_DBC->GetAll($sql); $rows = $CC_DBC->GetAll($sql);
return $rows; 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;
} }
/** /**

View File

@ -8,7 +8,6 @@
<body> <body>
<h1>An error occurred</h1> <h1>An error occurred</h1>
<h2><?php echo $this->message ?></h2> <h2><?php echo $this->message ?></h2>
<h2><?php echo "test".APPLICATION_ENV ?></h2>
<?php if ('development' == APPLICATION_ENV): ?> <?php if ('development' == APPLICATION_ENV): ?>

View File

@ -1,5 +1,9 @@
<?php <?php
//error_reporting(E_ALL|E_STRICT);
error_reporting(E_ALL);
ini_set('display_errors', 'on');
// Define path to application directory // Define path to application directory
defined('APPLICATION_PATH') defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

View File

@ -1,6 +1,5 @@
var estimatedSchedulePosixTime = -1; var estimatedSchedulePosixTime = null;
var localRemoteTimeOffset = null;
var localRemoteTimeOffset = -1;
var previousSongs = new Array(); var previousSongs = new Array();
var currentSong = new Array(); var currentSong = new Array();
@ -16,6 +15,7 @@ var songEndFunc;
var showStartPosixTime = 0; var showStartPosixTime = 0;
var showEndPosixTime = 0; var showEndPosixTime = 0;
var showLengthMs = 1; var showLengthMs = 1;
var currentShowName = "";
/* boolean flag to let us know if we should prepare to execute a function /* boolean flag to let us know if we should prepare to execute a function
* that flips the playlist to the next song. This flags purpose is to * that flips the playlist to the next song. This flags purpose is to
@ -50,23 +50,18 @@ function getTrackInfo(song){
} }
function secondsTimer(){ function secondsTimer(){
if (localRemoteTimeOffset != null){
var date = new Date(); var date = new Date();
if (localRemoteTimeOffset != -1)
estimatedSchedulePosixTime = date.getTime() - localRemoteTimeOffset; estimatedSchedulePosixTime = date.getTime() - localRemoteTimeOffset;
updateProgressBarValue(); updateProgressBarValue();
} }
setTimeout(secondsTimer, uiUpdateInterval);
function updateGlobalValues(obj){
showStartPosixTime = obj.showStartPosixTime;
showEndPosixTime = obj.showEndPosixTime;
showLengthMs = showEndPosixTime - showStartPosixTime;
} }
function newSongStart(){ function newSongStart(){
nextSongPrepare = true; nextSongPrepare = true;
currentSong[0] = nextSongs.shift(); currentSong[0] = nextSongs.shift();
updateGlobalValues(currentSong[0]); //updateGlobalValues(currentSong[0]);
updatePlaybar(); updatePlaybar();
notifySongEndListener(); notifySongEndListener();
@ -74,7 +69,6 @@ function newSongStart(){
/* Called every "uiUpdateInterval" mseconds. */ /* Called every "uiUpdateInterval" mseconds. */
function updateProgressBarValue(){ function updateProgressBarValue(){
if (estimatedSchedulePosixTime != -1){
if (showStartPosixTime != 0){ if (showStartPosixTime != 0){
var showPercentDone = (estimatedSchedulePosixTime - showStartPosixTime)/showLengthMs*100; var showPercentDone = (estimatedSchedulePosixTime - showStartPosixTime)/showLengthMs*100;
if (showPercentDone < 0 || showPercentDone > 100){ if (showPercentDone < 0 || showPercentDone > 100){
@ -106,8 +100,6 @@ function updateProgressBarValue(){
updatePlaybar(); updatePlaybar();
} }
setTimeout(secondsTimer, uiUpdateInterval);
}
function updatePlaybar(){ function updatePlaybar(){
/* Column 0 update */ /* Column 0 update */
@ -149,9 +141,8 @@ function updatePlaybar(){
/* Column 1 update */ /* Column 1 update */
$('#playlist').text("Current Show:"); $('#playlist').text("Current Show:");
for (var i=0; i<currentSong.length; i++){ $('#playlist').text(currentShowName);
$('#playlist').text(currentSong[i].name);
}
$('#show-length').empty(); $('#show-length').empty();
if (estimatedSchedulePosixTime < showEndPosixTime){ if (estimatedSchedulePosixTime < showEndPosixTime){
$('#show-length').text(convertDateToHHMMSS(showStartPosixTime) + " - " + convertDateToHHMMSS(showEndPosixTime)); $('#show-length').text(convertDateToHHMMSS(showStartPosixTime) + " - " + convertDateToHHMMSS(showEndPosixTime));
@ -167,21 +158,17 @@ function calcAdditionalData(currentItem, bUpdateGlobalValues){
currentItem[i].songEndPosixTime = convertDateToPosixTime(currentItem[i].ends); currentItem[i].songEndPosixTime = convertDateToPosixTime(currentItem[i].ends);
currentItem[i].songLengthMs = currentItem[i].songEndPosixTime - currentItem[i].songStartPosixTime; currentItem[i].songLengthMs = currentItem[i].songEndPosixTime - currentItem[i].songStartPosixTime;
currentItem[i].showStartPosixTime = convertDateToPosixTime(currentItem[i].starts.substring(0, currentItem[i].starts.indexOf(" ")) + " " + currentItem[i].start_time);
currentItem[i].showEndPosixTime = convertDateToPosixTime(currentItem[i].starts.substring(0, currentItem[i].starts.indexOf(" ")) + " " + currentItem[i].end_time);
//check if there is a rollover past midnight
if (currentItem[i].start_time > 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; 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){ function parseItems(obj){
@ -194,17 +181,28 @@ function parseItems(obj){
currentSong = obj.current; currentSong = obj.current;
nextSongs = obj.next; nextSongs = obj.next;
calcAdditionalData(previousSongs, false); updateGlobalValues(obj);
calcAdditionalData(currentSong, true);
calcAdditionalData(nextSongs, false);
if (estimatedSchedulePosixTime == -1){ calcAdditionalData(previousSongs);
calcAdditionalData(currentSong);
calcAdditionalData(nextSongs);
if (localRemoteTimeOffset == null){
var date = new Date(); var date = new Date();
localRemoteTimeOffset = date.getTime() - schedulePosixTime; 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(){ function getScheduleFromServer(){
$.ajax({ url: "/Schedule/get-current-playlist/format/json", dataType:"json", success:function(data){ $.ajax({ url: "/Schedule/get-current-playlist/format/json", dataType:"json", success:function(data){
parseItems(data.entries); parseItems(data.entries);
@ -212,12 +210,14 @@ function getScheduleFromServer(){
setTimeout(getScheduleFromServer, serverUpdateInterval); setTimeout(getScheduleFromServer, serverUpdateInterval);
} }
function init() { function init() {
//begin producer "thread" //begin producer "thread"
getScheduleFromServer(); getScheduleFromServer();
//getScheduleFromServerDebug();
//begin consumer "thread" //begin consumer "thread"
updateProgressBarValue(); secondsTimer();
} }
function popup(mylink){ function popup(mylink){
@ -233,6 +233,5 @@ function popup(mylink){
} }
$(document).ready(function() { $(document).ready(function() {
//initialize the playlist bar in the included playlist.js
init(); init();
}); });