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
|
|
|
* Returns array indexed by:
|
2010-12-07 23:29:28 +01:00
|
|
|
* "playlistId"/"playlist_id" (aliases to the same thing)
|
|
|
|
* "start"/"starts" (aliases to the same thing) as YYYY-MM-DD HH:MM:SS.nnnnnn
|
|
|
|
* "end"/"ends" (aliases to the same thing) as YYYY-MM-DD HH:MM:SS.nnnnnn
|
|
|
|
* "group_id"/"id" (aliases to the same thing)
|
|
|
|
* "clip_length" (for audio clips this is the length of the audio clip,
|
2011-02-02 02:28:38 +01:00
|
|
|
* for playlists this is the length of the entire playlist)
|
2010-12-07 23:29:28 +01:00
|
|
|
* "name" (playlist only)
|
|
|
|
* "creator" (playlist only)
|
|
|
|
* "file_id" (audioclip only)
|
|
|
|
* "count" (number of items in the playlist, always 1 for audioclips.
|
|
|
|
* Note that playlists with one item will also have count = 1.
|
|
|
|
*
|
|
|
|
* @param string $p_fromDateTime
|
|
|
|
* In the format YYYY-MM-DD HH:MM:SS.nnnnnn
|
|
|
|
* @param string $p_toDateTime
|
|
|
|
* In the format YYYY-MM-DD HH:MM:SS.nnnnnn
|
|
|
|
* @param boolean $p_playlistsOnly
|
2010-12-22 00:28:17 +01:00
|
|
|
* Retrieve playlists as a single item.
|
2010-12-07 23:29:28 +01:00
|
|
|
* @return array
|
2011-02-02 02:28:38 +01:00
|
|
|
* Returns empty array if nothing found
|
2010-12-07 23:29:28 +01:00
|
|
|
*/
|
2011-03-25 04:43:27 +01:00
|
|
|
|
|
|
|
public static function GetItems($p_currentDateTime, $p_toDateTime, $p_playlistsOnly = true)
|
2011-03-22 14:55:33 +01:00
|
|
|
{
|
2010-12-07 23:29:28 +01:00
|
|
|
global $CC_CONFIG, $CC_DBC;
|
|
|
|
$rows = array();
|
|
|
|
if (!$p_playlistsOnly) {
|
|
|
|
$sql = "SELECT * FROM ".$CC_CONFIG["scheduleTable"]
|
2011-03-25 04:43:27 +01:00
|
|
|
." WHERE (starts >= TIMESTAMP '$p_currentDateTime') "
|
2010-12-07 20:19:27 +01:00
|
|
|
." AND (ends <= TIMESTAMP '$p_toDateTime')";
|
2010-12-07 23:29:28 +01:00
|
|
|
$rows = $CC_DBC->GetAll($sql);
|
|
|
|
foreach ($rows as &$row) {
|
|
|
|
$row["count"] = "1";
|
|
|
|
$row["playlistId"] = $row["playlist_id"];
|
|
|
|
$row["start"] = $row["starts"];
|
|
|
|
$row["end"] = $row["ends"];
|
|
|
|
$row["id"] = $row["group_id"];
|
|
|
|
}
|
|
|
|
} else {
|
2011-09-17 18:36:35 +02:00
|
|
|
$sql = "SELECT MIN(pt.creator) AS creator,"
|
|
|
|
." st.group_id,"
|
2011-03-04 18:07:22 +01:00
|
|
|
." SUM(st.clip_length) AS clip_length,"
|
|
|
|
." MIN(st.file_id) AS file_id,"
|
|
|
|
." COUNT(*) as count,"
|
|
|
|
." MIN(st.playlist_id) AS playlist_id,"
|
|
|
|
." MIN(st.starts) AS starts,"
|
|
|
|
." MAX(st.ends) AS ends,"
|
2011-04-14 06:20:19 +02:00
|
|
|
." MIN(sh.name) AS show_name,"
|
|
|
|
." MIN(si.starts) AS show_start,"
|
|
|
|
." MAX(si.ends) AS show_end"
|
2011-03-04 18:07:22 +01:00
|
|
|
." FROM $CC_CONFIG[scheduleTable] as st"
|
|
|
|
." LEFT JOIN $CC_CONFIG[playListTable] as pt"
|
|
|
|
." ON st.playlist_id = pt.id"
|
|
|
|
." LEFT JOIN $CC_CONFIG[showInstances] as si"
|
|
|
|
." ON st.instance_id = si.id"
|
|
|
|
." LEFT JOIN $CC_CONFIG[showTable] as sh"
|
|
|
|
." ON si.show_id = sh.id"
|
2011-08-25 00:13:50 +02:00
|
|
|
//The next line ensures we only get songs that haven't ended yet
|
2011-03-25 04:43:27 +01:00
|
|
|
." WHERE (st.ends >= TIMESTAMP '$p_currentDateTime')"
|
2011-03-04 18:07:22 +01:00
|
|
|
." AND (st.ends <= TIMESTAMP '$p_toDateTime')"
|
2011-03-07 20:01:08 +01:00
|
|
|
//next line makes sure that we aren't returning items that
|
|
|
|
//are past the show's scheduled timeslot.
|
2011-03-22 14:55:33 +01:00
|
|
|
." AND (st.starts < si.ends)"
|
2011-03-04 18:07:22 +01:00
|
|
|
." GROUP BY st.group_id"
|
2010-12-07 23:29:28 +01:00
|
|
|
." ORDER BY starts";
|
2011-03-03 20:35:27 +01:00
|
|
|
|
2010-12-07 23:29:28 +01:00
|
|
|
$rows = $CC_DBC->GetAll($sql);
|
|
|
|
if (!PEAR::isError($rows)) {
|
|
|
|
foreach ($rows as &$row) {
|
|
|
|
$row["playlistId"] = $row["playlist_id"];
|
|
|
|
$row["start"] = $row["starts"];
|
|
|
|
$row["end"] = $row["ends"];
|
|
|
|
$row["id"] = $row["group_id"];
|
|
|
|
}
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
2010-12-07 23:29:28 +01:00
|
|
|
return $rows;
|
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
|
|
|
*
|
|
|
|
* @param int $prev
|
|
|
|
* @param int $next
|
|
|
|
* @return date
|
|
|
|
*/
|
2011-03-22 14:55:33 +01:00
|
|
|
public static function GetPlayOrderRange($prev = 1, $next = 1)
|
|
|
|
{
|
2010-12-22 00:28:17 +01:00
|
|
|
if (!is_int($prev) || !is_int($next)){
|
|
|
|
//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-02-22 22:16:37 +01:00
|
|
|
global $CC_CONFIG;
|
|
|
|
|
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();
|
|
|
|
$range = array("env"=>APPLICATION_ENV,
|
2011-08-15 22:40:24 +02:00
|
|
|
"schedulerTime"=>$timeNow,
|
2011-11-15 21:45:08 +01:00
|
|
|
"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),
|
2011-01-31 22:34:08 +01:00
|
|
|
"timezone"=> date("T"),
|
2011-07-12 20:09:40 +02:00
|
|
|
"timezoneOffset"=> date("Z"));
|
2012-01-23 19:07:07 +01:00
|
|
|
|
2011-11-15 21:45:08 +01:00
|
|
|
return $range;
|
2010-12-07 23:29:28 +01:00
|
|
|
}
|
2011-02-22 18:22:31 +01:00
|
|
|
|
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){
|
2011-02-13 20:04:38 +01:00
|
|
|
$sql .= " AND st.ends < TIMESTAMP '$timeStamp'"
|
|
|
|
." AND st.ends > (TIMESTAMP '$timeStamp' - INTERVAL '$interval')"
|
2011-02-07 02:12:56 +01:00
|
|
|
." ORDER BY st.starts DESC"
|
2011-02-22 18:22:31 +01:00
|
|
|
." LIMIT $count";
|
2011-02-03 00:25:42 +01:00
|
|
|
} else if ($timePeriod == 0){
|
2011-02-13 20:04:38 +01:00
|
|
|
$sql .= " AND st.starts <= TIMESTAMP '$timeStamp'"
|
2011-02-22 18:22:31 +01:00
|
|
|
." AND st.ends >= TIMESTAMP '$timeStamp'";
|
2011-02-03 00:25:42 +01:00
|
|
|
} else if ($timePeriod > 0){
|
2011-02-13 21:35:41 +01:00
|
|
|
$sql .= " AND st.starts > TIMESTAMP '$timeStamp'"
|
2011-02-22 18:22:31 +01:00
|
|
|
." AND st.starts < (TIMESTAMP '$timeStamp' + INTERVAL '$interval')"
|
2011-02-03 00:25:42 +01:00
|
|
|
." ORDER BY st.starts"
|
2011-02-22 18:22:31 +01:00
|
|
|
." LIMIT $count";
|
2011-02-03 00:25:42 +01:00
|
|
|
}
|
2011-02-05 00:22:15 +01:00
|
|
|
|
2011-02-03 00:25:42 +01:00
|
|
|
$rows = $CC_DBC->GetAll($sql);
|
|
|
|
return $rows;
|
|
|
|
}
|
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-02-15 00:39:27 +01:00
|
|
|
public static function GetScheduleDetailItems($p_startDateTime, $p_endDateTime, $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,
|
|
|
|
showt.background_color AS show_background_colour, 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-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-02-15 00:39:27 +01:00
|
|
|
si.starts >= '{$p_startDateTime}' AND si.starts < '{$p_endDateTime}'";
|
2012-01-26 15:21:04 +01:00
|
|
|
|
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(){
|
|
|
|
global $CC_CONFIG, $CC_DBC;
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2011-03-29 00:23:57 +02:00
|
|
|
public static function GetScheduledPlaylists($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
|
|
|
'row_id' => $item["id"],
|
|
|
|
'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
|
|
|
'export_source' => 'scheduler',
|
|
|
|
'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();
|
|
|
|
$formWho = new Application_Form_AddShowWho();
|
|
|
|
$formWhen = new Application_Form_AddShowWhen();
|
|
|
|
$formRepeats = new Application_Form_AddShowRepeats();
|
|
|
|
$formStyle = new Application_Form_AddShowStyle();
|
|
|
|
|
|
|
|
$formWhat->removeDecorator('DtDdWrapper');
|
|
|
|
$formWho->removeDecorator('DtDdWrapper');
|
|
|
|
$formWhen->removeDecorator('DtDdWrapper');
|
|
|
|
$formRepeats->removeDecorator('DtDdWrapper');
|
|
|
|
$formStyle->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;
|
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',
|
|
|
|
'add_show_end_date_no_repeate' => date("Y-m-d"),
|
|
|
|
'add_show_end_time' => '01:00',
|
|
|
|
'add_show_duration' => '1h'));
|
|
|
|
|
|
|
|
$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
|
|
|
}
|
|
|
|
|