From 38856c4af713af03cd1b216b15833aaf8fd9f122 Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 4 Mar 2011 18:26:22 -0500 Subject: [PATCH] -began adding grouping by shows for the datatable. --- application/models/DateHelper.php | 4 ++ application/models/Nowplaying.php | 62 ++++++++++++++++++++---- application/models/Shows.php | 28 +++++++++++ dev/pf.sh | 3 ++ dev/pl.sh | 3 ++ dev/pp.sh | 3 ++ public/js/playlist/nowplayingdatagrid.js | 35 ++++++++++++- 7 files changed, 126 insertions(+), 12 deletions(-) create mode 100755 dev/pf.sh create mode 100755 dev/pl.sh create mode 100755 dev/pp.sh diff --git a/application/models/DateHelper.php b/application/models/DateHelper.php index e24d9c7ec..052fe10d5 100644 --- a/application/models/DateHelper.php +++ b/application/models/DateHelper.php @@ -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); diff --git a/application/models/Nowplaying.php b/application/models/Nowplaying.php index 43d6bdc4b..fb4cab6d8 100644 --- a/application/models/Nowplaying.php +++ b/application/models/Nowplaying.php @@ -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; } diff --git a/application/models/Shows.php b/application/models/Shows.php index c6902fa80..fc3da8600 100644 --- a/application/models/Shows.php +++ b/application/models/Shows.php @@ -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; + } } diff --git a/dev/pf.sh b/dev/pf.sh new file mode 100755 index 000000000..324a44a36 --- /dev/null +++ b/dev/pf.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +su -l pypo -c "tail -F /etc/service/pypo-fetch/log/main/current" diff --git a/dev/pl.sh b/dev/pl.sh new file mode 100755 index 000000000..7c6f8b650 --- /dev/null +++ b/dev/pl.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +su -l pypo -c "tail -F /etc/service/pypo-liquidsoap/log/main/current" diff --git a/dev/pp.sh b/dev/pp.sh new file mode 100755 index 000000000..f1aac3025 --- /dev/null +++ b/dev/pp.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +su -l pypo -c "tail -F /etc/service/pypo-push/log/main/current" diff --git a/public/js/playlist/nowplayingdatagrid.js b/public/js/playlist/nowplayingdatagrid.js index 98cd108bb..25d8dedcc 100644 --- a/public/js/playlist/nowplayingdatagrid.js +++ b/public/js/playlist/nowplayingdatagrid.js @@ -60,7 +60,7 @@ var columns = [{"sTitle": "type", "bVisible":false}, {"sTitle":"Album"}, {"sTitle":"Playlist"}, {"sTitle":"Show"}, - {"sTitle":"bgcolor", "bVisible":false}, + {"sTitle":"instance_id", "bVisible":true}, {"sTitle":"group_id", "bVisible":false}]; function getDateString(){ @@ -85,7 +85,9 @@ function updateDataTable(){ //function can be called before ajax call has been returned. if (datagridData != null){ table.fnClearTable(false); - table.fnAddData(datagridData.rows, false); + for (var show in datagridData.rows){ + table.fnAddData(datagridData.rows[show].items, false); + } table.fnDraw(true); } } @@ -133,6 +135,35 @@ function createDataGrid(){ $(nRow).attr("class", "gap"); return nRow; }, + "fnDrawCallback": function(oSettings){ + //check if there are any rows to display + if (oSettings.aiDisplay.length == 0) + return; + + var nTrs = $('#nowplayingtable tbody tr'); + var iColspan = nTrs[0].getElementsByTagName('td').length; + + for (var i=0; i