cc-2229-refactor-now-playing-code
-further refactoring...
This commit is contained in:
parent
48ed126703
commit
7010f2156e
6 changed files with 39 additions and 168 deletions
|
@ -16,26 +16,16 @@ class NowplayingController extends Zend_Controller_Action
|
|||
$baseUrl = $request->getBaseUrl();
|
||||
|
||||
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/js/jquery.dataTables.min.js','text/javascript');
|
||||
$this->view->headScript()->appendFile($baseUrl.'/js/playlist/nowplayingdatagrid.js','text/javascript');
|
||||
$this->view->headScript()->appendFile($baseUrl.'/js/playlist/nowview.js','text/javascript');
|
||||
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/nowplaying/nowplayingdatagrid.js','text/javascript');
|
||||
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/nowplaying/nowview.js','text/javascript');
|
||||
}
|
||||
|
||||
public function getDataGridDataAction()
|
||||
{
|
||||
$iTotal = 5;
|
||||
$iFilteredTotal = 5;
|
||||
|
||||
$output = array(
|
||||
"sEcho" => intval($this->_request->getParam('sEcho')),
|
||||
"iTotalRecords" => $iTotal,
|
||||
"iTotalDisplayRecords" => $iFilteredTotal
|
||||
);
|
||||
|
||||
$viewType = $this->_request->getParam('view');
|
||||
$dateString = $this->_request->getParam('date');
|
||||
$output["aaData"] = Application_Model_Nowplaying::GetDataGridData($viewType, $dateString);
|
||||
$this->view->entries = Application_Model_Nowplaying::GetDataGridData($viewType, $dateString);
|
||||
|
||||
die(json_encode($output));
|
||||
}
|
||||
|
||||
public function livestreamAction()
|
||||
|
@ -50,8 +40,8 @@ class NowplayingController extends Zend_Controller_Action
|
|||
$baseUrl = $request->getBaseUrl();
|
||||
|
||||
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/js/jquery.dataTables.min.js','text/javascript');
|
||||
$this->view->headScript()->appendFile($baseUrl.'/js/playlist/nowplayingdatagrid.js','text/javascript');
|
||||
$this->view->headScript()->appendFile($baseUrl.'/js/playlist/dayview.js','text/javascript');
|
||||
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/nowplaying/nowplayingdatagrid.js','text/javascript');
|
||||
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/nowplaying/dayview.js','text/javascript');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,148 +2,6 @@
|
|||
|
||||
class Application_Model_Nowplaying
|
||||
{
|
||||
/*
|
||||
public static function FindBeginningOfShow($rows){
|
||||
$numRows = count($rows);
|
||||
|
||||
$newCopy = array();
|
||||
|
||||
for ($i=0; $i<$numRows; $i++){
|
||||
$currentRow = $rows[$i];
|
||||
if ($i == 0 || ($i != 0 && $currentRow['instance_id'] != $rows[$i-1]['instance_id'])){
|
||||
//$currentRow is first instance of a show.
|
||||
$group = $currentRow;
|
||||
$group['group'] = 'x';
|
||||
$group['item_starts'] = $group['show_starts'];
|
||||
$group['item_ends'] = $group['show_ends'];
|
||||
|
||||
array_push($newCopy, $group);
|
||||
}
|
||||
array_push($newCopy, $currentRow);
|
||||
}
|
||||
|
||||
return $newCopy;
|
||||
}
|
||||
|
||||
public static function FindGapAtEndOfShow($rows){
|
||||
$numRows = count($rows);
|
||||
|
||||
$newCopy = array();
|
||||
|
||||
for ($i=0; $i<$numRows; $i++){
|
||||
$currentRow = $rows[$i];
|
||||
array_push($newCopy, $currentRow);
|
||||
if ($i+1 == $numRows || ($i+1 !=$numRows && $currentRow['instance_id'] != $rows[$i+1]['instance_id'])){
|
||||
//$row is the last instance in the show.
|
||||
|
||||
if ($currentRow['item_ends'] == ""){
|
||||
//show is empty and has no scheduled items in it. Therefore
|
||||
//the gap is the entire length of the show.
|
||||
$currentRow['item_ends'] = $currentRow['show_starts'];
|
||||
}
|
||||
|
||||
$diff = strtotime($currentRow['show_ends']) - strtotime($currentRow['item_ends']);
|
||||
if ($diff > 0){
|
||||
//gap at the end of show. Lets create a "gap" row
|
||||
$gap = $currentRow;
|
||||
$gap['gap'] = '';
|
||||
$gap['item_starts'] = $diff;
|
||||
|
||||
array_push($newCopy, $gap);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $newCopy;
|
||||
}
|
||||
|
||||
public static function FilterRowsByDate($rows, $date, $startCutoff, $endCutoff){
|
||||
$dateNow = new DateHelper;
|
||||
$timeNow = $dateNow->getTimestamp();
|
||||
|
||||
$data = array();
|
||||
//iterate over each show, and calculate information for it.
|
||||
$numItems = count($rows);
|
||||
for ($i=0; $i<$numItems; $i++){
|
||||
$item = $rows[$i];
|
||||
|
||||
if ((strtotime($item['item_ends']) > $date->getEpochTime() - $startCutoff
|
||||
&& strtotime($item['item_starts']) < $date->getEpochTime() + $endCutoff) || array_key_exists("group", $item) || array_key_exists("gap", $item)){
|
||||
|
||||
if (array_key_exists("group", $item)){
|
||||
$type = "g";
|
||||
} else if (array_key_exists("gap", $item)){
|
||||
$type = "b";
|
||||
} else if (strtotime($item['item_ends']) < strtotime($timeNow)){
|
||||
$type = "p";
|
||||
} else if (strtotime($item['item_starts']) < strtotime($timeNow) && strtotime($timeNow) < strtotime($item['item_ends'])
|
||||
&& strtotime($item['show_starts']) < strtotime($timeNow) && strtotime($timeNow) < strtotime($item['show_ends'])){
|
||||
$type = "c";
|
||||
} else {
|
||||
$type = "n";
|
||||
}
|
||||
|
||||
$over = "";
|
||||
if (strtotime($item['item_ends']) > strtotime($item['show_ends']))
|
||||
$over = "x";
|
||||
|
||||
array_push($data, array($type, $item["item_starts"], $item["item_starts"], $item["item_ends"], $item["clip_length"], $item["track_title"], $item["artist_name"], $item["album_title"], $item["playlist_name"], $item["show_name"], $over, $item["instance_id"]));
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function HandleRebroadcastShows($rows){
|
||||
$newCopy = array();
|
||||
|
||||
$numRows = count($rows);
|
||||
for ($i=0; $i<$numRows; $i++){
|
||||
$currentRow = $rows[$i];
|
||||
if ($currentRow["rebroadcast"] == 1 && !array_key_exists("group", $currentRow)){
|
||||
$newRow = $currentRow;
|
||||
unset($newRow['group']);
|
||||
$newRow['item_starts'] = $newRow['show_starts'];
|
||||
$newRow['item_ends'] = $newRow['show_ends'];
|
||||
|
||||
array_push($newCopy, $newRow);
|
||||
} else {
|
||||
array_push($newCopy, $currentRow);
|
||||
}
|
||||
}
|
||||
|
||||
return $newCopy;
|
||||
}
|
||||
|
||||
public static function GetDataGridData($viewType, $dateString){
|
||||
|
||||
if ($viewType == "now"){
|
||||
$date = new DateHelper;
|
||||
$timeNow = $date->getTimestamp();
|
||||
|
||||
$startCutoff = 60;
|
||||
$endCutoff = 86400; //60*60*24 - seconds in a day
|
||||
} else {
|
||||
$date = new DateHelper;
|
||||
$time = $date->getTime();
|
||||
$date->setDate($dateString." ".$time);
|
||||
$timeNow = $date->getTimestamp();
|
||||
|
||||
$startCutoff = $date->getNowDayStartDiff();
|
||||
$endCutoff = $date->getNowDayEndDiff();
|
||||
}
|
||||
|
||||
$rows = Show_DAL::GetShowsInRange($timeNow, $startCutoff, $endCutoff);
|
||||
$rows = Application_Model_Nowplaying::FindBeginningOfShow($rows);
|
||||
$rows = Application_Model_Nowplaying::HandleRebroadcastShows($rows);
|
||||
$rows = Application_Model_Nowplaying::FindGapAtEndOfShow($rows);
|
||||
//$rows = FindGapsBetweenShows()
|
||||
$data = Application_Model_Nowplaying::FilterRowsByDate($rows, $date, $startCutoff, $endCutoff);
|
||||
|
||||
$date = new DateHelper;
|
||||
$timeNow = $date->getTimestamp();
|
||||
return array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$data);
|
||||
}
|
||||
*/
|
||||
|
||||
public static function CreateHeaderRow($p_showName, $p_showStart, $p_showEnd){
|
||||
return array("h", $p_showName, $p_showStart, $p_showEnd, "", "", "", "", "", "", "");
|
||||
|
@ -192,7 +50,7 @@ class Application_Model_Nowplaying
|
|||
|
||||
$si = new ShowInstance($instanceId);
|
||||
|
||||
$showId->getShowId();
|
||||
$showId = $si->getShowId();
|
||||
$show = new Show($showId);
|
||||
|
||||
//append show header row
|
||||
|
@ -209,6 +67,6 @@ class Application_Model_Nowplaying
|
|||
$data[] = Application_Model_Nowplaying::CreateGapRow($gapTime);
|
||||
}
|
||||
|
||||
return $data;
|
||||
return array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1657,7 +1657,7 @@ class ShowInstance {
|
|||
|
||||
public function getScheduleItemsInRange($timeNow, $start, $end)
|
||||
{
|
||||
global $CC_DBC;
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
|
||||
$instanceId = $this->_instanceId;
|
||||
|
||||
|
@ -1686,16 +1686,36 @@ class ShowInstance {
|
|||
." WHERE ((si.starts < TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends > TIMESTAMP '$timeNow' - INTERVAL '$start seconds')"
|
||||
." OR (si.starts > TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends < TIMESTAMP '$timeNow' + INTERVAL '$end seconds')"
|
||||
." OR (si.starts < TIMESTAMP '$timeNow' + INTERVAL '$end seconds' AND si.ends > TIMESTAMP '$timeNow' + INTERVAL '$end seconds'))"
|
||||
//checking for st.starts IS NULL so that the query also returns shows that do not have any items scheduled.
|
||||
." AND (st.starts < si.ends OR st.starts IS NULL)"
|
||||
." AND (st.starts < si.ends)"
|
||||
." AND si.id = $instanceId"
|
||||
." ORDER BY si.starts, st.starts";
|
||||
|
||||
return $CC_DBC->GetAll($sql);
|
||||
}
|
||||
|
||||
public function getLastAudioItemEnd(){
|
||||
global $CC_DBC;
|
||||
|
||||
$sql = "SELECT ends FROM cc_schedule "
|
||||
."WHERE instance_id = {$this->_instanceId} "
|
||||
."ORDER BY ends DESC "
|
||||
."LIMIT 1";
|
||||
|
||||
return $CC_DBC->GetOne($sql);
|
||||
}
|
||||
|
||||
public function getShowEndGapTime(){
|
||||
return 5;
|
||||
$showEnd = $this->getShowEnd();
|
||||
$lastItemEnd = $this->getLastAudioItemEnd();
|
||||
|
||||
if (is_null($lastItemEnd)){
|
||||
$lastItemEnd = $this->getShowStart();
|
||||
}
|
||||
|
||||
|
||||
$diff = strtotime($showEnd) - strtotime($lastItemEnd);
|
||||
|
||||
return ($diff < 0) ? 0 : $diff;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,8 +68,7 @@ var columns = [{"sTitle": "type", "bVisible":false},
|
|||
{"sTitle":"Album"},
|
||||
{"sTitle":"Playlist"},
|
||||
{"sTitle":"Show"},
|
||||
{"sTitle":"Status", "fnRender":statusColumn},
|
||||
{"sTitle":"instance_id", "bVisible":false}];
|
||||
{"sTitle":"Status", "fnRender":statusColumn}];
|
||||
|
||||
function getDateString(){
|
||||
var date0 = $("#datepicker").datepicker("getDate");
|
||||
|
@ -155,8 +154,10 @@ function createDataGrid(){
|
|||
var iDisplayIndex = oSettings._iDisplayStart + i;
|
||||
var sType = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[0];
|
||||
|
||||
if ( sType == "g" ){
|
||||
var showName = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[9];
|
||||
if ( sType == "h" ){
|
||||
//show header row found
|
||||
|
||||
var showName = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[1];
|
||||
var startTime = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[2];
|
||||
var endTime = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[3];
|
||||
|
||||
|
@ -167,7 +168,9 @@ function createDataGrid(){
|
|||
nCell.innerHTML = showName + ": " + startTime + " - " + endTime;
|
||||
nGroup.appendChild(nCell);
|
||||
nTrs[i].parentNode.replaceChild(nGroup, nTrs[i]);
|
||||
} else if ( sType == "b" ){
|
||||
} else if ( sType == "g" ){
|
||||
//gap row found
|
||||
|
||||
var gapTime = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[1];
|
||||
|
||||
var nGroup = document.createElement('tr');
|
Loading…
Add table
Add a link
Reference in a new issue