144 lines
5.6 KiB
PHP
144 lines
5.6 KiB
PHP
<?php
|
|
|
|
class Application_Model_Nowplaying
|
|
{
|
|
/*
|
|
public static function InsertBlankRow($i, $rows){
|
|
$startDateFull = $rows[$i-1][3];
|
|
$endDateFull = $rows[$i][2];
|
|
|
|
$startDate = explode(".", $startDateFull);
|
|
$endDate = explode(".", $endDateFull);
|
|
|
|
$epochStartMS = strtotime($startDate[0])*1000;
|
|
$epochEndMS = strtotime($endDate[0])*1000;
|
|
|
|
if (count($startDate) > 1)
|
|
$epochStartMS += $startDate[1];
|
|
if (count($endDate) > 1)
|
|
$epochEndMS += $endDate[1];
|
|
|
|
$blankRow = array(array("b", $startDateFull, $startDateFull, $endDate, Application_Model_DateHelper::ConvertMSToHHMMSSmm($epochEndMS - $epochStartMS), "-", "-", "-", "-" , "-", "", ""));
|
|
array_splice($rows, $i, 0, $blankRow);
|
|
return $rows;
|
|
}
|
|
|
|
public static function FindGaps($rows){
|
|
$n = count($rows);
|
|
|
|
$blankRowIndices = array();
|
|
$arrayIndexOffset = 0;
|
|
|
|
if ($n < 2)
|
|
return $rows;
|
|
|
|
for ($i=1; $i<$n; $i++){
|
|
if ($rows[$i-1][3] != $rows[$i][2])
|
|
array_push($blankRowIndices, $i);
|
|
}
|
|
|
|
for ($i=0, $n=count($blankRowIndices); $i<$n; $i++){
|
|
$rows = Application_Model_Nowplaying::InsertBlankRow($blankRowIndices[$i]+$arrayIndexOffset, $rows);
|
|
$arrayIndexOffset++;
|
|
}
|
|
|
|
return $rows;
|
|
}
|
|
*/
|
|
|
|
public static function FindGapsBetweenShows($showsMap){
|
|
return $showsMap;
|
|
}
|
|
|
|
public static function FindGapsAtEndOfShows($showsMap){
|
|
foreach($showsMap as $k => $show){
|
|
$showStartTime = $show['starts'];
|
|
$showEndTime = $show['ends'];
|
|
|
|
//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;
|
|
}
|
|
|
|
public static function GetDataGridData($viewType, $dateString){
|
|
|
|
//echo $dateString;
|
|
if ($viewType == "now"){
|
|
|
|
$date = new Application_Model_DateHelper;
|
|
$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");
|
|
} else {
|
|
$date = new Application_Model_DateHelper;
|
|
$time = $date->getTime();
|
|
$date->setDate($dateString." ".$time);
|
|
$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());
|
|
}
|
|
|
|
//$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 = Application_Model_Nowplaying::FindGapsBetweenShows($showsMap);
|
|
$showsMap = Application_Model_Nowplaying::FindGapsAtEndOfShows($showsMap);
|
|
|
|
//$rows = Application_Model_Nowplaying::FindGaps($rows);
|
|
$date = new Application_Model_DateHelper;
|
|
$timeNow = $date->getDate();
|
|
|
|
$data = array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$showsMap);
|
|
|
|
return $data;
|
|
}
|
|
}
|