cc-2167-top-panel-doesn't-list-recording-shows

This commit is contained in:
martin 2011-05-10 19:06:35 -04:00
parent b9c1f7356f
commit bc640d38f2
9 changed files with 302 additions and 139 deletions

View file

@ -71,8 +71,8 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
$view->headScript()->appendFile($baseUrl.'/js/qtip/jquery.qtip-1.0.0.min.js','text/javascript');
//scripts for now playing bar
$view->headScript()->appendFile($baseUrl.'/js/playlist/helperfunctions.js','text/javascript');
$view->headScript()->appendFile($baseUrl.'/js/playlist/playlist.js','text/javascript');
$view->headScript()->appendFile($baseUrl.'/js/airtime/dashboard/helperfunctions.js','text/javascript');
$view->headScript()->appendFile($baseUrl.'/js/airtime/dashboard/playlist.js','text/javascript');
$view->headScript()->appendFile($baseUrl.'/js/airtime/common/common.js','text/javascript');
}

View file

@ -113,8 +113,6 @@ class ApiController extends Zend_Controller_Action
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$result = Schedule::GetPlayOrderRange(0, 1);
$date = new DateHelper;
$timeNow = $date->getTimestamp();
$result = array("env"=>APPLICATION_ENV,

View file

@ -0,0 +1,22 @@
<?php
class DashboardController extends Zend_Controller_Action
{
public function init()
{
}
public function indexAction()
{
// action body
}
public function helpAction()
{
// action body
}
}

View file

@ -0,0 +1,115 @@
<?php
class Application_Model_Dashboard
{
public static function GetPreviousItem($p_timeNow){
//get previous show and previous item in the schedule table.
//Compare the two and if the last show was recorded and started
//after the last item in the schedule table, then return the show's
//name. Else return the last item from the schedule.
$showInstance = ShowInstance::GetLastShowInstance($p_timeNow);
$row = Schedule::GetLastScheduleItem($p_timeNow);
if (is_null($showInstance)){
if (count($row) == 0){
return null;
} else {
//should never reach here. Doesnt make sense to have
//a schedule item not within a show_instance.
}
} else {
if (count($row) == 0){
//last item is a show instance
return array("name"=>$showInstance->getName(),
"starts"=>$showInstance->getShowStart(),
"ends"=>$showInstance->getShowEnd());
} else {
//return the one that started later.
if ($row[0]["starts"] >= $showInstance->getShowStart()){
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
"starts"=>$row[0]["starts"],
"ends"=>$row[0]["ends"]);
} else {
return array("name"=>$showInstance->getName(),
"starts"=>$showInstance->getShowStart(),
"ends"=>$showInstance->getShowEnd());
}
}
}
}
public static function GetCurrentItem($p_timeNow){
//get previous show and previous item in the schedule table.
//Compare the two and if the last show was recorded and started
//after the last item in the schedule table, then return the show's
//name. Else return the last item from the schedule.
$showInstance = ShowInstance::GetCurrentShowInstance($p_timeNow);
$row = Schedule::GetCurrentScheduleItem($p_timeNow);
if (is_null($showInstance)){
if (count($row) == 0){
return null;
} else {
//should never reach here. Doesnt make sense to have
//a schedule item not within a show_instance.
}
} else {
if (count($row) == 0){
//last item is a show instance
return array("name"=>$showInstance->getName(),
"starts"=>$showInstance->getShowStart(),
"ends"=>$showInstance->getShowEnd(),
"media_item_played"=>false, //TODO
"record"=>$showInstance->isRecorded()); //TODO
} else {
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
"starts"=>$row[0]["starts"],
"ends"=>$row[0]["ends"],
"media_item_played"=>$row[0]["media_item_played"],
"record"=>0);
}
}
}
public static function GetNextItem($p_timeNow){
//get previous show and previous item in the schedule table.
//Compare the two and if the last show was recorded and started
//after the last item in the schedule table, then return the show's
//name. Else return the last item from the schedule.
$showInstance = ShowInstance::GetNextShowInstance($p_timeNow);
$row = Schedule::GetNextScheduleItem($p_timeNow);
if (is_null($showInstance)){
if (count($row) == 0){
return null;
} else {
//should never reach here. Doesnt make sense to have
//a schedule item not within a show_instance.
}
} else {
if (count($row) == 0){
//last item is a show instance
return array("name"=>$showInstance->getName(),
"starts"=>$showInstance->getShowStart(),
"ends"=>$showInstance->getShowEnd());
} else {
//return the one that starts sooner.
if ($row[0]["starts"] <= $showInstance->getShowStart()){
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
"starts"=>$row[0]["starts"],
"ends"=>$row[0]["ends"]);
} else {
return array("name"=>$showInstance->getName(),
"starts"=>$showInstance->getShowStart(),
"ends"=>$showInstance->getShowEnd());
}
}
}
}
}

View file

@ -365,9 +365,12 @@ class Schedule {
$timeNow = $date->getTimestamp();
return array("env"=>APPLICATION_ENV,
"schedulerTime"=>gmdate("Y-m-d H:i:s"),
"previous"=>Schedule::GetScheduledItemData($timeNow, -1, $prev, "24 hours"),
"current"=>Schedule::GetScheduledItemData($timeNow, 0),
"next"=>Schedule::GetScheduledItemData($timeNow, 1, $next, "48 hours"),
//"previous"=>Schedule::GetScheduledItemData($timeNow, -1, $prev, "24 hours"),
//"current"=>Schedule::GetScheduledItemData($timeNow, 0),
//"next"=>Schedule::GetScheduledItemData($timeNow, 1, $next, "48 hours"),
"previous"=>Application_Model_Dashboard::GetPreviousItem($timeNow),
"current"=>Application_Model_Dashboard::GetCurrentItem($timeNow),
"next"=>Application_Model_Dashboard::GetNextItem($timeNow),
"currentShow"=>Show_DAL::GetCurrentShow($timeNow),
"nextShow"=>Show_DAL::GetNextShows($timeNow, 1),
"timezone"=> date("T"),
@ -375,6 +378,52 @@ class Schedule {
"apiKey"=>$CC_CONFIG['apiKey'][0]);
}
public static function GetLastScheduleItem($p_timeNow){
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT *"
." FROM $CC_CONFIG[scheduleTable] st"
." LEFT JOIN $CC_CONFIG[filesTable] ft"
." ON st.file_id = ft.id"
." WHERE st.ends < TIMESTAMP '$p_timeNow'"
." ORDER BY st.ends DESC"
." LIMIT 1";
$row = $CC_DBC->GetAll($sql);
return $row;
}
public static function GetCurrentScheduleItem($p_timeNow){
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT *"
." FROM $CC_CONFIG[scheduleTable] st"
." LEFT JOIN $CC_CONFIG[filesTable] ft"
." ON st.file_id = ft.id"
." WHERE st.starts <= TIMESTAMP '$p_timeNow'"
." AND st.ends > TIMESTAMP '$p_timeNow'"
." LIMIT 1";
$row = $CC_DBC->GetAll($sql);
return $row;
}
public static function GetNextScheduleItem($p_timeNow){
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT *"
." FROM $CC_CONFIG[scheduleTable] st"
." LEFT JOIN $CC_CONFIG[filesTable] ft"
." ON st.file_id = ft.id"
." WHERE st.starts > TIMESTAMP '$p_timeNow'"
." ORDER BY st.starts"
." LIMIT 1";
$row = $CC_DBC->GetAll($sql);
return $row;
}
/**
* Builds an SQL Query for accessing scheduled item information from
* the database.

View file

@ -1718,6 +1718,57 @@ class ShowInstance {
return ($diff < 0) ? 0 : $diff;
}
public static function GetLastShowInstance($p_timeNow){
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT si.id"
." FROM $CC_CONFIG[showInstances] si"
." WHERE si.ends < TIMESTAMP '$p_timeNow'"
." ORDER BY si.ends DESC"
." LIMIT 1";
$id = $CC_DBC->GetOne($sql);
if (is_null($id)){
return null;
} else {
return new ShowInstance($id);
}
}
public static function GetCurrentShowInstance($p_timeNow){
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT si.id"
." FROM $CC_CONFIG[showInstances] si"
." WHERE si.starts <= TIMESTAMP '$p_timeNow'"
." AND si.ends > TIMESTAMP '$p_timeNow'"
." LIMIT 1";
$id = $CC_DBC->GetOne($sql);
if (is_null($id)){
return null;
} else {
return new ShowInstance($id);
}
}
public static function GetNextShowInstance($p_timeNow){
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT si.id"
." FROM $CC_CONFIG[showInstances] si"
." WHERE si.starts > TIMESTAMP '$p_timeNow'"
." ORDER BY si.starts"
." LIMIT 1";
$id = $CC_DBC->GetOne($sql);
if (is_null($id)){
return null;
} else {
return new ShowInstance($id);
}
}
}
/* Show Data Access Layer */

View file

@ -1,9 +1,9 @@
var estimatedSchedulePosixTime = null;
var localRemoteTimeOffset = null;
var previousSongs = new Array();
var currentSong = new Array();
var nextSongs = new Array();
var previousSong = null;
var currentSong = null;
var nextSong = null;
var currentShow = new Array();
var nextShow = new Array();
@ -25,21 +25,8 @@ var nextShowPrepare = true;
var apiKey = "";
function getTrackInfo(song){
var str = "";
if (song.track_title != null)
str += song.track_title;
if (song.artist_name != null)
str += " - " + song.artist_name;
str += ","
return str;
}
function secondsTimer(){
if (localRemoteTimeOffset != null){
if (localRemoteTimeOffset !== null){
var date = new Date();
estimatedSchedulePosixTime = date.getTime() - localRemoteTimeOffset;
updateProgressBarValue();
@ -50,7 +37,8 @@ function secondsTimer(){
function newSongStart(){
nextSongPrepare = true;
currentSong[0] = nextSongs.shift();
currentSong = nextSong;
nextSong = null;
if (typeof notifySongStart == "function")
notifySongStart();
@ -80,13 +68,13 @@ function updateProgressBarValue(){
$('#progress-show').attr("style", "width:"+showPercentDone+"%");
var songPercentDone = 0;
if (currentSong.length > 0){
songPercentDone = (estimatedSchedulePosixTime - currentSong[0].songStartPosixTime)/currentSong[0].songLengthMs*100;
if (currentSong !== null){
songPercentDone = (estimatedSchedulePosixTime - currentSong.songStartPosixTime)/currentSong.songLengthMs*100;
if (songPercentDone < 0 || songPercentDone > 100){
songPercentDone = 0;
currentSong = new Array();
currentSong = null;
} else {
if (currentSong[0].media_item_played == "t" && currentShow.length > 0)
if (currentSong.media_item_played == "t" && currentShow.length > 0)
$('#on-air-info').attr("class", "on-air-info on");
else
$('#on-air-info').attr("class", "on-air-info off");
@ -99,8 +87,8 @@ function updateProgressBarValue(){
$('#progress-bar').attr("style", "width:"+songPercentDone+"%");
//calculate how much time left to next song if there is any
if (nextSongs.length > 0 && nextSongPrepare){
var diff = nextSongs[0].songStartPosixTime - estimatedSchedulePosixTime;
if (nextSong !== null && nextSongPrepare){
var diff = nextSong.songStartPosixTime - estimatedSchedulePosixTime;
if (diff < serverUpdateInterval){
//sometimes the diff is negative (-100ms for example). Still looking
@ -133,20 +121,26 @@ function updatePlaybar(){
$('#current').html("Current: <span style='color:red; font-weight:bold'>Nothing Scheduled</span>");
$('#next').empty();
$('#next-length').empty();
if (previousSongs.length > 0){
$('#previous').text(getTrackInfo(previousSongs[previousSongs.length-1]));
$('#prev-length').text(convertToHHMMSSmm(previousSongs[previousSongs.length-1].songLengthMs));
if (previousSong !== null){
$('#previous').text(previousSong.name+",");
$('#prev-length').text(convertToHHMMSSmm(previousSong.songLengthMs));
}
if (currentSong.length > 0){
$('#current').text(getTrackInfo(currentSong[0]));
} else if (currentShow.length > 0){
if (currentSong !== null){
if (currentSong.record == "1")
$('#current').html("<span style='color:red; font-weight:bold'>Recording: </span>"+currentSong.name+",");
else
$('#current').text(currentSong.name+",");
}
/*
else if (currentShow.length > 0){
if (currentShow[0].record == "1"){
$('#current').html("Current: <span style='color:red; font-weight:bold'>Recording</span>");
}
}
if (nextSongs.length > 0){
$('#next').text(getTrackInfo(nextSongs[0]));
$('#next-length').text(convertToHHMMSSmm(nextSongs[0].songLengthMs));
* */
if (nextSong !== null){
$('#next').text(nextSong.name+",");
$('#next-length').text(convertToHHMMSSmm(nextSong.songLengthMs));
}
$('#start').empty();
@ -154,18 +148,18 @@ function updatePlaybar(){
$('#time-elapsed').empty();
$('#time-remaining').empty();
$('#song-length').empty();
for (var i=0; i<currentSong.length; i++){
$('#start').text(currentSong[i].starts.substring(currentSong[i].starts.indexOf(" ")+1));
$('#end').text(currentSong[i].ends.substring(currentSong[i].starts.indexOf(" ")+1));
if (currentSong !== null){
$('#start').text(currentSong.starts.substring(currentSong.starts.indexOf(" ")+1));
$('#end').text(currentSong.ends.substring(currentSong.starts.indexOf(" ")+1));
/* Get rid of the millisecond accuracy so that the second counters for both
* show and song change at the same time. */
var songStartRoughly = parseInt(Math.round(currentSong[i].songStartPosixTime/1000))*1000;
var songEndRoughly = parseInt(Math.round(currentSong[i].songEndPosixTime/1000))*1000;
var songStartRoughly = parseInt(Math.round(currentSong.songStartPosixTime/1000))*1000;
var songEndRoughly = parseInt(Math.round(currentSong.songEndPosixTime/1000))*1000;
$('#time-elapsed').text(convertToHHMMSS(estimatedSchedulePosixTime - songStartRoughly));
$('#time-remaining').text(convertToHHMMSS(songEndRoughly - estimatedSchedulePosixTime));
$('#song-length').text(convertToHHMMSSmm(currentSong[i].songLengthMs));
$('#song-length').text(convertToHHMMSSmm(currentSong.songLengthMs));
}
/* Column 1 update */
$('#playlist').text("Current Show:");
@ -187,11 +181,9 @@ function updatePlaybar(){
}
function calcAdditionalData(currentItem){
for (var i=0; i<currentItem.length; i++){
currentItem[i].songStartPosixTime = convertDateToPosixTime(currentItem[i].starts);
currentItem[i].songEndPosixTime = convertDateToPosixTime(currentItem[i].ends);
currentItem[i].songLengthMs = currentItem[i].songEndPosixTime - currentItem[i].songStartPosixTime;
}
currentItem.songStartPosixTime = convertDateToPosixTime(currentItem.starts);
currentItem.songEndPosixTime = convertDateToPosixTime(currentItem.ends);
currentItem.songLengthMs = currentItem.songEndPosixTime - currentItem.songStartPosixTime;
}
function calcAdditionalShowData(show){
@ -208,17 +200,18 @@ function parseItems(obj){
$('#time-zone').text(obj.timezone);
previousSongs = obj.previous;
nextSongs = obj.next;
previousSong = obj.previous;
currentSong = obj.current;
nextSong = obj.next;
calcAdditionalData(previousSongs);
calcAdditionalData(nextSongs);
if (previousSong !== null)
calcAdditionalData(previousSong);
if (currentSong !== null)
calcAdditionalData(currentSong);
if (nextSong !== null)
calcAdditionalData(nextSong);
currentShow = obj.currentShow;
if(currentShow.length > 0){
currentSong = obj.current;
calcAdditionalData(currentSong);
}
nextShow = obj.nextShow;
calcAdditionalShowData(obj.currentShow);
@ -238,17 +231,10 @@ function getScheduleFromServer(){
setTimeout(getScheduleFromServer, serverUpdateInterval);
}
function init() {
//begin producer "thread"
getScheduleFromServer();
//begin consumer "thread"
secondsTimer();
function setupQtip(){
var qtipElem = $('#about-link');
if (qtipElem.length > 0)
if (qtipElem.length > 0){
qtipElem.qtip({
content: $('#about-txt').html(),
show: 'mouseover',
@ -267,6 +253,17 @@ function init() {
name: 'light' // Use the default light style
}
});
}
}
function init() {
//begin producer "thread"
getScheduleFromServer();
//begin consumer "thread"
secondsTimer();
setupQtip();
}
$(document).ready(function() {

View file

@ -1,69 +0,0 @@
function createDataGrid(datagridData){
var columnHeaders = [
{ "sTitle": "name" },
{ "sTitle": "date" },
{ "sTitle": "start time" },
{ "sTitle": "end time" }
];
$('#demo').html( '<table cellpadding="0" cellspacing="0" border="0" width="100%" id="nowplayingtable"></table>' );
$('#nowplayingtable').dataTable( {
"bSort" : false,
"bJQueryUI": true,
"bFilter": false,
"bInfo": false,
"bLengthChange": false,
"aaData": datagridData.rows,
"aoColumns": columnHeaders
} );
var options1 = [
{title:"Menu Item 1 - Go TO www.google.com", action:{type:"gourl",url:"http://www.google.com/"}},
{title:"Menu Item 2 - do <b style='color:red;'>nothing</b>"},
{title:"Menu Item 3 - submenu", type:"sub", src:[{title:"Submenu 1"},{title:"Submenu 2"},{title:"Submenu 3"}, {title:"Submenu 4 - submenu", type:"sub", src:[{title:"SubSubmenu 1"},{title:"SubSubmenu 2"}]}]},
{title:"Menu Item 4 - Js function", action:{type:"fn",callback:"(function(){ alert('THIS IS THE TEST'); })"}}
];
var userData = {};
var effects = {
show:"default", //type of show effect
orientation: "auto", //type of menu orientation - to top, to bottom, auto (to bottom, if doesn't fit on screen - to top)
xposition:"mouse", // position of menu (left side or right side of trigger element)
yposition:"mouse"
}
$('#demo').jjmenu('both', options1, userData, effects );
}
function initShowListView(){
$.ajax({ url: "/Schedule/get-show-data/format/json", dataType:"text", success:function(data){
$('#json-string').text(data);
}});
$.ajax({ url: "/Schedule/get-show-data/format/json", dataType:"json", success:function(data){
var temp = data.data;
var rows = new Array();
for (var i=0; i<temp.length; i++){
rows[i] = [temp[i].name.toString(), temp[i].first_show.toString(), temp[i].start_time.toString(), temp[i].end_time.toString()];
var datagridData = {rows:rows};
createDataGrid(datagridData);
}
}});
//setTimeout(initShowListView, 5000);
}
$(document).ready(function() {
initShowListView();
});