CC-3404: Change "Now Playing" dashboard SQL query to take advantage of the "playout_status" field in the schedule table
- Updated the logic in GetPlayOrderRange now I get the previous, current and next shows and tracks to be played. - This information is then sent back to the caller. - if the previous track is null the previous show is sent back as an example of the algorithm.
This commit is contained in:
parent
09b5d9003b
commit
cbaeda1d6b
|
@ -23,7 +23,7 @@ class Logging {
|
|||
}
|
||||
|
||||
public static function debug($p_msg){
|
||||
if (APPLICATION_ENV == "development"){
|
||||
if (defined('APPLICATION_ENV') && APPLICATION_ENV == "development"){
|
||||
$logger = self::getLogger();
|
||||
$logger->debug($p_msg);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@ class Application_Model_Schedule {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns data related to the scheduled items.
|
||||
*
|
||||
|
@ -60,24 +59,91 @@ class Application_Model_Schedule {
|
|||
return array();
|
||||
}
|
||||
|
||||
global $CC_CONFIG;
|
||||
|
||||
$date = new Application_Model_DateHelper;
|
||||
$timeNow = $date->getTimestamp();
|
||||
$utcTimeNow = $date->getUtcTimestamp();
|
||||
|
||||
$shows = Application_Model_Show::getPrevCurrentNext($utcTimeNow);
|
||||
$currentShowID = count($shows['currentShow'])>0?$shows['currentShow'][0]['id']:null;
|
||||
$results = Application_Model_Schedule::GetPrevCurrentNext($currentShowID, $utcTimeNow);
|
||||
|
||||
$range = array("env"=>APPLICATION_ENV,
|
||||
"schedulerTime"=>$timeNow,
|
||||
"previous"=>Application_Model_Dashboard::GetPreviousItem($utcTimeNow),
|
||||
"current"=>Application_Model_Dashboard::GetCurrentItem($utcTimeNow),
|
||||
"next"=>Application_Model_Dashboard::GetNextItem($utcTimeNow),
|
||||
"currentShow"=>Application_Model_Show::GetCurrentShow($utcTimeNow),
|
||||
"nextShow"=>Application_Model_Show::GetNextShows($utcTimeNow, 1),
|
||||
"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,
|
||||
"currentShow"=>$shows['currentShow'],
|
||||
"nextShow"=>$shows['nextShow'],
|
||||
"timezone"=> date("T"),
|
||||
"timezoneOffset"=> date("Z"));
|
||||
|
||||
return $range;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Queries the database for the set of schedules one hour before and after the given time.
|
||||
* If a show starts and ends within that time that is considered the current show. Then the
|
||||
* scheduled item before it is the previous show, and the scheduled item after it is the next
|
||||
* show. This way the dashboard getCurrentPlaylist is very fast. But if any one of the three
|
||||
* 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)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
if (!isset($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
|
||||
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;
|
||||
|
||||
$timeNowAsMillis = strtotime($p_timeNow);
|
||||
for( $i = 0; $i < $numberOfRows; ++$i ){
|
||||
if ((strtotime($rows[$i]['starts']) <= $timeNowAsMillis) && (strtotime($rows[$i]['ends']) >= $timeNowAsMillis)){
|
||||
if ( $i - 1 >= 0){
|
||||
$results['previous'] = array("name"=>$rows[$i-1]["artist_name"]." - ".$rows[$i-1]["track_title"],
|
||||
"starts"=>$rows[$i-1]["starts"],
|
||||
"ends"=>$rows[$i-1]["ends"]);
|
||||
}
|
||||
$results['current'] = array("name"=>$rows[$i]["artist_name"]." - ".$rows[$i]["track_title"],
|
||||
"starts"=>$rows[$i]["starts"],
|
||||
"ends"=>$rows[$i]["ends"],
|
||||
"media_item_played"=>$rows[$i]["media_item_played"],
|
||||
"record"=>0);
|
||||
if ( isset($rows[$i+1])){
|
||||
$results['next'] = array("name"=>$rows[$i+1]["artist_name"]." - ".$rows[$i+1]["track_title"],
|
||||
"starts"=>$rows[$i+1]["starts"],
|
||||
"ends"=>$rows[$i+1]["ends"]);
|
||||
}
|
||||
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"]);;
|
||||
}
|
||||
if (strtotime($rows[$i]['starts']) > $timeNowAsMillis) {
|
||||
$results['next'] = array("name"=>$rows[$i]["artist_name"]." - ".$rows[$i]["track_title"],
|
||||
"starts"=>$rows[$i]["starts"],
|
||||
"ends"=>$rows[$i]["ends"]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public static function GetLastScheduleItem($p_timeNow){
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
|
|
|
@ -1680,6 +1680,71 @@ class Application_Model_Show {
|
|||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
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";
|
||||
|
||||
//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);
|
||||
for( $i = 0; $i < $numberOfRows; ++$i ){
|
||||
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'],
|
||||
"end_timestamp"=>$rows[$i-1]['end_timestamp'],
|
||||
"starts"=>$rows[$i-1]['starts'],
|
||||
"ends"=>$rows[$i-1]['ends']);
|
||||
}
|
||||
|
||||
$results['currentShow'][0] = $rows[$i];
|
||||
|
||||
if ( isset($rows[$i+1])){
|
||||
$results['nextShow'][0] = array("name"=>$rows[$i+1]['name'],
|
||||
"start_timestamp"=>$rows[$i+1]['start_timestamp'],
|
||||
"end_timestamp"=>$rows[$i+1]['end_timestamp'],
|
||||
"starts"=>$rows[$i+1]['starts'],
|
||||
"ends"=>$rows[$i+1]['ends']);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
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']);
|
||||
}
|
||||
if (strtotime($rows[$i]['starts']) > $timeNowAsMillis) {
|
||||
$results['nextShow'][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']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
/**
|
||||
* Given a start time $timeStart and end time $timeEnd, returns the next $limit
|
||||
* number of shows within the time interval;
|
||||
|
|
Loading…
Reference in New Issue