2010-12-07 20:19:27 +01:00
|
|
|
<?php
|
|
|
|
|
2011-09-23 22:50:00 +02:00
|
|
|
class Application_Model_Schedule {
|
2010-12-07 23:29:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if there is nothing in the schedule for the given start time
|
|
|
|
* up to the length of time after that.
|
|
|
|
*
|
|
|
|
* @param string $p_datetime
|
|
|
|
* In the format YYYY-MM-DD HH:MM:SS.mmmmmm
|
|
|
|
* @param string $p_length
|
|
|
|
* In the format HH:MM:SS.mmmmmm
|
|
|
|
* @return boolean|PEAR_Error
|
|
|
|
*/
|
|
|
|
public static function isScheduleEmptyInRange($p_datetime, $p_length) {
|
|
|
|
global $CC_CONFIG, $CC_DBC;
|
|
|
|
if (empty($p_length)) {
|
2011-09-23 22:50:00 +02:00
|
|
|
return new PEAR_Error("Application_Model_Schedule::isSchedulerEmptyInRange: param p_length is empty.");
|
2010-12-07 23:29:28 +01:00
|
|
|
}
|
|
|
|
$sql = "SELECT COUNT(*) FROM ".$CC_CONFIG["scheduleTable"]
|
|
|
|
." WHERE (starts >= '$p_datetime') "
|
|
|
|
." AND (ends <= (TIMESTAMP '$p_datetime' + INTERVAL '$p_length'))";
|
|
|
|
//$_SESSION["debug"] = $sql;
|
2010-12-17 00:24:37 +01:00
|
|
|
//echo $sql;
|
2010-12-07 23:29:28 +01:00
|
|
|
$count = $CC_DBC->GetOne($sql);
|
|
|
|
//var_dump($count);
|
|
|
|
return ($count == '0');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return TRUE if file is going to be played in the future.
|
|
|
|
*
|
|
|
|
* @param string $p_fileId
|
|
|
|
*/
|
|
|
|
public function IsFileScheduledInTheFuture($p_fileId)
|
|
|
|
{
|
|
|
|
global $CC_CONFIG, $CC_DBC;
|
|
|
|
$sql = "SELECT COUNT(*) FROM ".$CC_CONFIG["scheduleTable"]
|
|
|
|
." WHERE file_id = {$p_fileId} AND starts > NOW()";
|
|
|
|
$count = $CC_DBC->GetOne($sql);
|
|
|
|
if (is_numeric($count) && ($count != '0')) {
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
2010-12-07 23:29:28 +01:00
|
|
|
|
2010-12-22 00:28:17 +01:00
|
|
|
/**
|
2011-02-03 00:25:42 +01:00
|
|
|
* Returns data related to the scheduled items.
|
2010-12-22 00:28:17 +01:00
|
|
|
*
|
2012-03-13 22:46:13 +01:00
|
|
|
* @param int $p_prev
|
|
|
|
* @param int $p_next
|
2010-12-22 00:28:17 +01:00
|
|
|
* @return date
|
|
|
|
*/
|
2012-03-13 22:46:13 +01:00
|
|
|
public static function GetPlayOrderRange($p_prev = 1, $p_next = 1)
|
2011-03-22 14:55:33 +01:00
|
|
|
{
|
2012-03-13 22:46:13 +01:00
|
|
|
if (!is_int($p_prev) || !is_int($p_next)){
|
2010-12-22 00:28:17 +01:00
|
|
|
//must enter integers to specify ranges
|
2011-02-07 06:26:16 +01:00
|
|
|
return array();
|
2010-12-22 00:28:17 +01:00
|
|
|
}
|
2010-12-07 23:29:28 +01:00
|
|
|
|
2011-09-26 21:29:12 +02:00
|
|
|
$date = new Application_Model_DateHelper;
|
2011-11-12 06:04:37 +01:00
|
|
|
$timeNow = $date->getTimestamp();
|
2011-11-15 21:45:08 +01:00
|
|
|
$utcTimeNow = $date->getUtcTimestamp();
|
2012-03-13 15:21:01 +01:00
|
|
|
|
|
|
|
$shows = Application_Model_Show::getPrevCurrentNext($utcTimeNow);
|
2012-03-16 19:02:53 +01:00
|
|
|
$previousShowID = count($shows['previousShow'])>0?$shows['previousShow'][0]['id']:null;
|
2012-03-13 15:21:01 +01:00
|
|
|
$currentShowID = count($shows['currentShow'])>0?$shows['currentShow'][0]['id']:null;
|
2012-03-16 19:02:53 +01:00
|
|
|
$nextShowID = count($shows['nextShow'])>0?$shows['nextShow'][0]['id']:null;
|
|
|
|
$results = Application_Model_Schedule::GetPrevCurrentNext($previousShowID, $currentShowID, $nextShowID, $utcTimeNow);
|
2012-03-13 15:21:01 +01:00
|
|
|
|
2011-11-15 21:45:08 +01:00
|
|
|
$range = array("env"=>APPLICATION_ENV,
|
2011-08-15 22:40:24 +02:00
|
|
|
"schedulerTime"=>$timeNow,
|
2012-03-16 19:02:53 +01:00
|
|
|
"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),
|
2012-03-13 15:21:01 +01:00
|
|
|
"currentShow"=>$shows['currentShow'],
|
|
|
|
"nextShow"=>$shows['nextShow'],
|
2011-01-31 22:34:08 +01:00
|
|
|
"timezone"=> date("T"),
|
2011-07-12 20:09:40 +02:00
|
|
|
"timezoneOffset"=> date("Z"));
|
2012-03-13 16:31:24 +01:00
|
|
|
|
2011-11-15 21:45:08 +01:00
|
|
|
return $range;
|
2010-12-07 23:29:28 +01:00
|
|
|
}
|
2012-03-13 15:21:01 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
**/
|
2012-03-16 19:02:53 +01:00
|
|
|
public static function GetPrevCurrentNext($p_previousShowID, $p_currentShowID, $p_nextShowID, $p_timeNow)
|
2012-03-13 15:21:01 +01:00
|
|
|
{
|
2012-03-16 22:13:32 +01:00
|
|
|
if ($p_previousShowID == null && $p_currentShowID == null && $p_nextShowID == null)
|
|
|
|
return;
|
|
|
|
|
2012-03-13 15:21:01 +01:00
|
|
|
global $CC_CONFIG, $CC_DBC;
|
2012-03-16 19:02:53 +01:00
|
|
|
$sql = 'Select ft.artist_name, ft.track_title, st.starts as starts, st.ends as ends, st.media_item_played as media_item_played
|
2012-03-13 15:21:01 +01:00
|
|
|
FROM cc_schedule st LEFT JOIN cc_files ft ON st.file_id = ft.id
|
2012-03-16 19:02:53 +01:00
|
|
|
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';
|
2012-03-13 15:21:01 +01:00
|
|
|
|
|
|
|
$rows = $CC_DBC->GetAll($sql);
|
|
|
|
$numberOfRows = count($rows);
|
2012-03-13 22:46:13 +01:00
|
|
|
|
2012-03-13 15:21:01 +01:00
|
|
|
$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);
|
2012-03-13 16:31:24 +01:00
|
|
|
|
2012-03-13 15:21:01 +01:00
|
|
|
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 ) {
|
2012-03-13 22:46:13 +01:00
|
|
|
$previousIndex = $i;
|
2012-03-13 15:21:01 +01:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2012-03-13 22:46:13 +01:00
|
|
|
//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"]);;
|
|
|
|
}
|
2012-03-13 15:21:01 +01:00
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
2011-05-11 01:06:35 +02:00
|
|
|
public static function GetLastScheduleItem($p_timeNow){
|
|
|
|
global $CC_CONFIG, $CC_DBC;
|
|
|
|
|
2011-06-29 20:40:56 +02:00
|
|
|
$sql = "SELECT"
|
|
|
|
." ft.artist_name, ft.track_title,"
|
|
|
|
." st.starts as starts, st.ends as ends"
|
2011-05-11 01:06:35 +02:00
|
|
|
." FROM $CC_CONFIG[scheduleTable] st"
|
|
|
|
." LEFT JOIN $CC_CONFIG[filesTable] ft"
|
|
|
|
." ON st.file_id = ft.id"
|
2011-06-29 20:40:56 +02:00
|
|
|
." LEFT JOIN $CC_CONFIG[showInstances] sit"
|
|
|
|
." ON st.instance_id = sit.id"
|
2011-05-11 01:06:35 +02:00
|
|
|
." WHERE st.ends < TIMESTAMP '$p_timeNow'"
|
2011-06-29 20:40:56 +02:00
|
|
|
." AND st.starts >= sit.starts" //this and the next line are necessary since we can overbook shows.
|
|
|
|
." AND st.starts < sit.ends"
|
2011-05-11 01:06:35 +02:00
|
|
|
." ORDER BY st.ends DESC"
|
|
|
|
." LIMIT 1";
|
|
|
|
|
|
|
|
$row = $CC_DBC->GetAll($sql);
|
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-03 22:36:13 +02:00
|
|
|
public static function GetCurrentScheduleItem($p_timeNow, $p_instanceId){
|
2011-05-11 01:06:35 +02:00
|
|
|
global $CC_CONFIG, $CC_DBC;
|
|
|
|
|
2011-06-02 18:45:57 +02:00
|
|
|
/* Note that usually there will be one result returned. In some
|
|
|
|
* rare cases two songs are returned. This happens when a track
|
|
|
|
* that was overbooked from a previous show appears as if it
|
|
|
|
* hasnt ended yet (track end time hasn't been reached yet). For
|
|
|
|
* this reason, we need to get the track that starts later, as
|
|
|
|
* this is the *real* track that is currently playing. So this
|
|
|
|
* is why we are ordering by track start time. */
|
2011-05-11 01:06:35 +02:00
|
|
|
$sql = "SELECT *"
|
|
|
|
." FROM $CC_CONFIG[scheduleTable] st"
|
|
|
|
." LEFT JOIN $CC_CONFIG[filesTable] ft"
|
|
|
|
." ON st.file_id = ft.id"
|
|
|
|
." WHERE st.starts <= TIMESTAMP '$p_timeNow'"
|
2011-06-03 22:36:13 +02:00
|
|
|
." AND st.instance_id = $p_instanceId"
|
2011-05-11 01:06:35 +02:00
|
|
|
." AND st.ends > TIMESTAMP '$p_timeNow'"
|
2011-06-02 18:45:57 +02:00
|
|
|
." ORDER BY st.starts DESC"
|
2011-05-11 01:06:35 +02:00
|
|
|
." LIMIT 1";
|
|
|
|
|
|
|
|
$row = $CC_DBC->GetAll($sql);
|
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function GetNextScheduleItem($p_timeNow){
|
|
|
|
global $CC_CONFIG, $CC_DBC;
|
|
|
|
|
2011-06-29 20:40:56 +02:00
|
|
|
$sql = "SELECT"
|
|
|
|
." ft.artist_name, ft.track_title,"
|
|
|
|
." st.starts as starts, st.ends as ends"
|
2011-05-11 01:06:35 +02:00
|
|
|
." FROM $CC_CONFIG[scheduleTable] st"
|
|
|
|
." LEFT JOIN $CC_CONFIG[filesTable] ft"
|
|
|
|
." ON st.file_id = ft.id"
|
2011-06-29 20:40:56 +02:00
|
|
|
." LEFT JOIN $CC_CONFIG[showInstances] sit"
|
|
|
|
." ON st.instance_id = sit.id"
|
2011-05-11 01:06:35 +02:00
|
|
|
." WHERE st.starts > TIMESTAMP '$p_timeNow'"
|
2011-06-29 20:40:56 +02:00
|
|
|
." AND st.starts >= sit.starts" //this and the next line are necessary since we can overbook shows.
|
|
|
|
." AND st.starts < sit.ends"
|
2011-05-11 01:06:35 +02:00
|
|
|
." ORDER BY st.starts"
|
|
|
|
." LIMIT 1";
|
|
|
|
|
|
|
|
$row = $CC_DBC->GetAll($sql);
|
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
|
2011-02-03 00:25:42 +01:00
|
|
|
/**
|
|
|
|
* Builds an SQL Query for accessing scheduled item information from
|
2011-02-22 18:22:31 +01:00
|
|
|
* the database.
|
2011-02-03 00:25:42 +01:00
|
|
|
*
|
|
|
|
* @param int $timeNow
|
|
|
|
* @param int $timePeriod
|
|
|
|
* @param int $count
|
|
|
|
* @param String $interval
|
|
|
|
* @return date
|
2011-02-22 18:22:31 +01:00
|
|
|
*
|
|
|
|
* $timeNow is the the currentTime in the format "Y-m-d H:i:s".
|
2011-02-03 00:25:42 +01:00
|
|
|
* For example: 2011-02-02 22:00:54
|
2011-02-22 18:22:31 +01:00
|
|
|
*
|
2011-02-03 00:25:42 +01:00
|
|
|
* $timePeriod can be either negative, zero or positive. This is used
|
|
|
|
* to indicate whether we want items from the past, present or future.
|
2011-02-22 18:22:31 +01:00
|
|
|
*
|
2011-02-03 00:25:42 +01:00
|
|
|
* $count indicates how many results we want to limit ourselves to.
|
2011-02-22 18:22:31 +01:00
|
|
|
*
|
2011-02-03 00:25:42 +01:00
|
|
|
* $interval is used to indicate how far into the past or future we
|
|
|
|
* want to search the database. For example "5 days", "18 hours", "60 minutes",
|
|
|
|
* "30 seconds" etc.
|
|
|
|
*/
|
2011-03-22 14:55:33 +01:00
|
|
|
public static function GetScheduledItemData($timeStamp, $timePeriod=0, $count = 0, $interval="0 hours")
|
|
|
|
{
|
2011-02-03 00:25:42 +01:00
|
|
|
global $CC_CONFIG, $CC_DBC;
|
2011-02-22 18:22:31 +01:00
|
|
|
|
2011-03-29 00:07:16 +02:00
|
|
|
$sql = "SELECT DISTINCT"
|
|
|
|
." pt.name,"
|
|
|
|
." ft.track_title,"
|
|
|
|
." ft.artist_name,"
|
|
|
|
." ft.album_title,"
|
|
|
|
." st.starts,"
|
|
|
|
." st.ends,"
|
|
|
|
." st.clip_length,"
|
|
|
|
." st.media_item_played,"
|
|
|
|
." st.group_id,"
|
|
|
|
." show.name as show_name,"
|
|
|
|
." st.instance_id"
|
|
|
|
." FROM $CC_CONFIG[scheduleTable] st"
|
|
|
|
." LEFT JOIN $CC_CONFIG[filesTable] ft"
|
|
|
|
." ON st.file_id = ft.id"
|
|
|
|
." LEFT JOIN $CC_CONFIG[playListTable] pt"
|
|
|
|
." ON st.playlist_id = pt.id"
|
|
|
|
." LEFT JOIN $CC_CONFIG[showInstances] si"
|
|
|
|
." ON st.instance_id = si.id"
|
|
|
|
." LEFT JOIN $CC_CONFIG[showTable] show"
|
|
|
|
." ON si.show_id = show.id"
|
|
|
|
." WHERE st.starts < si.ends";
|
|
|
|
|
2011-02-03 00:25:42 +01:00
|
|
|
if ($timePeriod < 0){
|
2012-02-17 22:47:12 +01:00
|
|
|
$sql .= " AND st.ends < TIMESTAMP '$timeStamp'"
|
|
|
|
." AND st.ends > (TIMESTAMP '$timeStamp' - INTERVAL '$interval')"
|
|
|
|
." ORDER BY st.starts DESC"
|
|
|
|
." LIMIT $count";
|
|
|
|
} else if ($timePeriod == 0){
|
|
|
|
$sql .= " AND st.starts <= TIMESTAMP '$timeStamp'"
|
|
|
|
." AND st.ends >= TIMESTAMP '$timeStamp'";
|
|
|
|
} else if ($timePeriod > 0){
|
|
|
|
$sql .= " AND st.starts > TIMESTAMP '$timeStamp'"
|
|
|
|
." AND st.starts < (TIMESTAMP '$timeStamp' + INTERVAL '$interval')"
|
|
|
|
." ORDER BY st.starts"
|
|
|
|
." LIMIT $count";
|
|
|
|
}
|
2011-02-05 00:22:15 +01:00
|
|
|
|
2011-02-03 00:25:42 +01:00
|
|
|
$rows = $CC_DBC->GetAll($sql);
|
|
|
|
return $rows;
|
2012-02-17 22:47:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-02 22:32:16 +01:00
|
|
|
public static function getScheduleItemsInRange($starts, $ends)
|
2012-02-17 22:47:12 +01:00
|
|
|
{
|
|
|
|
global $CC_DBC, $CC_CONFIG;
|
2011-02-22 18:22:31 +01:00
|
|
|
|
2012-02-17 22:47:12 +01:00
|
|
|
$sql = "SELECT"
|
|
|
|
." si.starts as show_starts,"
|
|
|
|
." si.ends as show_ends,"
|
|
|
|
." si.rebroadcast as rebroadcast,"
|
|
|
|
." 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"
|
2012-02-17 23:08:47 +01:00
|
|
|
." LEFT JOIN ".$CC_CONFIG["scheduleTable"]." st"
|
2012-02-17 22:47:12 +01:00
|
|
|
." ON st.instance_id = si.id"
|
2012-02-17 23:08:47 +01:00
|
|
|
." LEFT JOIN ".$CC_CONFIG["playListTable"]." pt"
|
2012-02-17 22:47:12 +01:00
|
|
|
." ON st.playlist_id = pt.id"
|
2012-02-17 23:08:47 +01:00
|
|
|
." LEFT JOIN ".$CC_CONFIG["filesTable"]." ft"
|
2012-02-17 22:47:12 +01:00
|
|
|
." ON st.file_id = ft.id"
|
2012-02-17 23:08:47 +01:00
|
|
|
." LEFT JOIN ".$CC_CONFIG["showTable"]." s"
|
2012-02-17 22:47:12 +01:00
|
|
|
." ON si.show_id = s.id"
|
2012-03-02 22:32:16 +01:00
|
|
|
." WHERE ((si.starts < TIMESTAMP '$starts' AND si.ends > TIMESTAMP '$starts')"
|
|
|
|
." OR (si.starts > TIMESTAMP '$starts' AND si.ends < TIMESTAMP '$ends')"
|
|
|
|
." OR (si.starts < TIMESTAMP '$ends' AND si.ends > TIMESTAMP '$ends'))"
|
2012-02-17 22:47:12 +01:00
|
|
|
." AND (st.starts < si.ends)"
|
|
|
|
." ORDER BY si.id, si.starts, st.starts";
|
|
|
|
|
|
|
|
return $CC_DBC->GetAll($sql);
|
2012-03-12 22:52:17 +01:00
|
|
|
}
|
2011-02-22 18:22:31 +01:00
|
|
|
|
2012-01-23 19:07:07 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* @param DateTime $p_startDateTime
|
|
|
|
*
|
|
|
|
* @param DateTime $p_endDateTime
|
|
|
|
*
|
|
|
|
* @return array $scheduledItems
|
|
|
|
*
|
|
|
|
*/
|
2012-03-02 14:01:02 +01:00
|
|
|
public static function GetScheduleDetailItems($p_start, $p_end, $p_shows)
|
2012-01-23 19:07:07 +01:00
|
|
|
{
|
|
|
|
global $CC_CONFIG, $CC_DBC;
|
|
|
|
|
|
|
|
$sql = "SELECT DISTINCT
|
|
|
|
|
2012-01-31 18:59:27 +01:00
|
|
|
showt.name AS show_name, showt.color AS show_color,
|
2012-03-22 18:04:22 +01:00
|
|
|
showt.background_color AS show_background_color, showt.id AS show_id,
|
2012-01-26 15:21:04 +01:00
|
|
|
|
|
|
|
si.starts AS si_starts, si.ends AS si_ends, si.time_filled AS si_time_filled,
|
2012-02-16 16:29:11 +01:00
|
|
|
si.record AS si_record, si.rebroadcast AS si_rebroadcast, si.id AS si_id, si.last_scheduled AS si_last_scheduled,
|
2012-01-26 15:21:04 +01:00
|
|
|
|
2012-01-26 19:10:37 +01:00
|
|
|
sched.starts AS sched_starts, sched.ends AS sched_ends, sched.id AS sched_id,
|
2012-02-27 21:29:02 +01:00
|
|
|
sched.cue_in AS cue_in, sched.cue_out AS cue_out,
|
|
|
|
sched.fade_in AS fade_in, sched.fade_out AS fade_out,
|
2012-03-02 12:22:08 +01:00
|
|
|
sched.playout_status AS playout_status,
|
2012-01-26 15:21:04 +01:00
|
|
|
|
|
|
|
ft.track_title AS file_track_title, ft.artist_name AS file_artist_name,
|
|
|
|
ft.album_title AS file_album_title, ft.length AS file_length
|
2012-01-23 19:07:07 +01:00
|
|
|
|
|
|
|
FROM
|
|
|
|
((cc_schedule AS sched JOIN cc_files AS ft ON (sched.file_id = ft.id)
|
|
|
|
RIGHT OUTER JOIN cc_show_instances AS si ON (si.id = sched.instance_id))
|
|
|
|
JOIN cc_show AS showt ON (showt.id = si.show_id)
|
|
|
|
)
|
|
|
|
|
2012-02-09 21:19:21 +01:00
|
|
|
WHERE si.modified_instance = false AND
|
|
|
|
|
2012-03-02 14:01:02 +01:00
|
|
|
((si.starts >= '{$p_start}' AND si.starts < '{$p_end}')
|
|
|
|
OR (si.ends > '{$p_start}' AND si.ends <= '{$p_end}')
|
|
|
|
OR (si.starts <= '{$p_start}' AND si.ends >= '{$p_end}'))";
|
|
|
|
|
|
|
|
|
2012-02-15 00:39:27 +01:00
|
|
|
if (count($p_shows) > 0) {
|
|
|
|
$sql .= " AND show_id IN (".implode(",", $p_shows).")";
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql .= " ORDER BY si.starts, sched.starts;";
|
2012-01-26 15:21:04 +01:00
|
|
|
|
2012-02-14 13:33:25 +01:00
|
|
|
Logging::log($sql);
|
2012-01-23 19:07:07 +01:00
|
|
|
|
|
|
|
$rows = $CC_DBC->GetAll($sql);
|
|
|
|
return $rows;
|
|
|
|
}
|
|
|
|
|
2011-03-22 14:55:33 +01:00
|
|
|
public static function GetShowInstanceItems($instance_id)
|
|
|
|
{
|
2011-03-05 05:53:29 +01:00
|
|
|
global $CC_CONFIG, $CC_DBC;
|
|
|
|
|
|
|
|
$sql = "SELECT DISTINCT pt.name, ft.track_title, ft.artist_name, ft.album_title, st.starts, st.ends, st.clip_length, st.media_item_played, st.group_id, show.name as show_name, st.instance_id"
|
|
|
|
." FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt, $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] show"
|
|
|
|
." WHERE st.playlist_id = pt.id"
|
|
|
|
." AND st.file_id = ft.id"
|
|
|
|
." AND st.instance_id = si.id"
|
|
|
|
." AND si.show_id = show.id"
|
|
|
|
." AND instance_id = $instance_id"
|
|
|
|
." ORDER BY st.starts";
|
|
|
|
|
|
|
|
$rows = $CC_DBC->GetAll($sql);
|
|
|
|
return $rows;
|
|
|
|
}
|
|
|
|
|
2011-03-22 14:55:33 +01:00
|
|
|
public static function UpdateMediaPlayedStatus($p_id)
|
|
|
|
{
|
2011-02-23 23:03:27 +01:00
|
|
|
global $CC_CONFIG, $CC_DBC;
|
|
|
|
$sql = "UPDATE ".$CC_CONFIG['scheduleTable']
|
|
|
|
." SET media_item_played=TRUE"
|
2011-03-22 14:55:33 +01:00
|
|
|
." WHERE id=$p_id";
|
|
|
|
$retVal = $CC_DBC->query($sql);
|
|
|
|
return $retVal;
|
2011-02-23 23:03:27 +01:00
|
|
|
}
|
2011-07-19 12:37:06 +02:00
|
|
|
|
2011-06-15 18:06:50 +02:00
|
|
|
public static function getSchduledPlaylistCount(){
|
2012-02-17 22:47:12 +01:00
|
|
|
global $CC_CONFIG, $CC_DBC;
|
2011-06-15 18:06:50 +02:00
|
|
|
$sql = "SELECT count(*) as cnt FROM ".$CC_CONFIG['scheduleTable'];
|
|
|
|
return $CC_DBC->GetOne($sql);
|
|
|
|
}
|
2011-02-23 23:03:27 +01:00
|
|
|
|
2010-12-07 23:29:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a time string in the format "YYYY-MM-DD HH:mm:SS"
|
|
|
|
* to "YYYY-MM-DD-HH-mm-SS".
|
|
|
|
*
|
|
|
|
* @param string $p_time
|
|
|
|
* @return string
|
|
|
|
*/
|
2011-03-22 14:55:33 +01:00
|
|
|
private static function AirtimeTimeToPypoTime($p_time)
|
2010-12-07 23:29:28 +01:00
|
|
|
{
|
|
|
|
$p_time = substr($p_time, 0, 19);
|
|
|
|
$p_time = str_replace(" ", "-", $p_time);
|
|
|
|
$p_time = str_replace(":", "-", $p_time);
|
|
|
|
return $p_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a time string in the format "YYYY-MM-DD-HH-mm-SS" to
|
|
|
|
* "YYYY-MM-DD HH:mm:SS".
|
|
|
|
*
|
|
|
|
* @param string $p_time
|
|
|
|
* @return string
|
|
|
|
*/
|
2011-03-22 14:55:33 +01:00
|
|
|
private static function PypoTimeToAirtimeTime($p_time)
|
2010-12-07 23:29:28 +01:00
|
|
|
{
|
|
|
|
$t = explode("-", $p_time);
|
|
|
|
return $t[0]."-".$t[1]."-".$t[2]." ".$t[3].":".$t[4].":00";
|
|
|
|
}
|
|
|
|
|
2010-12-10 00:44:47 +01:00
|
|
|
/**
|
|
|
|
* Return true if the input string is in the format YYYY-MM-DD-HH-mm
|
|
|
|
*
|
|
|
|
* @param string $p_time
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function ValidPypoTimeFormat($p_time)
|
|
|
|
{
|
|
|
|
$t = explode("-", $p_time);
|
|
|
|
if (count($t) != 5) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
foreach ($t as $part) {
|
|
|
|
if (!is_numeric($part)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-07 23:29:28 +01:00
|
|
|
/**
|
|
|
|
* Converts a time value as a string (with format HH:MM:SS.mmmmmm) to
|
|
|
|
* millisecs.
|
|
|
|
*
|
|
|
|
* @param string $p_time
|
|
|
|
* @return int
|
|
|
|
*/
|
2011-04-06 23:53:09 +02:00
|
|
|
public static function WallTimeToMillisecs($p_time)
|
2010-12-07 23:29:28 +01:00
|
|
|
{
|
|
|
|
$t = explode(":", $p_time);
|
|
|
|
$millisecs = 0;
|
|
|
|
if (strpos($t[2], ".")) {
|
|
|
|
$secParts = explode(".", $t[2]);
|
|
|
|
$millisecs = $secParts[1];
|
|
|
|
$millisecs = substr($millisecs, 0, 3);
|
|
|
|
$millisecs = intval($millisecs);
|
|
|
|
$seconds = intval($secParts[0]);
|
|
|
|
} else {
|
|
|
|
$seconds = intval($t[2]);
|
|
|
|
}
|
|
|
|
$ret = $millisecs + ($seconds * 1000) + ($t[1] * 60 * 1000) + ($t[0] * 60 * 60 * 1000);
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute the difference between two times in the format "HH:MM:SS.mmmmmm".
|
|
|
|
* Note: currently only supports calculating millisec differences.
|
|
|
|
*
|
|
|
|
* @param string $p_time1
|
|
|
|
* @param string $p_time2
|
|
|
|
* @return double
|
|
|
|
*/
|
|
|
|
private static function TimeDiff($p_time1, $p_time2)
|
|
|
|
{
|
|
|
|
$parts1 = explode(".", $p_time1);
|
|
|
|
$parts2 = explode(".", $p_time2);
|
|
|
|
$diff = 0;
|
|
|
|
if ( (count($parts1) > 1) && (count($parts2) > 1) ) {
|
|
|
|
$millisec1 = substr($parts1[1], 0, 3);
|
|
|
|
$millisec1 = str_pad($millisec1, 3, "0");
|
|
|
|
$millisec1 = intval($millisec1);
|
|
|
|
$millisec2 = substr($parts2[1], 0, 3);
|
|
|
|
$millisec2 = str_pad($millisec2, 3, "0");
|
|
|
|
$millisec2 = intval($millisec2);
|
2011-01-17 08:32:51 +01:00
|
|
|
$diff = abs($millisec1 - $millisec2)/1000;
|
2010-12-07 23:29:28 +01:00
|
|
|
}
|
|
|
|
return $diff;
|
|
|
|
}
|
2012-03-01 15:09:13 +01:00
|
|
|
|
2012-02-22 23:29:49 +01:00
|
|
|
/**
|
2012-03-06 01:02:46 +01:00
|
|
|
* Returns an array of schedule items from cc_schedule table. Tries
|
|
|
|
* to return at least 3 items (if they are available). The parameters
|
|
|
|
* $p_startTime and $p_endTime specify the range. Schedule items returned
|
|
|
|
* do not have to be entirely within this range. It is enough that the end
|
|
|
|
* or beginning of the scheduled item is in the range.
|
|
|
|
*
|
2012-02-22 23:29:49 +01:00
|
|
|
*
|
2012-03-06 01:02:46 +01:00
|
|
|
* @param string $p_startTime
|
2012-02-22 23:29:49 +01:00
|
|
|
* In the format YYYY-MM-DD HH:MM:SS.nnnnnn
|
2012-03-06 01:02:46 +01:00
|
|
|
* @param string $p_endTime
|
2012-02-22 23:29:49 +01:00
|
|
|
* In the format YYYY-MM-DD HH:MM:SS.nnnnnn
|
|
|
|
* @return array
|
2012-03-06 01:02:46 +01:00
|
|
|
* Returns null if nothing found, else an array of associative
|
|
|
|
* arrays representing each row.
|
2012-02-22 23:29:49 +01:00
|
|
|
*/
|
2012-03-06 01:02:46 +01:00
|
|
|
public static function GetItems($p_startTime, $p_endTime) {
|
2012-02-22 23:29:49 +01:00
|
|
|
global $CC_CONFIG, $CC_DBC;
|
2012-03-01 23:58:44 +01:00
|
|
|
|
|
|
|
$baseQuery = "SELECT st.file_id AS file_id,"
|
|
|
|
." st.id as id,"
|
|
|
|
." st.starts AS start,"
|
|
|
|
." st.ends AS end,"
|
|
|
|
." st.cue_in AS cue_in,"
|
|
|
|
." st.cue_out AS cue_out,"
|
|
|
|
." st.fade_in AS fade_in,"
|
|
|
|
." st.fade_out AS fade_out,"
|
|
|
|
." si.starts as show_start,"
|
|
|
|
." si.ends as show_end"
|
|
|
|
." FROM $CC_CONFIG[scheduleTable] as st"
|
|
|
|
." LEFT JOIN $CC_CONFIG[showInstances] as si"
|
|
|
|
." ON st.instance_id = si.id";
|
|
|
|
|
|
|
|
|
2012-03-06 01:02:46 +01:00
|
|
|
$predicates = " WHERE st.ends > '$p_startTime'"
|
|
|
|
." AND st.starts < '$p_endTime'"
|
2012-03-01 23:58:44 +01:00
|
|
|
." ORDER BY st.starts";
|
|
|
|
|
|
|
|
$sql = $baseQuery.$predicates;
|
2012-03-01 15:09:13 +01:00
|
|
|
|
2012-02-22 23:29:49 +01:00
|
|
|
$rows = $CC_DBC->GetAll($sql);
|
2012-02-27 19:52:35 +01:00
|
|
|
if (PEAR::isError($rows)) {
|
|
|
|
return null;
|
2012-02-22 23:29:49 +01:00
|
|
|
}
|
2012-03-01 23:58:44 +01:00
|
|
|
|
|
|
|
if (count($rows) < 3){
|
|
|
|
Logging::debug("Get Schedule: Less than 3 results returned. Doing another query since we need a minimum of 3 results.");
|
|
|
|
|
|
|
|
$dt = new DateTime("@".time());
|
|
|
|
$dt->add(new DateInterval("PT30M"));
|
|
|
|
$range_end = $dt->format("Y-m-d H:i:s");
|
|
|
|
|
2012-03-06 01:02:46 +01:00
|
|
|
$predicates = " WHERE st.ends > '$p_startTime'"
|
2012-03-01 23:58:44 +01:00
|
|
|
." AND st.starts < '$range_end'"
|
|
|
|
." ORDER BY st.starts"
|
|
|
|
." LIMIT 3";
|
|
|
|
|
|
|
|
$sql = $baseQuery.$predicates;
|
|
|
|
$rows = $CC_DBC->GetAll($sql);
|
|
|
|
if (PEAR::isError($rows)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-22 23:29:49 +01:00
|
|
|
return $rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function GetScheduledPlaylists($p_fromDateTime = null, $p_toDateTime = null){
|
2012-03-01 15:09:13 +01:00
|
|
|
|
2012-02-22 23:29:49 +01:00
|
|
|
global $CC_CONFIG, $CC_DBC;
|
2010-12-07 23:29:28 +01:00
|
|
|
|
2012-02-22 23:29:49 +01:00
|
|
|
/* if $p_fromDateTime and $p_toDateTime function parameters are null, then set range
|
|
|
|
* from "now" to "now + 24 hours". */
|
|
|
|
if (is_null($p_fromDateTime)) {
|
|
|
|
$t1 = new DateTime("@".time());
|
|
|
|
$range_start = $t1->format("Y-m-d H:i:s");
|
|
|
|
} else {
|
|
|
|
$range_start = Application_Model_Schedule::PypoTimeToAirtimeTime($p_fromDateTime);
|
|
|
|
}
|
|
|
|
if (is_null($p_fromDateTime)) {
|
|
|
|
$t2 = new DateTime("@".time());
|
2012-03-17 19:53:15 +01:00
|
|
|
|
|
|
|
$cache_ahead_hours = $CC_CONFIG["cache_ahead_hours"];
|
|
|
|
|
|
|
|
if (is_numeric($cache_ahead_hours)){
|
|
|
|
//make sure we are not dealing with a float
|
|
|
|
$cache_ahead_hours = intval($cache_ahead_hours);
|
|
|
|
} else {
|
|
|
|
$cache_ahead_hours = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$t2->add(new DateInterval("PT".$cache_ahead_hours."H"));
|
2012-02-22 23:29:49 +01:00
|
|
|
$range_end = $t2->format("Y-m-d H:i:s");
|
|
|
|
} else {
|
|
|
|
$range_end = Application_Model_Schedule::PypoTimeToAirtimeTime($p_toDateTime);
|
|
|
|
}
|
2012-03-01 15:09:13 +01:00
|
|
|
|
2012-02-22 23:29:49 +01:00
|
|
|
// Scheduler wants everything in a playlist
|
2012-02-23 02:41:24 +01:00
|
|
|
$items = Application_Model_Schedule::GetItems($range_start, $range_end);
|
2012-03-01 15:09:13 +01:00
|
|
|
|
2012-02-23 02:41:24 +01:00
|
|
|
$data = array();
|
|
|
|
$utcTimeZone = new DateTimeZone("UTC");
|
2012-03-01 15:09:13 +01:00
|
|
|
|
2012-02-27 19:52:35 +01:00
|
|
|
$data["status"] = array();
|
|
|
|
$data["media"] = array();
|
2012-03-22 21:23:59 +01:00
|
|
|
$data["harbor"] = array();
|
|
|
|
|
|
|
|
|
|
|
|
$data["harbor"]['next_live_dj_show_end'] = Application_Model_ShowInstance::GetEndTimeOfNextShowWithLiveDJ();
|
|
|
|
$data["harbor"]['transition_fade'] = Application_Model_Preference::GetDefaultTransitionFade();
|
2012-03-01 15:09:13 +01:00
|
|
|
|
2012-02-23 02:41:24 +01:00
|
|
|
foreach ($items as $item){
|
2012-03-01 15:09:13 +01:00
|
|
|
|
2012-02-23 02:41:24 +01:00
|
|
|
$storedFile = Application_Model_StoredFile::Recall($item["file_id"]);
|
2012-03-01 23:58:44 +01:00
|
|
|
$uri = $storedFile->getFilePath();
|
|
|
|
|
2012-02-23 02:41:24 +01:00
|
|
|
$showEndDateTime = new DateTime($item["show_end"], $utcTimeZone);
|
2012-02-27 19:52:35 +01:00
|
|
|
$trackEndDateTime = new DateTime($item["end"], $utcTimeZone);
|
2012-03-01 15:09:13 +01:00
|
|
|
|
2012-02-23 17:21:16 +01:00
|
|
|
/* Note: cue_out and end are always the same. */
|
|
|
|
/* TODO: Not all tracks will have "show_end" */
|
2012-03-01 15:09:13 +01:00
|
|
|
|
2012-02-23 02:41:24 +01:00
|
|
|
if ($trackEndDateTime->getTimestamp() > $showEndDateTime->getTimestamp()){
|
|
|
|
$diff = $trackEndDateTime->getTimestamp() - $showEndDateTime->getTimestamp();
|
|
|
|
//assuming ends takes cue_out into assumption
|
|
|
|
$item["cue_out"] = $item["cue_out"] - $diff;
|
|
|
|
}
|
|
|
|
|
2012-03-01 15:09:13 +01:00
|
|
|
$start = Application_Model_Schedule::AirtimeTimeToPypoTime($item["start"]);
|
2012-02-27 19:52:35 +01:00
|
|
|
$data["media"][$start] = array(
|
2012-02-23 02:41:24 +01:00
|
|
|
'id' => $storedFile->getGunid(),
|
2012-02-29 04:33:19 +01:00
|
|
|
'row_id' => $item["id"],
|
2012-02-23 02:41:24 +01:00
|
|
|
'uri' => $uri,
|
|
|
|
'fade_in' => Application_Model_Schedule::WallTimeToMillisecs($item["fade_in"]),
|
|
|
|
'fade_out' => Application_Model_Schedule::WallTimeToMillisecs($item["fade_out"]),
|
|
|
|
'cue_in' => Application_Model_DateHelper::CalculateLengthInSeconds($item["cue_in"]),
|
|
|
|
'cue_out' => Application_Model_DateHelper::CalculateLengthInSeconds($item["cue_out"]),
|
2012-02-27 19:52:35 +01:00
|
|
|
'start' => $start,
|
|
|
|
'end' => Application_Model_Schedule::AirtimeTimeToPypoTime($item["end"])
|
2012-02-23 02:41:24 +01:00
|
|
|
);
|
|
|
|
}
|
2012-03-01 15:09:13 +01:00
|
|
|
|
2012-02-22 23:29:49 +01:00
|
|
|
return $data;
|
|
|
|
}
|
2010-12-07 23:29:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Export the schedule in json formatted for pypo (the liquidsoap scheduler)
|
|
|
|
*
|
2011-03-22 14:55:33 +01:00
|
|
|
* @param string $p_fromDateTime
|
|
|
|
* In the format "YYYY-MM-DD-HH-mm-SS"
|
|
|
|
* @param string $p_toDateTime
|
|
|
|
* In the format "YYYY-MM-DD-HH-mm-SS"
|
2010-12-07 23:29:28 +01:00
|
|
|
*/
|
2012-02-22 23:29:49 +01:00
|
|
|
public static function GetScheduledPlaylistsOld($p_fromDateTime = null, $p_toDateTime = null)
|
2010-12-07 23:29:28 +01:00
|
|
|
{
|
|
|
|
global $CC_CONFIG, $CC_DBC;
|
2011-03-07 04:42:52 +01:00
|
|
|
|
2011-03-29 00:23:57 +02:00
|
|
|
if (is_null($p_fromDateTime)) {
|
2011-08-19 00:13:43 +02:00
|
|
|
$t1 = new DateTime("@".time());
|
2011-03-29 00:23:57 +02:00
|
|
|
$range_start = $t1->format("Y-m-d H:i:s");
|
|
|
|
} else {
|
2011-09-23 22:50:00 +02:00
|
|
|
$range_start = Application_Model_Schedule::PypoTimeToAirtimeTime($p_fromDateTime);
|
2011-03-29 00:23:57 +02:00
|
|
|
}
|
|
|
|
if (is_null($p_fromDateTime)) {
|
2011-08-19 00:13:43 +02:00
|
|
|
$t2 = new DateTime("@".time());
|
2011-03-29 00:23:57 +02:00
|
|
|
$t2->add(new DateInterval("PT24H"));
|
|
|
|
$range_end = $t2->format("Y-m-d H:i:s");
|
|
|
|
} else {
|
2011-09-23 22:50:00 +02:00
|
|
|
$range_end = Application_Model_Schedule::PypoTimeToAirtimeTime($p_toDateTime);
|
2011-03-29 00:23:57 +02:00
|
|
|
}
|
2011-04-25 22:48:34 +02:00
|
|
|
|
2010-12-07 23:29:28 +01:00
|
|
|
// Scheduler wants everything in a playlist
|
2011-09-23 22:50:00 +02:00
|
|
|
$data = Application_Model_Schedule::GetItems($range_start, $range_end, true);
|
2010-12-07 23:29:28 +01:00
|
|
|
$playlists = array();
|
|
|
|
|
2011-04-14 06:20:19 +02:00
|
|
|
if (is_array($data)){
|
|
|
|
foreach ($data as $dx){
|
2010-12-07 23:29:28 +01:00
|
|
|
$start = $dx['start'];
|
2011-03-03 20:35:27 +01:00
|
|
|
|
|
|
|
//chop off subseconds
|
2010-12-07 23:29:28 +01:00
|
|
|
$start = substr($start, 0, 19);
|
|
|
|
|
2011-03-03 20:35:27 +01:00
|
|
|
//Start time is the array key, needs to be in the format "YYYY-MM-DD-HH-mm-ss"
|
2011-09-23 22:50:00 +02:00
|
|
|
$pkey = Application_Model_Schedule::AirtimeTimeToPypoTime($start);
|
2010-12-07 23:29:28 +01:00
|
|
|
$timestamp = strtotime($start);
|
|
|
|
$playlists[$pkey]['source'] = "PLAYLIST";
|
2011-03-23 17:09:29 +01:00
|
|
|
$playlists[$pkey]['x_ident'] = $dx['group_id'];
|
2010-12-07 23:29:28 +01:00
|
|
|
$playlists[$pkey]['timestamp'] = $timestamp;
|
|
|
|
$playlists[$pkey]['duration'] = $dx['clip_length'];
|
|
|
|
$playlists[$pkey]['played'] = '0';
|
|
|
|
$playlists[$pkey]['schedule_id'] = $dx['group_id'];
|
2011-03-04 18:07:22 +01:00
|
|
|
$playlists[$pkey]['show_name'] = $dx['show_name'];
|
2011-09-23 22:50:00 +02:00
|
|
|
$playlists[$pkey]['show_start'] = Application_Model_Schedule::AirtimeTimeToPypoTime($dx['show_start']);
|
|
|
|
$playlists[$pkey]['show_end'] = Application_Model_Schedule::AirtimeTimeToPypoTime($dx['show_end']);
|
2010-12-07 23:29:28 +01:00
|
|
|
$playlists[$pkey]['user_id'] = 0;
|
2011-03-23 17:09:29 +01:00
|
|
|
$playlists[$pkey]['id'] = $dx['group_id'];
|
2011-09-23 22:50:00 +02:00
|
|
|
$playlists[$pkey]['start'] = Application_Model_Schedule::AirtimeTimeToPypoTime($dx["start"]);
|
|
|
|
$playlists[$pkey]['end'] = Application_Model_Schedule::AirtimeTimeToPypoTime($dx["end"]);
|
2010-12-07 23:29:28 +01:00
|
|
|
}
|
|
|
|
}
|
2011-08-25 00:13:50 +02:00
|
|
|
ksort($playlists);
|
2010-12-07 23:29:28 +01:00
|
|
|
|
|
|
|
foreach ($playlists as &$playlist)
|
|
|
|
{
|
2011-09-23 22:50:00 +02:00
|
|
|
$scheduleGroup = new Application_Model_ScheduleGroup($playlist["schedule_id"]);
|
2010-12-07 23:29:28 +01:00
|
|
|
$items = $scheduleGroup->getItems();
|
|
|
|
$medias = array();
|
|
|
|
foreach ($items as $item)
|
|
|
|
{
|
2011-09-22 18:24:17 +02:00
|
|
|
$storedFile = Application_Model_StoredFile::Recall($item["file_id"]);
|
2011-10-14 00:07:53 +02:00
|
|
|
$uri = $storedFile->getFileUrlUsingConfigAddress();
|
2010-12-07 23:29:28 +01:00
|
|
|
|
2011-09-23 22:50:00 +02:00
|
|
|
$starts = Application_Model_Schedule::AirtimeTimeToPypoTime($item["starts"]);
|
2011-06-14 23:17:15 +02:00
|
|
|
$medias[$starts] = array(
|
2011-02-23 23:03:27 +01:00
|
|
|
'id' => $storedFile->getGunid(),
|
2011-02-02 02:28:38 +01:00
|
|
|
'uri' => $uri,
|
2011-09-23 22:50:00 +02:00
|
|
|
'fade_in' => Application_Model_Schedule::WallTimeToMillisecs($item["fade_in"]),
|
|
|
|
'fade_out' => Application_Model_Schedule::WallTimeToMillisecs($item["fade_out"]),
|
2011-02-02 02:28:38 +01:00
|
|
|
'fade_cross' => 0,
|
2011-09-26 21:29:12 +02:00
|
|
|
'cue_in' => Application_Model_DateHelper::CalculateLengthInSeconds($item["cue_in"]),
|
|
|
|
'cue_out' => Application_Model_DateHelper::CalculateLengthInSeconds($item["cue_out"]),
|
2011-06-14 23:17:15 +02:00
|
|
|
'start' => $starts,
|
2011-09-23 22:50:00 +02:00
|
|
|
'end' => Application_Model_Schedule::AirtimeTimeToPypoTime($item["ends"])
|
2010-12-07 23:29:28 +01:00
|
|
|
);
|
|
|
|
}
|
2011-08-25 00:13:50 +02:00
|
|
|
ksort($medias);
|
2010-12-07 23:29:28 +01:00
|
|
|
$playlist['medias'] = $medias;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = array();
|
2011-03-10 22:41:41 +01:00
|
|
|
$result['status'] = array('range' => array('start' => $range_start, 'end' => $range_end),
|
2011-03-22 14:55:33 +01:00
|
|
|
'version' => AIRTIME_REST_VERSION);
|
2010-12-07 23:29:28 +01:00
|
|
|
$result['playlists'] = $playlists;
|
|
|
|
$result['check'] = 1;
|
2011-03-22 14:55:33 +01:00
|
|
|
$result['stream_metadata'] = array();
|
|
|
|
$result['stream_metadata']['format'] = Application_Model_Preference::GetStreamLabelFormat();
|
|
|
|
$result['stream_metadata']['station_name'] = Application_Model_Preference::GetStationName();
|
2010-12-07 23:29:28 +01:00
|
|
|
|
2011-03-04 02:13:55 +01:00
|
|
|
return $result;
|
2010-12-07 23:29:28 +01:00
|
|
|
}
|
2011-04-25 22:48:34 +02:00
|
|
|
|
|
|
|
public static function deleteAll()
|
|
|
|
{
|
|
|
|
global $CC_CONFIG, $CC_DBC;
|
|
|
|
$CC_DBC->query("TRUNCATE TABLE ".$CC_CONFIG["scheduleTable"]);
|
|
|
|
}
|
2011-07-19 12:37:06 +02:00
|
|
|
|
2011-06-03 20:01:58 +02:00
|
|
|
public static function createNewFormSections($p_view){
|
2011-09-02 21:24:35 +02:00
|
|
|
$isSaas = Application_Model_Preference::GetPlanLevel() == 'disabled'?false:true;
|
2012-01-23 19:07:07 +01:00
|
|
|
|
2011-06-03 20:01:58 +02:00
|
|
|
$formWhat = new Application_Form_AddShowWhat();
|
2012-02-08 06:04:19 +01:00
|
|
|
$formWho = new Application_Form_AddShowWho();
|
|
|
|
$formWhen = new Application_Form_AddShowWhen();
|
|
|
|
$formRepeats = new Application_Form_AddShowRepeats();
|
|
|
|
$formStyle = new Application_Form_AddShowStyle();
|
|
|
|
$formLive = new Application_Form_AddShowLiveStream();
|
|
|
|
|
|
|
|
$formWhat->removeDecorator('DtDdWrapper');
|
|
|
|
$formWho->removeDecorator('DtDdWrapper');
|
|
|
|
$formWhen->removeDecorator('DtDdWrapper');
|
|
|
|
$formRepeats->removeDecorator('DtDdWrapper');
|
|
|
|
$formStyle->removeDecorator('DtDdWrapper');
|
|
|
|
$formLive->removeDecorator('DtDdWrapper');
|
2011-07-19 12:37:06 +02:00
|
|
|
|
2011-06-03 20:01:58 +02:00
|
|
|
$p_view->what = $formWhat;
|
|
|
|
$p_view->when = $formWhen;
|
|
|
|
$p_view->repeats = $formRepeats;
|
|
|
|
$p_view->who = $formWho;
|
|
|
|
$p_view->style = $formStyle;
|
2012-02-08 06:04:19 +01:00
|
|
|
$p_view->live = $formLive;
|
2011-07-19 12:37:06 +02:00
|
|
|
|
2011-06-03 20:01:58 +02:00
|
|
|
$formWhat->populate(array('add_show_id' => '-1'));
|
2011-06-13 20:20:57 +02:00
|
|
|
$formWhen->populate(array('add_show_start_date' => date("Y-m-d"),
|
|
|
|
'add_show_start_time' => '00:00',
|
2012-02-17 22:47:12 +01:00
|
|
|
'add_show_end_date_no_repeate' => date("Y-m-d"),
|
|
|
|
'add_show_end_time' => '01:00',
|
2011-06-13 20:20:57 +02:00
|
|
|
'add_show_duration' => '1h'));
|
|
|
|
|
2012-02-17 22:47:12 +01:00
|
|
|
$formRepeats->populate(array('add_show_end_date' => date("Y-m-d")));
|
2012-01-23 19:07:07 +01:00
|
|
|
|
2011-09-02 21:24:35 +02:00
|
|
|
if(!$isSaas){
|
|
|
|
$formRecord = new Application_Form_AddShowRR();
|
|
|
|
$formAbsoluteRebroadcast = new Application_Form_AddShowAbsoluteRebroadcastDates();
|
|
|
|
$formRebroadcast = new Application_Form_AddShowRebroadcastDates();
|
2012-01-23 19:07:07 +01:00
|
|
|
|
2011-09-02 21:24:35 +02:00
|
|
|
$formRecord->removeDecorator('DtDdWrapper');
|
|
|
|
$formAbsoluteRebroadcast->removeDecorator('DtDdWrapper');
|
|
|
|
$formRebroadcast->removeDecorator('DtDdWrapper');
|
2012-01-23 19:07:07 +01:00
|
|
|
|
2011-09-02 21:24:35 +02:00
|
|
|
$p_view->rr = $formRecord;
|
|
|
|
$p_view->absoluteRebroadcast = $formAbsoluteRebroadcast;
|
|
|
|
$p_view->rebroadcast = $formRebroadcast;
|
|
|
|
}
|
|
|
|
$p_view->addNewShow = true;
|
2011-06-03 20:01:58 +02:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|