CC-2229-refactor-now-playing-code

-server side done.
This commit is contained in:
mkonecny 2011-05-05 13:24:21 -04:00
parent 1492dcf283
commit 48ed126703
3 changed files with 101 additions and 60 deletions

View file

@ -145,6 +145,27 @@ class Application_Model_Nowplaying
}
*/
public static function CreateHeaderRow($p_showName, $p_showStart, $p_showEnd){
return array("h", $p_showName, $p_showStart, $p_showEnd, "", "", "", "", "", "", "");
}
public static function CreateDatatableRows($p_dbRows){
$dataTablesRows = array();
foreach ($p_dbRows as $dbRow){
$dataTablesRows[] = array('a', $dbRow['show_starts'], $dbRow['show_starts'], $dbRow['show_ends'],
$dbRow['clip_length'], $dbRow['track_title'], $dbRow['artist_name'], $dbRow['album_title'],
$dbRow['playlist_name'], $dbRow['playlist_name'], $dbRow['show_name']);
}
return $dataTablesRows;
}
public static function CreateGapRow($p_gapTime){
return array("g", $p_gapTime, "", "", "", "", "", "", "", "", "");
}
public static function GetDataGridData($viewType, $dateString){
if ($viewType == "now"){
@ -163,24 +184,31 @@ class Application_Model_Nowplaying
$endCutoff = $date->getNowDayEndDiff();
}
$showInstances = Show::GetShowsInstancesInRange($timeNow, $startCutoff, $endCutoff);
$data = array();
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array()
);
$showIds = ShowInstance::GetShowsInstancesIdsInRange($timeNow, $startCutoff, $endCutoff);
foreach ($showIds as $showId){
$instanceId = $showId['id'];
foreach ($showInstances as $si){
$rows = $si->getShowContent();
foreach ($rows as $row){
$output['aaData'][] = $row;
}
$output['aaData'][] = $si->getShowEndGap();
$si = new ShowInstance($instanceId);
$showId->getShowId();
$show = new Show($showId);
//append show header row
$data[] = Application_Model_Nowplaying::CreateHeaderRow($show->getName(), $si->getShowStart(), $si->getShowEnd());
$scheduledItems = $si->getScheduleItemsInRange($timeNow, $startCutoff, $endCutoff);
$dataTablesRows = Application_Model_Nowplaying::CreateDatatableRows($scheduledItems);
//append show audio item rows
$data = array_merge($data, $dataTablesRows);
//append show gap time row
$gapTime = $si->getShowEndGapTime();
$data[] = Application_Model_Nowplaying::CreateGapRow($gapTime);
}
return $output;
return $data;
}
}