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

This commit is contained in:
naomiaro 2011-02-05 16:00:11 -05:00
commit 78f83f5f6e
9 changed files with 165 additions and 75 deletions

View File

@ -111,6 +111,7 @@
<modelsDirectory>
<modelFile modelName="Nowplaying"/>
<modelFile modelName="Preference"/>
<modelFile modelName="DateHelper"/>
</modelsDirectory>
<modulesDirectory enabled="false"/>
<viewsDirectory>

View File

@ -60,8 +60,8 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
$view->headScript()->appendFile('/js/libs/jquery.stickyPanel.js','text/javascript');
//scripts for now playing bar
//$this->view->headScript()->appendFile('/js/playlist/helperfunctions.js','text/javascript');
//$this->view->headScript()->appendFile('/js/playlist/playlist.js','text/javascript');
$this->view->headScript()->appendFile('/js/playlist/helperfunctions.js','text/javascript');
$this->view->headScript()->appendFile('/js/playlist/playlist.js','text/javascript');
$view->headScript()->appendFile('/js/airtime/common/common.js','text/javascript');
}

View File

@ -18,8 +18,8 @@ class NowplayingController extends Zend_Controller_Action
public function getDataGridDataAction()
{
//$this->view->entries = json_encode(Application_Model_Nowplaying::GetDataGridData());
$this->view->entries = Application_Model_Nowplaying::GetDataGridData();
$viewType = $this->_request->getParam('view');
$this->view->entries = Application_Model_Nowplaying::GetDataGridData($viewType);
}
public function livestreamAction()

View File

@ -0,0 +1,47 @@
<?php
class Application_Model_DateHelper
{
private $_timestamp;
function __construct() {
$this->_timestamp = date("U");
}
function getDate(){
return date("Y-m-d H:i:s", $this->_timestamp);
}
function getNowDayStartDiff(){
$dayStartTS = strtotime(date("Y-m-d", $this->_timestamp));
return $this->_timestamp - $dayStartTS;
}
function getNowDayEndDiff(){
$dayEndTS = strtotime(date("Y-m-d", $this->_timestamp+(86400)));
return $dayEndTS - $this->_timestamp;
}
public static function ConvertMSToHHMMSSmm($time){
$hours = floor($time / 3600000);
$time -= 3600000*$hours;
$minutes = floor($time / 60000);
$time -= 60000*$minutes;
$seconds = floor($time / 1000);
$time -= 1000*$seconds;
$ms = $time;
if (strlen($hours) == 1)
$hours = "0".$hours;
if (strlen($minutes) == 1)
$minutes = "0".$minutes;
if (strlen($seconds) == 1)
$seconds = "0".$seconds;
return $hours.":".$minutes.":".$seconds.".".$ms;
}
}

View File

@ -15,7 +15,7 @@ class Application_Model_Nowplaying
if (count($endDate) > 1)
$epochEndMS += $endDate[1];
$blankRow = array(array("b", "-", "-", "-", TimeDateHelper::ConvertMSToHHMMSSmm($epochEndMS - $epochStartMS), "-", "-", "-", "-" , "-", "", ""));
$blankRow = array(array("b", "-", "-", "-", Application_Model_DateHelper::ConvertMSToHHMMSSmm($epochEndMS - $epochStartMS), "-", "-", "-", "-" , "-", "", ""));
array_splice($rows, $i, 0, $blankRow);
return $rows;
}
@ -42,7 +42,7 @@ class Application_Model_Nowplaying
return $rows;
}
public static function GetDataGridData(){
public static function GetDataGridData($viewType){
$columnHeaders = array(array("sTitle"=>"type", "bVisible"=>false),
array("sTitle"=>"Date"),
@ -52,44 +52,52 @@ class Application_Model_Nowplaying
array("sTitle"=>"Song"),
array("sTitle"=>"Artist"),
array("sTitle"=>"Album"),
array("sTitle"=>"Creator"),
array("sTitle"=>"Playlist"),
array("sTitle"=>"Show"),
array("sTitle"=>"bgcolor", "bVisible"=>false),
array("sTitle"=>"group_id", "bVisible"=>false));
$timeNow = Schedule::GetSchedulerTime();
$date = Schedule::GetSchedulerTime();
$timeNow = $date->getDate();
$currentShow = Schedule::GetCurrentShow($timeNow);
$groupIDs = array();
if (count($currentShow) > 0){
$dbRows = Schedule::GetCurrentShowGroupIDs($currentShow[0]["id"]);
$groupIDs = array();
$dbRows = Show_DAL::GetShowGroupIDs($currentShow[0]["id"]);
foreach ($dbRows as $row){
array_push($groupIDs, $row["group_id"]);
}
}
$previous = Schedule::Get_Scheduled_Item_Data($timeNow, -1, 1, "60 seconds");
$current = Schedule::Get_Scheduled_Item_Data($timeNow, 0);
$next = Schedule::Get_Scheduled_Item_Data($timeNow, 1, 10, "48 hours");
if ($viewType == "now"){
$previous = Schedule::Get_Scheduled_Item_Data($timeNow, -1, 1, "60 seconds");
$current = Schedule::Get_Scheduled_Item_Data($timeNow, 0);
$next = Schedule::Get_Scheduled_Item_Data($timeNow, 1, 10, "24 hours");
} else {
$previous = Schedule::Get_Scheduled_Item_Data($timeNow, -1, "ALL", $date->getNowDayStartDiff()." seconds");
$current = Schedule::Get_Scheduled_Item_Data($timeNow, 0);
$next = Schedule::Get_Scheduled_Item_Data($timeNow, 1, "ALL", $date->getNowDayEndDiff()." seconds");
}
$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"]));
$item["album_title"], $item["name"], $item["show_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["group_id"]));
$item["album_title"], $item["name"], $item["show_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"], $color, $item["group_id"]));
$item["album_title"], $item["name"], $item["show_name"], $color, $item["group_id"]));
}
$rows = Application_Model_Nowplaying::FindGaps($rows);
@ -99,30 +107,3 @@ class Application_Model_Nowplaying
}
}
class TimeDateHelper
{
public static function ConvertMSToHHMMSSmm($time){
$hours = floor($time / 3600000);
$time -= 3600000*$hours;
$minutes = floor($time / 60000);
$time -= 60000*$minutes;
$seconds = floor($time / 1000);
$time -= 1000*$seconds;
$ms = $time;
if (strlen($hours) == 1)
$hours = "0".$hours;
if (strlen($minutes) == 1)
$minutes = "0".$minutes;
if (strlen($seconds) == 1)
$seconds = "0".$seconds;
return $hours.":".$minutes.":".$seconds.".".$ms;
}
}

View File

@ -446,7 +446,8 @@ class Schedule {
* @return date Current server time.
*/
public static function GetSchedulerTime() {
return date("Y-m-d H:i:s");
$date = new Application_Model_DateHelper;
return $date;
}
/**
@ -462,7 +463,8 @@ class Schedule {
return "{}";
}
$timeNow = Schedule::GetSchedulerTime();
$date = Schedule::GetSchedulerTime();
$timeNow = $date->getDate();
return array("schedulerTime"=>gmdate("Y-m-d H:i:s"),
"previous"=>Schedule::Get_Scheduled_Item_Data($timeNow, -1, $prev, "24 hours"),
"current"=>Schedule::Get_Scheduled_Item_Data($timeNow, 0),
@ -497,15 +499,17 @@ class Schedule {
*/
public static function Get_Scheduled_Item_Data($timeNow, $timePeriod=0, $count = 0, $interval="0 hours"){
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"
." FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt"
$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"
." FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt, $CC_CONFIG[showSchedule] ss, $CC_CONFIG[showTable] show"
." WHERE st.playlist_id = pt.id"
." AND st.file_id = ft.id";
." AND st.file_id = ft.id"
." AND st.group_id = ss.group_id"
." AND ss.show_id = show.id";
if ($timePeriod < 0){
$sql .= " AND st.ends < TIMESTAMP '$timeNow'"
." AND st.ends > (TIMESTAMP '$timeNow' - INTERVAL '$interval')"
." ORDER BY st.starts DESC"
." ORDER BY st.starts"
." LIMIT $count";
} else if ($timePeriod == 0){
$sql .= " AND st.starts < TIMESTAMP '$timeNow'"
@ -516,13 +520,12 @@ class Schedule {
." ORDER BY st.starts"
." LIMIT $count";
}
$rows = $CC_DBC->GetAll($sql);
return $rows;
}
/*
public static function GetPreviousItems($timeNow, $prevCount = 1, $prevInterval="24 hours"){
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"
@ -602,18 +605,6 @@ class Schedule {
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"

View File

@ -652,3 +652,38 @@ class Show {
return StoredFile::searchPlaylistsForSchedule($length, $datatables);
}
}
/* Show Data Access Layer */
class Show_DAL{
/* Given a group_id, get all show data related to
* id. This is useful in the case where you have an item
* in the schedule table and you want to find out more about
* the show it is in without joining the schedule and show tables
* (which causes problems with duplicate items)
*/
public static function GetShowData($group_id){
global $CC_DBC;
$sql="SELECT * FROM cc_show_schedule as ss, cc_show as s"
." WHERE ss.show_id = s.id"
." AND ss.group_id = $group_id"
." LIMIT 1";
return $CC_DBC->GetOne($sql);
}
/* Given a show ID, this function returns what group IDs
* are present in this show. */
public static function GetShowGroupIDs($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

@ -1 +1,2 @@
<div style="text-align:right;"><a href="javascript:void(0);" onclick="setViewType(0)">Now View</a> | <a href="javascript:void(0);" onclick="setViewType(1)">Day View</a></div>
<div id='demo'></div>

View File

@ -45,12 +45,35 @@ function notifySongEnd(){
createDataGrid();
}
/*
function updateDataGrid(){
var table = $('#nowplayingtable');
//table.dataTable().fnClearTable();
for (var i=0; i<datagridData.rows.length; i++){
table.dataTable().fnAddData(datagridData.rows[i]);
}
}
*/
var columns = [{"sTitle": "type", "bVisible":false},
{"sTitle":"Date"},
{"sTitle":"Start"},
{"sTitle":"End"},
{"sTitle":"Duration"},
{"sTitle":"Song"},
{"sTitle":"Artist"},
{"sTitle":"Album"},
{"sTitle":"Playlist"},
{"sTitle":"Show"},
{"sTitle":"bgcolor", "bVisible":false},
{"sTitle":"group_id", "bVisible":false}];
function createDataGrid(){
datagridData.columnHeaders[1]["fnRender"] = getDateText;
datagridData.columnHeaders[2]["fnRender"] = getTimeText;
datagridData.columnHeaders[3]["fnRender"] = getTimeText;
datagridData.columnHeaders[4]["fnRender"] = changeTimePrecisionInit;
columns[1]["fnRender"] = getDateText;
columns[2]["fnRender"] = getTimeText;
columns[3]["fnRender"] = getTimeText;
columns[4]["fnRender"] = changeTimePrecisionInit;
$('#demo').html( '<table cellpadding="0" cellspacing="0" border="0" class="datatable" id="nowplayingtable"></table>' );
$('#nowplayingtable').dataTable( {
@ -59,8 +82,9 @@ function createDataGrid(){
"bFilter": false,
"bInfo": false,
"bLengthChange": false,
"bPaginate": false,
"aaData": datagridData.rows,
"aoColumns": datagridData.columnHeaders,
"aoColumns": columns,
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
if (aData[aData.length-2] != "")
$(nRow).attr("style", "background-color:#166622");
@ -71,20 +95,30 @@ function createDataGrid(){
return nRow;
}
} );
setTimeout(init2, 5000);
}
var viewType = "now" //"day";
function setViewType(type){
if (type == 0){
viewType = "now";
} else {
viewType = "day";
}
init2();
}
function init2(){
$.ajax({ url: "/Nowplaying/get-data-grid-data/format/json", dataType:"json", success:function(data){
$.ajax({ url: "/Nowplaying/get-data-grid-data/format/json/view/" + viewType, dataType:"json", success:function(data){
datagridData = data.entries;
createDataGrid();
createDataGrid();
}});
if (typeof registerSongEndListener == 'function' && !registered){
registered = true;
registerSongEndListener(notifySongEnd);
}
setTimeout(init2, 5000);
}
$(document).ready(function() {