Merge branch 'master' of dev.sourcefabric.org:campcaster

This commit is contained in:
naomiaro 2011-03-22 18:20:39 -04:00
commit 6c5a51e0fa
4 changed files with 146 additions and 83 deletions

View File

@ -109,6 +109,16 @@ class ApiController extends Zend_Controller_Action
$this->_helper->viewRenderer->setNoRender(true); $this->_helper->viewRenderer->setNoRender(true);
$result = Schedule::GetPlayOrderRange(0, 1); $result = Schedule::GetPlayOrderRange(0, 1);
$date = new Application_Model_DateHelper;
$timeNow = $date->getDate();
$result = array("env"=>APPLICATION_ENV,
"schedulerTime"=>gmdate("Y-m-d H:i:s"),
"currentShow"=>Show_DAL::GetCurrentShow($timeNow),
"nextShow"=>Show_DAL::GetNextShows($timeNow, 5),
"timezone"=> date("T"),
"timezoneOffset"=> date("Z"));
//echo json_encode($result); //echo json_encode($result);
header("Content-type: text/javascript"); header("Content-type: text/javascript");
echo $_GET['callback'].'('.json_encode($result).')'; echo $_GET['callback'].'('.json_encode($result).')';

View File

@ -435,7 +435,7 @@ class Schedule {
"current"=>Schedule::GetScheduledItemData($timeNow, 0), "current"=>Schedule::GetScheduledItemData($timeNow, 0),
"next"=>Schedule::GetScheduledItemData($timeNow, 1, $next, "48 hours"), "next"=>Schedule::GetScheduledItemData($timeNow, 1, $next, "48 hours"),
"currentShow"=>Show_DAL::GetCurrentShow($timeNow), "currentShow"=>Show_DAL::GetCurrentShow($timeNow),
"nextShow"=>Show_DAL::GetNextShow($timeNow), "nextShow"=>Show_DAL::GetNextShows($timeNow, 1),
"timezone"=> date("T"), "timezone"=> date("T"),
"timezoneOffset"=> date("Z"), "timezoneOffset"=> date("Z"),
"apiKey"=>$CC_CONFIG['apiKey'][0]); "apiKey"=>$CC_CONFIG['apiKey'][0]);

View File

@ -889,7 +889,7 @@ class Show_DAL {
return $rows; return $rows;
} }
public static function GetNextShow($timeNow) public static function GetNextShows($timeNow, $limit)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
@ -899,7 +899,7 @@ class Show_DAL {
." AND si.starts >= TIMESTAMP '$timeNow'" ." AND si.starts >= TIMESTAMP '$timeNow'"
." AND si.starts < TIMESTAMP '$timeNow' + INTERVAL '48 hours'" ." AND si.starts < TIMESTAMP '$timeNow' + INTERVAL '48 hours'"
." ORDER BY si.starts" ." ORDER BY si.starts"
." LIMIT 1"; ." LIMIT $limit";
$rows = $CC_DBC->GetAll($sql); $rows = $CC_DBC->GetAll($sql);
return $rows; return $rows;

View File

@ -2,25 +2,64 @@
$.fn.airtimeShowSchedule = function(options) { $.fn.airtimeShowSchedule = function(options) {
var defaults = { var defaults = {
updatePeriod: 5, //seconds updatePeriod: 20, //seconds
sourceDomain: "http://localhost/", //where to get show status from
}; };
var options = $.extend(defaults, options); var options = $.extend(defaults, options);
return this.each(function() { return this.each(function() {
var obj = $(this); var obj = $(this);
var sd;
obj.append("<h3>On air today</h3>"); getServerData();
obj.append(
"<table width='100%' border='0' cellspacing='0' cellpadding='0' class='widget widget no-playing-list small'>"+ function updateWidget(){
"<tbody><tr>" + var currentShow = sd.getCurrentShow();
"<td class='time'>13:15 - 13:30</td>" + var nextShows = sd.getNextShows();
"<td><a href='#'>Program name</a> <a href='#' class='listen'>Listen</a></td>" +
"</tr>"+ var currentShowName = "";
"<tr>"+ var nextShowName = ""
"<td class='time'>13:15 - 13:30</td>"+
"<td><a href='#'>Lorem ipsum dolor</a></td>"+ if (currentShow.length > 0){
"</tr>"+ currentShowName = currentShow[0].getName();
"</tbody></table>"); }
if (nextShows.length > 0){
nextShowName = nextShows[0].getName();
}
tableString = "";
tableString += "<h3>On air today</h3>";
tableString += "<table width='100%' border='0' cellspacing='0' cellpadding='0' class='widget widget no-playing-list small'>"+
"<tbody>";
var shows=currentShow.concat(nextShows);
obj.empty();
for (var i=0; i<shows.length; i++){
tableString +=
"<tr>" +
"<td class='time'>"+shows[i].getRange()+"</td>" +
"<td><a href='#'>"+shows[i].getName()+"</a> <a href='#' class='listen'>Listen</a></td>" +
"</tr>";
}
tableString += "</tbody></table>";
obj.append(tableString);
}
function processData(data){
sd = new ScheduleData(data);
updateWidget();
}
function getServerData(){
$.ajax({ url: options.sourceDomain + "api/live-info/", dataType:"jsonp", success:function(data){
processData(data);
}, error:function(jqXHR, textStatus, errorThrown){}});
setTimeout(getServerData, defaults.updatePeriod*1000);
}
}); });
}; };
})(jQuery); })(jQuery);
@ -42,24 +81,42 @@
getServerData(); getServerData();
function updateWidget(){ function updateWidget(){
var currentShow = sd.getCurrentShowName(); var currentShow = sd.getCurrentShow();
var timeRemaining = sd.getCurrentShowTimeRemaining(); var nextShows = sd.getNextShows();
var timeElapsed = sd.getCurrentShowTimeElapsed();
var showStatus = sd.getCurrentShowStatus();
var nextShow = sd.getNextShowName(); var showStatus = "Offline";
var nextShowRange = sd.getNextShowRange(); var currentShowName = "";
var timeElapsed = "";
var timeRemaining = "";
var nextShowName = "";
var nextShowRange = "";
if (currentShow.length > 0){
showStatus = "On Air Now";
currentShowName = currentShow[0].getName();
timeElapsed = sd.getShowTimeElapsed(currentShow[0]);
timeRemaining = sd.getShowTimeRemaining(currentShow[0]);
}
if (nextShows.length > 0){
nextShowName = nextShows[0].getName();
nextShowRange = nextShows[0].getRange();
}
obj.empty(); obj.empty();
obj.append("<a id='listenWadrLive'><span>Listen WADR Live</span></a>"); obj.append("<a id='listenWadrLive'><span>Listen WADR Live</span></a>");
obj.append("<h4>"+showStatus+" &gt;&gt;</h4>"); obj.append("<h4>"+showStatus+" &gt;&gt;</h4>");
obj.append("<ul class='widget no-playing-bar'>" + obj.append("<ul class='widget no-playing-bar'>" +
"<li class='current'>"+currentShow+ "<span id='time-elapsed' class='time-elapsed'>"+timeElapsed+"</span>" + "<li class='current'>Current: "+currentShowName+
"<span id='time-remaining' class='time-remaining'>"+timeRemaining+"</span></li>" + "<span id='time-elapsed' class='time-elapsed'>"+timeElapsed+"</span>" +
"<li class='next'>"+nextShow+"<span>"+nextShowRange+"</span></li>" + "<span id='time-remaining' class='time-remaining'>"+timeRemaining+"</span>"+
"</li>" +
"<li class='next'>Next: "+nextShowName+"<span>"+nextShowRange+"</span></li>" +
"</ul>"); "</ul>");
//refresh the UI //refresh the UI to update the elapsed/remaining time
setTimeout(updateWidget, 1000); setTimeout(updateWidget, 1000);
} }
@ -78,12 +135,23 @@
}; };
})(jQuery); })(jQuery);
/* The rest of this file is the ScheduleData class */ /* ScheduleData class BEGIN */
function ScheduleData(data){ function ScheduleData(data){
this.data = data; this.data = data;
this.estimatedSchedulePosixTime; this.estimatedSchedulePosixTime;
this.schedulePosixTime = this.convertDateToPosixTime(data.schedulerTime); this.currentShow = new Array();
for (var i=0; i< data.currentShow.length; i++){
this.currentShow[i] = new Show(data.currentShow[i]);
}
this.nextShows = new Array();
for (var i=0; i< data.nextShow.length; i++){
this.nextShows[i] = new Show(data.nextShow[i]);
}
this.schedulePosixTime = convertDateToPosixTime(data.schedulerTime);
this.schedulePosixTime += parseInt(data.timezoneOffset)*1000; this.schedulePosixTime += parseInt(data.timezoneOffset)*1000;
var date = new Date(); var date = new Date();
this.localRemoteTimeOffset = date.getTime() - this.schedulePosixTime; this.localRemoteTimeOffset = date.getTime() - this.schedulePosixTime;
@ -95,72 +163,57 @@ ScheduleData.prototype.secondsTimer = function(){
this.estimatedSchedulePosixTime = date.getTime() - this.localRemoteTimeOffset; this.estimatedSchedulePosixTime = date.getTime() - this.localRemoteTimeOffset;
} }
ScheduleData.prototype.getCurrentShowName = function() { ScheduleData.prototype.getCurrentShow = function(){
var currentShow = this.data.currentShow; return this.currentShow;
if (currentShow.length > 0){ }
return "Current: " + currentShow[0].name;
} else {
return "";
}
};
ScheduleData.prototype.getCurrentShowStatus = function() { ScheduleData.prototype.getNextShows = function() {
var currentShow = this.data.currentShow; return this.nextShows;
if (currentShow.length > 0){ }
return "On Air Now";
} else {
return "Offline";
}
};
ScheduleData.prototype.getNextShowName = function() { ScheduleData.prototype.getShowTimeElapsed = function(show) {
var nextShow = this.data.nextShow;
if (nextShow.length > 0){
return "Next: " + nextShow[0].name;
} else {
return "";
}
};
ScheduleData.prototype.getNextShowRange = function() {
var nextShow = this.data.nextShow;
if (nextShow.length > 0){
return this.getTime(nextShow[0].start_timestamp) + " - " + this.getTime(nextShow[0].end_timestamp);
} else {
return "";
}
};
ScheduleData.prototype.getCurrentShowTimeElapsed = function() {
this.secondsTimer(); this.secondsTimer();
var currentShow = this.data.currentShow;
if (currentShow.length > 0){ var showStart = convertDateToPosixTime(show.getStartTimestamp());
var showStart = this.convertDateToPosixTime(currentShow[0].start_timestamp); return convertToHHMMSS(this.estimatedSchedulePosixTime - showStart);
return this.convertToHHMMSS(this.estimatedSchedulePosixTime - showStart);
} else {
return "";
}
}; };
ScheduleData.prototype.getCurrentShowTimeRemaining = function() { ScheduleData.prototype.getShowTimeRemaining = function(show) {
this.secondsTimer(); this.secondsTimer();
var currentShow = this.data.currentShow;
if (currentShow.length > 0){
var showEnd = this.convertDateToPosixTime(currentShow[0].end_timestamp);
return this.convertToHHMMSS(showEnd - this.estimatedSchedulePosixTime);
} else {
return "";
}
};
ScheduleData.prototype.getTime = function(timestamp) { var showEnd = convertDateToPosixTime(show.getEndTimestamp());
return timestamp.split(" ")[1]; return convertToHHMMSS(showEnd - this.estimatedSchedulePosixTime);
}; };
/* ScheduleData class END */
/* Show class BEGIN */
function Show(showData){
this.showData = showData;
}
Show.prototype.getName = function(){
return this.showData.name;
}
Show.prototype.getRange = function(){
return getTime(this.showData.start_timestamp) + " - " + getTime(this.showData.end_timestamp);
}
Show.prototype.getStartTimestamp = function(){
return this.showData.start_timestamp;
}
Show.prototype.getEndTimestamp = function(){
return this.showData.end_timestamp;
}
/* Show class END */
function getTime(timestamp) {
var time = timestamp.split(" ")[1].split(":");
return time[0] + ":" + time[1];
};
/* Takes an input parameter of milliseconds and converts these into /* Takes an input parameter of milliseconds and converts these into
* the format HH:MM:SS */ * the format HH:MM:SS */
ScheduleData.prototype.convertToHHMMSS = function(timeInMS){ function convertToHHMMSS(timeInMS){
var time = parseInt(timeInMS); var time = parseInt(timeInMS);
var hours = parseInt(time / 3600000); var hours = parseInt(time / 3600000);
@ -189,7 +242,7 @@ ScheduleData.prototype.convertToHHMMSS = function(timeInMS){
/* Takes in a string of format similar to 2011-02-07 02:59:57, /* Takes in a string of format similar to 2011-02-07 02:59:57,
* and converts this to epoch/posix time. */ * and converts this to epoch/posix time. */
ScheduleData.prototype.convertDateToPosixTime = function(s){ function convertDateToPosixTime(s){
var datetime = s.split(" "); var datetime = s.split(" ");
var date = datetime[0].split("-"); var date = datetime[0].split("-");