Merge branch 'cc-3336-refactor-pypo' into devel
This commit is contained in:
commit
057e377c5f
6 changed files with 406 additions and 450 deletions
|
@ -276,17 +276,19 @@ class ApiController extends Zend_Controller_Action
|
|||
|
||||
$api_key = $this->_getParam('api_key');
|
||||
|
||||
/*
|
||||
if(!in_array($api_key, $CC_CONFIG["apiKey"]))
|
||||
{
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
print 'You are not allowed to access this resource. ';
|
||||
exit;
|
||||
}
|
||||
* */
|
||||
|
||||
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
||||
|
||||
$result = Application_Model_Schedule::GetScheduledPlaylists();
|
||||
echo json_encode($result);
|
||||
$data = Application_Model_Schedule::GetScheduledPlaylists();
|
||||
echo json_encode($data, JSON_FORCE_OBJECT);
|
||||
}
|
||||
|
||||
public function notifyMediaItemStartPlayAction()
|
||||
|
|
|
@ -46,87 +46,6 @@ class Application_Model_Schedule {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns array indexed by:
|
||||
* "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,
|
||||
* for playlists this is the length of the entire playlist)
|
||||
* "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
|
||||
* Retrieve playlists as a single item.
|
||||
* @return array
|
||||
* Returns empty array if nothing found
|
||||
*/
|
||||
|
||||
public static function GetItems($p_currentDateTime, $p_toDateTime, $p_playlistsOnly = true)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$rows = array();
|
||||
if (!$p_playlistsOnly) {
|
||||
$sql = "SELECT * FROM ".$CC_CONFIG["scheduleTable"]
|
||||
." WHERE (starts >= TIMESTAMP '$p_currentDateTime') "
|
||||
." AND (ends <= TIMESTAMP '$p_toDateTime')";
|
||||
$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 {
|
||||
$sql = "SELECT MIN(pt.creator) AS creator,"
|
||||
." st.group_id,"
|
||||
." 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,"
|
||||
." MIN(sh.name) AS show_name,"
|
||||
." MIN(si.starts) AS show_start,"
|
||||
." MAX(si.ends) AS show_end"
|
||||
." 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"
|
||||
//The next line ensures we only get songs that haven't ended yet
|
||||
." WHERE (st.ends >= TIMESTAMP '$p_currentDateTime')"
|
||||
." AND (st.ends <= TIMESTAMP '$p_toDateTime')"
|
||||
//next line makes sure that we aren't returning items that
|
||||
//are past the show's scheduled timeslot.
|
||||
." AND (st.starts < si.ends)"
|
||||
." GROUP BY st.group_id"
|
||||
." ORDER BY starts";
|
||||
|
||||
$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"];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns data related to the scheduled items.
|
||||
*
|
||||
|
@ -475,7 +394,115 @@ class Application_Model_Schedule {
|
|||
}
|
||||
return $diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array indexed by:
|
||||
* "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,
|
||||
* for playlists this is the length of the entire playlist)
|
||||
* "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
|
||||
* Retrieve playlists as a single item.
|
||||
* @return array
|
||||
* Returns null if nothing found
|
||||
*/
|
||||
public static function GetItems($p_currentDateTime, $p_toDateTime) {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$rows = array();
|
||||
|
||||
$sql = "SELECT st.file_id AS file_id,"
|
||||
." st.starts AS start,"
|
||||
." st.ends AS end,"
|
||||
." 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"
|
||||
." ORDER BY start";
|
||||
|
||||
Logging::log($sql);
|
||||
|
||||
$rows = $CC_DBC->GetAll($sql);
|
||||
if (PEAR::isError($rows)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public static function GetScheduledPlaylists($p_fromDateTime = null, $p_toDateTime = null){
|
||||
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
/* 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());
|
||||
$t2->add(new DateInterval("PT24H"));
|
||||
$range_end = $t2->format("Y-m-d H:i:s");
|
||||
} else {
|
||||
$range_end = Application_Model_Schedule::PypoTimeToAirtimeTime($p_toDateTime);
|
||||
}
|
||||
|
||||
// Scheduler wants everything in a playlist
|
||||
$items = Application_Model_Schedule::GetItems($range_start, $range_end);
|
||||
|
||||
$data = array();
|
||||
$utcTimeZone = new DateTimeZone("UTC");
|
||||
|
||||
$data["status"] = array();
|
||||
$data["media"] = array();
|
||||
|
||||
foreach ($items as $item){
|
||||
|
||||
$storedFile = Application_Model_StoredFile::Recall($item["file_id"]);
|
||||
$uri = $storedFile->getFileUrlUsingConfigAddress();
|
||||
|
||||
$showEndDateTime = new DateTime($item["show_end"], $utcTimeZone);
|
||||
$trackEndDateTime = new DateTime($item["end"], $utcTimeZone);
|
||||
|
||||
/* Note: cue_out and end are always the same. */
|
||||
/* TODO: Not all tracks will have "show_end" */
|
||||
|
||||
if ($trackEndDateTime->getTimestamp() > $showEndDateTime->getTimestamp()){
|
||||
$diff = $trackEndDateTime->getTimestamp() - $showEndDateTime->getTimestamp();
|
||||
//assuming ends takes cue_out into assumption
|
||||
$item["cue_out"] = $item["cue_out"] - $diff;
|
||||
}
|
||||
|
||||
$start = Application_Model_Schedule::AirtimeTimeToPypoTime($item["start"]);
|
||||
$data["media"][$start] = array(
|
||||
'id' => $storedFile->getGunid(),
|
||||
'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"]),
|
||||
'start' => $start,
|
||||
'end' => Application_Model_Schedule::AirtimeTimeToPypoTime($item["end"])
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export the schedule in json formatted for pypo (the liquidsoap scheduler)
|
||||
|
@ -485,7 +512,7 @@ class Application_Model_Schedule {
|
|||
* @param string $p_toDateTime
|
||||
* In the format "YYYY-MM-DD-HH-mm-SS"
|
||||
*/
|
||||
public static function GetScheduledPlaylists($p_fromDateTime = null, $p_toDateTime = null)
|
||||
public static function GetScheduledPlaylistsOld($p_fromDateTime = null, $p_toDateTime = null)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
|
@ -546,7 +573,6 @@ class Application_Model_Schedule {
|
|||
|
||||
$starts = Application_Model_Schedule::AirtimeTimeToPypoTime($item["starts"]);
|
||||
$medias[$starts] = array(
|
||||
'row_id' => $item["id"],
|
||||
'id' => $storedFile->getGunid(),
|
||||
'uri' => $uri,
|
||||
'fade_in' => Application_Model_Schedule::WallTimeToMillisecs($item["fade_in"]),
|
||||
|
@ -554,7 +580,6 @@ class Application_Model_Schedule {
|
|||
'fade_cross' => 0,
|
||||
'cue_in' => Application_Model_DateHelper::CalculateLengthInSeconds($item["cue_in"]),
|
||||
'cue_out' => Application_Model_DateHelper::CalculateLengthInSeconds($item["cue_out"]),
|
||||
'export_source' => 'scheduler',
|
||||
'start' => $starts,
|
||||
'end' => Application_Model_Schedule::AirtimeTimeToPypoTime($item["ends"])
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue