CC-3465: Now playing should show tracks over shows for previous and next

- added logic to include previous and next show in schedule query so the now playing bar will show the tracks from the show instead of the show itself.
This commit is contained in:
Daniel 2012-03-16 14:02:53 -04:00
parent 5156f8067e
commit 8a34023336
2 changed files with 44 additions and 17 deletions

View File

@ -64,14 +64,16 @@ class Application_Model_Schedule {
$utcTimeNow = $date->getUtcTimestamp();
$shows = Application_Model_Show::getPrevCurrentNext($utcTimeNow);
$previousShowID = count($shows['previousShow'])>0?$shows['previousShow'][0]['id']:null;
$currentShowID = count($shows['currentShow'])>0?$shows['currentShow'][0]['id']:null;
$results = Application_Model_Schedule::GetPrevCurrentNext($currentShowID, $utcTimeNow);
$nextShowID = count($shows['nextShow'])>0?$shows['nextShow'][0]['id']:null;
$results = Application_Model_Schedule::GetPrevCurrentNext($previousShowID, $currentShowID, $nextShowID, $utcTimeNow);
$range = array("env"=>APPLICATION_ENV,
"schedulerTime"=>$timeNow,
"previous"=>isset($results['previous'])?$results['previous']:(count($shows['previousShow'])>0?$shows['previousShow'][0]:null),
"current"=>isset($results['current'])?$results['current']:null,
"next"=> isset($results['next'])?$results['next']:(count($shows['nextShow'])>0?$shows['nextShow'][0]:null),
"previous"=>$results['previous'] !=null?$results['previous']:(count($shows['previousShow'])>0?$shows['previousShow'][0]:null),
"current"=>$results['current'] !=null?$results['current']:null,
"next"=> $results['next'] !=null?$results['next']:(count($shows['nextShow'])>0?$shows['nextShow'][0]:null),
"currentShow"=>$shows['currentShow'],
"nextShow"=>$shows['nextShow'],
"timezone"=> date("T"),
@ -88,19 +90,36 @@ class Application_Model_Schedule {
* show types are not found through this mechanism a call is made to the old way of querying
* the database to find the track info.
**/
public static function GetPrevCurrentNext($p_currentShowID, $p_timeNow)
public static function GetPrevCurrentNext($p_previousShowID, $p_currentShowID, $p_nextShowID, $p_timeNow)
{
global $CC_CONFIG, $CC_DBC;
if (!isset($p_currentShowID)) {
return array();
}
$sql = "Select ft.artist_name, ft.track_title, st.starts as starts, st.ends as ends, st.media_item_played as media_item_played
$sql = 'Select ft.artist_name, ft.track_title, st.starts as starts, st.ends as ends, st.media_item_played as media_item_played
FROM cc_schedule st LEFT JOIN cc_files ft ON st.file_id = ft.id
WHERE st.instance_id = '$p_currentShowID' AND st.playout_status > 0
ORDER BY st.starts";
WHERE ';
if (isset($p_previousShowID)){
if (isset($p_nextShowID) || isset($p_currentShowID))
$sql .= '(';
$sql .= 'st.instance_id = '.$p_previousShowID;
}
if ($p_currentShowID != null){
if ($p_previousShowID != null)
$sql .= ' OR ';
else if($p_nextShowID != null)
$sql .= '(';
$sql .= 'st.instance_id = '.$p_currentShowID;
}
if ($p_nextShowID != null) {
if ($p_previousShowID != null || $p_currentShowID != null)
$sql .= ' OR ';
$sql .= 'st.instance_id = '.$p_nextShowID;
if($p_previousShowID != null || $p_currentShowID != null)
$sql .= ')';
} else if($p_previousShowID != null && $p_currentShowID != null)
$sql .= ')';
$sql .= ' AND st.playout_status > 0 ORDER BY st.starts';
//Logging::log($sql);
$rows = $CC_DBC->GetAll($sql);
$numberOfRows = count($rows);

View File

@ -1762,7 +1762,9 @@ class Application_Model_Show {
//Find the show that is within the current time.
if ((strtotime($rows[$i]['starts']) <= $timeNowAsMillis) && (strtotime($rows[$i]['ends']) >= $timeNowAsMillis)){
if ( $i - 1 >= 0){
$results['previousShow'][0] = array("name"=>$rows[$i-1]['name'],
$results['previousShow'][0] = array(
"id"=>$rows[$i-1]['id'],
"name"=>$rows[$i-1]['name'],
"start_timestamp"=>$rows[$i-1]['start_timestamp'],
"end_timestamp"=>$rows[$i-1]['end_timestamp'],
"starts"=>$rows[$i-1]['starts'],
@ -1772,7 +1774,9 @@ class Application_Model_Show {
$results['currentShow'][0] = $rows[$i];
if ( isset($rows[$i+1])){
$results['nextShow'][0] = array("name"=>$rows[$i+1]['name'],
$results['nextShow'][0] = array(
"id"=>$rows[$i+1]['id'],
"name"=>$rows[$i+1]['name'],
"start_timestamp"=>$rows[$i+1]['start_timestamp'],
"end_timestamp"=>$rows[$i+1]['end_timestamp'],
"starts"=>$rows[$i+1]['starts'],
@ -1787,7 +1791,9 @@ class Application_Model_Show {
}
//if we hit this we know we've gone to far and can stop looping.
if (strtotime($rows[$i]['starts']) > $timeNowAsMillis) {
$results['nextShow'][0] = array("name"=>$rows[$i]['name'],
$results['nextShow'][0] = array(
"id"=>$rows[$i]['id'],
"name"=>$rows[$i]['name'],
"start_timestamp"=>$rows[$i]['start_timestamp'],
"end_timestamp"=>$rows[$i]['end_timestamp'],
"starts"=>$rows[$i]['starts'],
@ -1798,7 +1804,9 @@ class Application_Model_Show {
//If we didn't find a a current show because the time didn't fit we may still have
//found a previous show so use it.
if (count($results['previousShow']) == 0 && isset($previousShowIndex)) {
$results['previousShow'][0] = array("name"=>$rows[$previousShowIndex]['name'],
$results['previousShow'][0] = array(
"id"=>$rows[$previousShowIndex]['id'],
"name"=>$rows[$previousShowIndex]['name'],
"start_timestamp"=>$rows[$previousShowIndex]['start_timestamp'],
"end_timestamp"=>$rows[$previousShowIndex]['end_timestamp'],
"starts"=>$rows[$previousShowIndex]['starts'],