diff --git a/application/models/Nowplaying.php b/application/models/Nowplaying.php index c0325dc9d..563dada04 100644 --- a/application/models/Nowplaying.php +++ b/application/models/Nowplaying.php @@ -2,92 +2,90 @@ 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); + public static function FindBeginningOfShow($rows){ + $numRows = count($rows); - $epochStartMS = strtotime($startDate[0])*1000; - $epochEndMS = strtotime($endDate[0])*1000; + $newCopy = array(); - if (count($startDate) > 1) - $epochStartMS += $startDate[1]; - if (count($endDate) > 1) - $epochEndMS += $endDate[1]; + 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']; - $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); + array_push($newCopy, $group); + } + array_push($newCopy, $currentRow); } - for ($i=0, $n=count($blankRowIndices); $i<$n; $i++){ - $rows = Application_Model_Nowplaying::InsertBlankRow($blankRowIndices[$i]+$arrayIndexOffset, $rows); - $arrayIndexOffset++; - } - - return $rows; + return $newCopy; } - */ - -/* - public static function FindGapsBetweenShows($showsMap){ + public static function FindGapAtEndOfShow($rows){ + $numRows = count($rows); - $previousShow = null; - foreach($showsMap as $k => $show){ - $currentShow = $showsMap[$k]; + $newCopy = array(); - if (!is_null($previousShow)){ - $diff = strtotime($currentShow['starts']) - strtotime($previousShow['ends']) - if ($$diff != 0){ - //array_splice($showsMap, $i, 0, $blankRow); + 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); } } - - $previousShow = $showsMap[$k]; } - - return $showsMap; + return $newCopy; } -*/ - public static function FindGapAtEndOfShow($show, $rows){ - $showStartTime = $show['starts']; - $showEndTime = $show['ends']; - if (count($rows) > 1){ - $lastItem = $rows[count($rows)-1]; - $lastItemEndTime = $lastItem['ends']; - } else { - $lastItemEndTime = $showStartTime; + public static function FilterRowsByDate($rows, $date, $startCutoff, $endCutoff){ + $dateNow = new Application_Model_DateHelper; + $timeNow = $dateNow->getDate(); + + $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'])){ + $type = "c"; + } else { + $type = "n"; + } + + 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"], $item["instance_id"])); + } } - $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, "-", "-", "-", "-", "-", "-", "-", "-", "-", "-"); - } + return $data; } public static function GetDataGridData($viewType, $dateString){ @@ -105,44 +103,19 @@ class Application_Model_Nowplaying $timeNow = $date->getDate(); $startCutoff = $date->getNowDayStartDiff(); - $endCutoff = $date->getNowDayEndDiff(); + $endCutoff = $date->getNowDayEndDiff(); } - $showsMap = Show_DAL::GetShowsInRange($timeNow, $startCutoff, $endCutoff); + $rows = Show_DAL::GetShowsInRange($timeNow, $startCutoff, $endCutoff); + $rows = Application_Model_Nowplaying::FindBeginningOfShow($rows); + $rows = Application_Model_Nowplaying::FindGapAtEndOfShow($rows); + //$rows = FindGapsBetweenShows + $data = Application_Model_Nowplaying::FilterRowsByDate($rows, $date, $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); - - $date = new Application_Model_DateHelper; $timeNow = $date->getDate(); - - return array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$showsMap); + return array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$data); } } diff --git a/application/models/Shows.php b/application/models/Shows.php index 065328d02..1465203b6 100644 --- a/application/models/Shows.php +++ b/application/models/Shows.php @@ -760,32 +760,33 @@ class Show_DAL{ 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.starts < TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends > TIMESTAMP '$timeNow' - INTERVAL '$start seconds')" + $sql = "SELECT" + ." si.starts as show_starts," + ." si.ends as show_ends," + ." st.starts as item_starts," + ." st.ends as item_ends," + ." st.clip_length as clip_length," + ." ft.track_title as track_title," + ." ft.artist_name as artist_name," + ." ft.album_title as album_title," + ." s.name as show_name," + ." si.id as instance_id," + ." pt.name as playlist_name" + ." FROM $CC_CONFIG[showInstances] si" + ." LEFT JOIN $CC_CONFIG[scheduleTable] st" + ." ON st.instance_id = si.id" + ." LEFT JOIN $CC_CONFIG[playListTable] pt" + ." ON st.playlist_id = pt.id" + ." LEFT JOIN $CC_CONFIG[filesTable] ft" + ." ON st.file_id = ft.id" + ." LEFT JOIN $CC_CONFIG[showTable] s" + ." ON si.show_id = s.id" + ." 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'))" - ." ORDER BY si.starts"; + ." ORDER BY st.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; + return $CC_DBC->GetAll($sql); } } diff --git a/public/js/playlist/nowplayingdatagrid.js b/public/js/playlist/nowplayingdatagrid.js index b0ee7ba25..97313278c 100644 --- a/public/js/playlist/nowplayingdatagrid.js +++ b/public/js/playlist/nowplayingdatagrid.js @@ -60,8 +60,7 @@ var columns = [{"sTitle": "type", "bVisible":false}, {"sTitle":"Album"}, {"sTitle":"Playlist"}, {"sTitle":"Show"}, - {"sTitle":"instance_id", "bVisible":true}, - {"sTitle":"group_id", "bVisible":false}]; + {"sTitle":"instance_id", "bVisible":true}]; function getDateString(){ var date0 = $("#datepicker").datepicker("getDate"); @@ -85,9 +84,7 @@ function updateDataTable(){ //function can be called before ajax call has been returned. if (datagridData != null){ table.fnClearTable(false); - for (var show in datagridData.rows){ - table.fnAddData(datagridData.rows[show].items, false); - } + table.fnAddData(datagridData.rows, false); table.fnDraw(true); } } @@ -131,8 +128,6 @@ function createDataGrid(){ $(nRow).addClass("playing-list"); if (aData[0] == "c") $(nRow).attr("class", "playing-song"); - else if (aData[0] == "b") - $(nRow).attr("class", "gap"); return nRow; }, "fnDrawCallback": function(oSettings){ @@ -148,7 +143,7 @@ function createDataGrid(){ var iDisplayIndex = oSettings._iDisplayStart + i; var sType = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex]]._aData[0]; - if ( sType == "s" ){ + if ( sType == "g" ){ 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];