-began adding grouping by shows for the datatable.

This commit is contained in:
martin 2011-03-04 18:26:22 -05:00
parent d22ab329d8
commit 38856c4af7
7 changed files with 126 additions and 12 deletions

View file

@ -29,6 +29,10 @@ class Application_Model_DateHelper
$dayEndTS = strtotime(date("Y-m-d", $this->_timestamp+(86400)));
return $dayEndTS - $this->_timestamp;
}
public static function TimeDiff($time1, $time2){
return strtotime($time2) - strtotime($time1);
}
public static function ConvertMSToHHMMSSmm($time){
$hours = floor($time / 3600000);

View file

@ -2,7 +2,7 @@
class Application_Model_Nowplaying
{
/*
public static function InsertBlankRow($i, $rows){
$startDateFull = $rows[$i-1][3];
$endDateFull = $rows[$i][2];
@ -44,6 +44,40 @@ class Application_Model_Nowplaying
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){
@ -60,6 +94,8 @@ class Application_Model_Nowplaying
$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();
@ -68,33 +104,39 @@ class Application_Model_Nowplaying
$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");
$next = Schedule::Get_Scheduled_Item_Data($timeNow, 1, "ALL", $date->getNowDayEndDiff()." seconds");
$showsMap = Show_DAL::GetShowsInRange($timeNow, $date->getNowDayStartDiff(), $date->getNowDayEndDiff());
}
$rows = array();
//$rows = array();
//print_r($showsMap);
foreach ($previous as $item){
array_push($rows, array("p", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
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($rows, array("c", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
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($rows, array("n", $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
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"]));
}
$rows = Application_Model_Nowplaying::FindGaps($rows);
//$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"=>$rows);
$data = array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$showsMap);
return $data;
}

View file

@ -757,5 +757,33 @@ class Show_DAL{
$rows = $CC_DBC->GetAll($sql);
return $rows;
}
public static function GetShowsInRange($timeNow, $start, $end){
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT *,"
." si.starts as start_timestamp,"
." si.ends as end_timestamp,"
." si.id as instance_id"
." FROM "
." $CC_CONFIG[showInstances] si,"
." $CC_CONFIG[showTable] s"
." WHERE si.show_id = s.id"
." AND (si.ends > TIMESTAMP '$timeNow' - INTERVAL '$start seconds' OR si.starts < TIMESTAMP '$timeNow' + INTERVAL '$end seconds')"
." ORDER BY si.starts";
$rows = $CC_DBC->GetAll($sql);
$showsMap = array();
$rowsCount = count($rows);
for ($i=0; $i<$rowsCount; $i++){
$rows[$i]['items'] = array();
array_push($rows[$i]['items'],
array("s", $rows[$i]["starts"], $rows[$i]["starts"], $rows[$i]["ends"], "", "", "", "", "", $rows[$i]["name"], $rows[$i]["instance_id"], ""));
$showsMap[$rows[$i]['instance_id']] = $rows[$i];
}
return $showsMap;
}
}