-further modifications to now-playing view with grouping by shows
This commit is contained in:
parent
38856c4af7
commit
cb119802df
|
@ -36,8 +36,6 @@ class NowplayingController extends Zend_Controller_Action
|
||||||
$this->view->headScript()->appendFile('/js/playlist/nowplayingdatagrid.js','text/javascript');
|
$this->view->headScript()->appendFile('/js/playlist/nowplayingdatagrid.js','text/javascript');
|
||||||
$this->view->headScript()->appendFile('/js/playlist/dayview.js','text/javascript');
|
$this->view->headScript()->appendFile('/js/playlist/dayview.js','text/javascript');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,10 @@ class Application_Model_DateHelper
|
||||||
return $dayEndTS - $this->_timestamp;
|
return $dayEndTS - $this->_timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getEpochTime(){
|
||||||
|
return $this->_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
public static function TimeDiff($time1, $time2){
|
public static function TimeDiff($time1, $time2){
|
||||||
return strtotime($time2) - strtotime($time1);
|
return strtotime($time2) - strtotime($time1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,135 +9,140 @@ class Application_Model_Nowplaying
|
||||||
|
|
||||||
$startDate = explode(".", $startDateFull);
|
$startDate = explode(".", $startDateFull);
|
||||||
$endDate = explode(".", $endDateFull);
|
$endDate = explode(".", $endDateFull);
|
||||||
|
|
||||||
$epochStartMS = strtotime($startDate[0])*1000;
|
$epochStartMS = strtotime($startDate[0])*1000;
|
||||||
$epochEndMS = strtotime($endDate[0])*1000;
|
$epochEndMS = strtotime($endDate[0])*1000;
|
||||||
|
|
||||||
if (count($startDate) > 1)
|
if (count($startDate) > 1)
|
||||||
$epochStartMS += $startDate[1];
|
$epochStartMS += $startDate[1];
|
||||||
if (count($endDate) > 1)
|
if (count($endDate) > 1)
|
||||||
$epochEndMS += $endDate[1];
|
$epochEndMS += $endDate[1];
|
||||||
|
|
||||||
$blankRow = array(array("b", $startDateFull, $startDateFull, $endDate, Application_Model_DateHelper::ConvertMSToHHMMSSmm($epochEndMS - $epochStartMS), "-", "-", "-", "-" , "-", "", ""));
|
$blankRow = array(array("b", $startDateFull, $startDateFull, $endDate, Application_Model_DateHelper::ConvertMSToHHMMSSmm($epochEndMS - $epochStartMS), "-", "-", "-", "-" , "-", "", ""));
|
||||||
array_splice($rows, $i, 0, $blankRow);
|
array_splice($rows, $i, 0, $blankRow);
|
||||||
return $rows;
|
return $rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function FindGaps($rows){
|
public static function FindGaps($rows){
|
||||||
$n = count($rows);
|
$n = count($rows);
|
||||||
|
|
||||||
$blankRowIndices = array();
|
$blankRowIndices = array();
|
||||||
$arrayIndexOffset = 0;
|
$arrayIndexOffset = 0;
|
||||||
|
|
||||||
if ($n < 2)
|
if ($n < 2)
|
||||||
return $rows;
|
return $rows;
|
||||||
|
|
||||||
for ($i=1; $i<$n; $i++){
|
for ($i=1; $i<$n; $i++){
|
||||||
if ($rows[$i-1][3] != $rows[$i][2])
|
if ($rows[$i-1][3] != $rows[$i][2])
|
||||||
array_push($blankRowIndices, $i);
|
array_push($blankRowIndices, $i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for ($i=0, $n=count($blankRowIndices); $i<$n; $i++){
|
for ($i=0, $n=count($blankRowIndices); $i<$n; $i++){
|
||||||
$rows = Application_Model_Nowplaying::InsertBlankRow($blankRowIndices[$i]+$arrayIndexOffset, $rows);
|
$rows = Application_Model_Nowplaying::InsertBlankRow($blankRowIndices[$i]+$arrayIndexOffset, $rows);
|
||||||
$arrayIndexOffset++;
|
$arrayIndexOffset++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $rows;
|
return $rows;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
public static function FindGapsBetweenShows($showsMap){
|
public static function FindGapsBetweenShows($showsMap){
|
||||||
|
|
||||||
|
$previousShow = null;
|
||||||
|
foreach($showsMap as $k => $show){
|
||||||
|
$currentShow = $showsMap[$k];
|
||||||
|
|
||||||
|
if (!is_null($previousShow)){
|
||||||
|
$diff = strtotime($currentShow['starts']) - strtotime($previousShow['ends'])
|
||||||
|
if ($$diff != 0){
|
||||||
|
//array_splice($showsMap, $i, 0, $blankRow);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$previousShow = $showsMap[$k];
|
||||||
|
}
|
||||||
|
|
||||||
return $showsMap;
|
return $showsMap;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
public static function FindGapAtEndOfShow($show, $rows){
|
||||||
|
$showStartTime = $show['starts'];
|
||||||
|
$showEndTime = $show['ends'];
|
||||||
|
|
||||||
public static function FindGapsAtEndOfShows($showsMap){
|
if (count($rows) > 1){
|
||||||
foreach($showsMap as $k => $show){
|
$lastItem = $rows[count($rows)-1];
|
||||||
$showStartTime = $show['starts'];
|
$lastItemEndTime = $lastItem['ends'];
|
||||||
$showEndTime = $show['ends'];
|
} else {
|
||||||
|
$lastItemEndTime = $showStartTime;
|
||||||
//get the last songs end-time
|
|
||||||
$items = $show['items'];
|
|
||||||
if (count($items) > 1){
|
|
||||||
$lastItem = $items[count($items)-1];
|
|
||||||
$lastItemEndTime = $lastItem[3];
|
|
||||||
} else {
|
|
||||||
$lastItemEndTime = $showStartTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
$diff = Application_Model_DateHelper::TimeDiff($lastItemEndTime, $showEndTime);
|
|
||||||
//echo $diff."-";
|
|
||||||
if ($diff <= 0){
|
|
||||||
//ok!
|
|
||||||
} else {
|
|
||||||
//There is a gap at the end of the show
|
|
||||||
//insert blank row
|
|
||||||
array_push($items, array("b", $diff, "-", "-", "-", "-", "-", "-", "-", "-", "-", "-"));
|
|
||||||
$showsMap[$k]['items'] = $items;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $showsMap;
|
$diff = Application_Model_DateHelper::TimeDiff($lastItemEndTime, $showEndTime);
|
||||||
|
|
||||||
|
if ($diff <= 0){
|
||||||
|
//ok!
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
//There is a gap at the end of the show. Return blank row
|
||||||
|
return array("b", $diff, "-", "-", "-", "-", "-", "-", "-", "-", "-", "-");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function GetDataGridData($viewType, $dateString){
|
public static function GetDataGridData($viewType, $dateString){
|
||||||
|
|
||||||
//echo $dateString;
|
|
||||||
if ($viewType == "now"){
|
if ($viewType == "now"){
|
||||||
|
|
||||||
$date = new Application_Model_DateHelper;
|
$date = new Application_Model_DateHelper;
|
||||||
$timeNow = $date->getDate();
|
$timeNow = $date->getDate();
|
||||||
|
|
||||||
/* When do "ORDER BY x DESC LIMIT 5" to ensure that we get the last 5 previously scheduled items.
|
|
||||||
* However using DESC, puts our scheduled items in reverse order, so we need to reverse it again
|
|
||||||
* with array_reverse.
|
|
||||||
*/
|
|
||||||
$previous = array_reverse(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");
|
|
||||||
|
|
||||||
$showsMap = Show_DAL::GetShowsInRange($timeNow, "60 seconds", "24 hours");
|
$startCutoff = 60;
|
||||||
|
$endCutoff = 86400; //60*60*24 - seconds in a day
|
||||||
} else {
|
} else {
|
||||||
$date = new Application_Model_DateHelper;
|
$date = new Application_Model_DateHelper;
|
||||||
$time = $date->getTime();
|
$time = $date->getTime();
|
||||||
$date->setDate($dateString." ".$time);
|
$date->setDate($dateString." ".$time);
|
||||||
$timeNow = $date->getDate();
|
$timeNow = $date->getDate();
|
||||||
|
|
||||||
$previous = array_reverse(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");
|
|
||||||
|
|
||||||
$showsMap = Show_DAL::GetShowsInRange($timeNow, $date->getNowDayStartDiff(), $date->getNowDayEndDiff());
|
$startCutoff = $date->getNowDayStartDiff();
|
||||||
|
$endCutoff = $date->getNowDayEndDiff();
|
||||||
}
|
}
|
||||||
|
|
||||||
//$rows = array();
|
|
||||||
//print_r($showsMap);
|
|
||||||
|
|
||||||
foreach ($previous as $item){
|
|
||||||
array_push($showsMap[$item["instance_id"]]['items'], array("p", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
|
|
||||||
$item["album_title"], $item["name"], $item["show_name"], $item["instance_id"], $item["group_id"]));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($current as $item){
|
|
||||||
array_push($showsMap[$item["instance_id"]]['items'], array("c", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
|
|
||||||
$item["album_title"], $item["name"], $item["show_name"], $item["instance_id"], $item["group_id"]));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($next as $item){
|
|
||||||
array_push($showsMap[$item["instance_id"]]['items'], array("n", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
|
|
||||||
$item["album_title"], $item["name"], $item["show_name"], $item["instance_id"], $item["group_id"]));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$showsMap = Show_DAL::GetShowsInRange($timeNow, $startCutoff, $endCutoff);
|
||||||
|
|
||||||
|
//iterate over each show, and calculate information for it.
|
||||||
|
foreach($showsMap as $k => $show){
|
||||||
|
$rows = Schedule::GetShowInstanceItems($k);
|
||||||
|
$gapRow = Application_Model_Nowplaying::FindGapAtEndOfShow($showsMap[$k], $rows);
|
||||||
|
foreach ($rows as $item){
|
||||||
|
//check if this item is in todays date range
|
||||||
|
if (strtotime($item['ends']) > $date->getEpochTime() - $startCutoff
|
||||||
|
&& strtotime($item['starts']) < $date->getEpochTime() + $endCutoff){
|
||||||
|
|
||||||
|
if ($item['ends'] < $timeNow){
|
||||||
|
$type = "p";
|
||||||
|
} else if ($item['starts'] < $timeNow && $timeNow < $item['ends']){
|
||||||
|
$type = "c";
|
||||||
|
} else {
|
||||||
|
$type = "n";
|
||||||
|
}
|
||||||
|
|
||||||
|
array_push($showsMap[$k]['items'], array($type, $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
|
||||||
|
$item["album_title"], $item["name"], $item["show_name"], $item["instance_id"], $item["group_id"]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_null($gapRow))
|
||||||
|
array_push($showsMap[$k]['items'], $gapRow);
|
||||||
|
}
|
||||||
|
|
||||||
//$showsMap = Application_Model_Nowplaying::FindGapsBetweenShows($showsMap);
|
//$showsMap = Application_Model_Nowplaying::FindGapsBetweenShows($showsMap);
|
||||||
$showsMap = Application_Model_Nowplaying::FindGapsAtEndOfShows($showsMap);
|
|
||||||
|
|
||||||
//$rows = Application_Model_Nowplaying::FindGaps($rows);
|
|
||||||
$date = new Application_Model_DateHelper;
|
$date = new Application_Model_DateHelper;
|
||||||
$timeNow = $date->getDate();
|
$timeNow = $date->getDate();
|
||||||
|
|
||||||
$data = array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$showsMap);
|
return array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$showsMap);
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -511,6 +511,22 @@ class Schedule {
|
||||||
return $rows;
|
return $rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function GetShowInstanceItems($instance_id){
|
||||||
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
|
||||||
|
$sql = "SELECT DISTINCT pt.name, ft.track_title, ft.artist_name, ft.album_title, st.starts, st.ends, st.clip_length, st.media_item_played, st.group_id, show.name as show_name, st.instance_id"
|
||||||
|
." FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt, $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] show"
|
||||||
|
." WHERE st.playlist_id = pt.id"
|
||||||
|
." AND st.file_id = ft.id"
|
||||||
|
." AND st.instance_id = si.id"
|
||||||
|
." AND si.show_id = show.id"
|
||||||
|
." AND instance_id = $instance_id"
|
||||||
|
." ORDER BY st.starts";
|
||||||
|
|
||||||
|
$rows = $CC_DBC->GetAll($sql);
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
public static function UpdateMediaPlayedStatus($id){
|
public static function UpdateMediaPlayedStatus($id){
|
||||||
global $CC_CONFIG, $CC_DBC;
|
global $CC_CONFIG, $CC_DBC;
|
||||||
$sql = "UPDATE ".$CC_CONFIG['scheduleTable']
|
$sql = "UPDATE ".$CC_CONFIG['scheduleTable']
|
||||||
|
|
|
@ -768,7 +768,9 @@ class Show_DAL{
|
||||||
." $CC_CONFIG[showInstances] si,"
|
." $CC_CONFIG[showInstances] si,"
|
||||||
." $CC_CONFIG[showTable] s"
|
." $CC_CONFIG[showTable] s"
|
||||||
." WHERE si.show_id = s.id"
|
." WHERE si.show_id = s.id"
|
||||||
." AND (si.ends > TIMESTAMP '$timeNow' - INTERVAL '$start seconds' OR si.starts < TIMESTAMP '$timeNow' + INTERVAL '$end seconds')"
|
." AND ((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'))"
|
||||||
." ORDER BY si.starts";
|
." ORDER BY si.starts";
|
||||||
|
|
||||||
$rows = $CC_DBC->GetAll($sql);
|
$rows = $CC_DBC->GetAll($sql);
|
||||||
|
|
|
@ -148,11 +148,11 @@ function createDataGrid(){
|
||||||
var iDisplayIndex = oSettings._iDisplayStart + i;
|
var iDisplayIndex = oSettings._iDisplayStart + i;
|
||||||
var sType = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[0];
|
var sType = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[0];
|
||||||
|
|
||||||
var showName = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[9];
|
|
||||||
var startTime = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[2];
|
|
||||||
var endTime = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[3];
|
|
||||||
|
|
||||||
if ( sType == "s" ){
|
if ( sType == "s" ){
|
||||||
|
var showName = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[9];
|
||||||
|
var startTime = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[2];
|
||||||
|
var endTime = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[3];
|
||||||
|
|
||||||
var nGroup = document.createElement('tr');
|
var nGroup = document.createElement('tr');
|
||||||
var nCell = document.createElement('td');
|
var nCell = document.createElement('td');
|
||||||
nCell.colSpan = iColspan;
|
nCell.colSpan = iColspan;
|
||||||
|
@ -160,6 +160,16 @@ function createDataGrid(){
|
||||||
nCell.innerHTML = showName + ": " + startTime + " - " + endTime;
|
nCell.innerHTML = showName + ": " + startTime + " - " + endTime;
|
||||||
nGroup.appendChild(nCell);
|
nGroup.appendChild(nCell);
|
||||||
nTrs[i].parentNode.replaceChild(nGroup, nTrs[i]);
|
nTrs[i].parentNode.replaceChild(nGroup, nTrs[i]);
|
||||||
|
} else if ( sType == "b" ){
|
||||||
|
var gapTime = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[1];
|
||||||
|
|
||||||
|
var nGroup = document.createElement('tr');
|
||||||
|
var nCell = document.createElement('td');
|
||||||
|
nCell.colSpan = iColspan;
|
||||||
|
nCell.className = "gap";
|
||||||
|
nCell.innerHTML = "Gap until show end: " + gapTime + " seconds";
|
||||||
|
nGroup.appendChild(nCell);
|
||||||
|
nTrs[i].parentNode.replaceChild(nGroup, nTrs[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue