CC-3404: Change "Now Playing" dashboard SQL query to take advantage of the "playout_status" field in the schedule table

- updated the code to remove the empty declaration of $results
- updated parameters so the name has p_ prepended to it
- fixed a weird bug where $con was not sent to updateScheduleStatus
- modified previous element logic so I only store the index and after the loop test if it was set and then do the formating.
This commit is contained in:
Daniel 2012-03-13 17:46:13 -04:00
parent 0b82107d28
commit a65ea6d058
2 changed files with 39 additions and 25 deletions

View File

@ -48,13 +48,13 @@ class Application_Model_Schedule {
/**
* Returns data related to the scheduled items.
*
* @param int $prev
* @param int $next
* @param int $p_prev
* @param int $p_next
* @return date
*/
public static function GetPlayOrderRange($prev = 1, $next = 1)
public static function GetPlayOrderRange($p_prev = 1, $p_next = 1)
{
if (!is_int($prev) || !is_int($next)){
if (!is_int($p_prev) || !is_int($p_next)){
//must enter integers to specify ranges
return array();
}
@ -88,22 +88,22 @@ 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($currentShowID, $p_timeNow)
public static function GetPrevCurrentNext($p_currentShowID, $p_timeNow)
{
global $CC_CONFIG, $CC_DBC;
if (!isset($currentShowID)) {
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
FROM cc_schedule st LEFT JOIN cc_files ft ON st.file_id = ft.id
WHERE st.instance_id = '$currentShowID' AND st.playout_status > 0
WHERE st.instance_id = '$p_currentShowID' AND st.playout_status > 0
ORDER BY st.starts";
//Logging::log($sql);
$rows = $CC_DBC->GetAll($sql);
$numberOfRows = count($rows);
$results;
$results['previous'] = null;
$results['current'] = null;
$results['next'] = null;
@ -130,9 +130,7 @@ class Application_Model_Schedule {
break;
}
if (strtotime($rows[$i]['ends']) < $timeNowAsMillis ) {
$results['previous'] = array("name"=>$rows[$i]["artist_name"]." - ".$rows[$i]["track_title"],
"starts"=>$rows[$i]["starts"],
"ends"=>$rows[$i]["ends"]);;
$previousIndex = $i;
}
if (strtotime($rows[$i]['starts']) > $timeNowAsMillis) {
$results['next'] = array("name"=>$rows[$i]["artist_name"]." - ".$rows[$i]["track_title"],
@ -141,6 +139,13 @@ class Application_Model_Schedule {
break;
}
}
//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 ($results['previous'] === null && isset($previousIndex)) {
$results['previous'] = array("name"=>$rows[$previousIndex]["artist_name"]." - ".$rows[$previousIndex]["track_title"],
"starts"=>$rows[$previousIndex]["starts"],
"ends"=>$rows[$previousIndex]["ends"]);;
}
return $results;
}

View File

@ -1082,7 +1082,7 @@ class Application_Model_Show {
->find($con);
foreach ($instances as $instance) {
$instance->updateScheduleStatus();
$instance->updateScheduleStatus($con);
}
$con->commit();
@ -1696,29 +1696,32 @@ class Application_Model_Show {
/**
* Gets the current show, previous and next with an 2day window from the given timeNow, so timeNow-2days and timeNow+2days.
*/
public static function getPrevCurrentNext($timeNow)
public static function getPrevCurrentNext($p_timeNow)
{
global $CC_CONFIG, $CC_DBC;
//TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin
$sql = "SELECT si.starts as start_timestamp, si.ends as end_timestamp, s.name, s.id, si.id as instance_id, si.record, s.url, starts, ends"
." FROM $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s"
." WHERE si.show_id = s.id"
." AND si.starts > TIMESTAMP '$timeNow' - INTERVAL '2 days'"
." AND si.ends < TIMESTAMP '$timeNow' + INTERVAL '2 days'"
." AND modified_instance != TRUE";
." AND si.starts > TIMESTAMP '$p_timeNow' - INTERVAL '2 days'"
." AND si.ends < TIMESTAMP '$p_timeNow' + INTERVAL '2 days'"
." AND modified_instance != TRUE"
." ORDER BY si.starts";
//Logging::log($sql);
// Convert back to local timezone
$rows = $CC_DBC->GetAll($sql);
$numberOfRows = count($rows);
$results;
$results['previousShow'] = array();
$results['currentShow'] = array();
$results['nextShow'] = array();
$timeNowAsMillis = strtotime($timeNow);
$timeNowAsMillis = strtotime($p_timeNow);
for( $i = 0; $i < $numberOfRows; ++$i ){
if ((strtotime($rows[$i]['starts']) <= $timeNowAsMillis) && (strtotime($rows[$i]['ends']) >= $timeNowAsMillis)){
//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'],
"start_timestamp"=>$rows[$i-1]['start_timestamp'],
@ -1739,13 +1742,11 @@ class Application_Model_Show {
}
break;
}
//Previous is any row that ends after time now capture it in case we need it later.
if (strtotime($rows[$i]['ends']) < $timeNowAsMillis ) {
$results['previousShow'][0] = array("name"=>$rows[$i]['name'],
"start_timestamp"=>$rows[$i]['start_timestamp'],
"end_timestamp"=>$rows[$i]['end_timestamp'],
"starts"=>$rows[$i]['starts'],
"ends"=>$rows[$i]['ends']);
$previousShowIndex = $i;
}
//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'],
"start_timestamp"=>$rows[$i]['start_timestamp'],
@ -1755,7 +1756,15 @@ class Application_Model_Show {
break;
}
}
//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'],
"start_timestamp"=>$rows[$previousShowIndex]['start_timestamp'],
"end_timestamp"=>$rows[$previousShowIndex]['end_timestamp'],
"starts"=>$rows[$previousShowIndex]['starts'],
"ends"=>$rows[$previousShowIndex]['ends']);
}
return $results;
}
/**