CC-2833: Use ClassLoaders for PHP Files

-Done for class Schedule and ScheduleGroup
This commit is contained in:
martin 2011-09-23 16:50:00 -04:00
parent cd95170b06
commit 1e9a8a28fe
13 changed files with 264 additions and 267 deletions

View file

@ -1,225 +1,6 @@
<?php
class ScheduleGroup {
private $groupId;
public function __construct($p_groupId = null) {
$this->groupId = $p_groupId;
}
/**
* Return true if the schedule group exists in the DB.
* @return boolean
*/
public function exists() {
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT COUNT(*) FROM ".$CC_CONFIG['scheduleTable']
." WHERE group_id=".$this->groupId;
$result = $CC_DBC->GetOne($sql);
if (PEAR::isError($result)) {
return $result;
}
return $result != "0";
}
/**
* Add a music clip or playlist to the schedule.
*
* @param int $p_showInstance
* ID of the show.
* @param $p_datetime
* In the format YYYY-MM-DD HH:MM:SS.mmmmmm
* @param $p_audioFileId
* (optional, either this or $p_playlistId must be set) DB ID of the audio file
* @param $p_playlistId
* (optional, either this of $p_audioFileId must be set) DB ID of the playlist
* @param $p_options
* Does nothing at the moment.
*
* @return int|PEAR_Error
* Return PEAR_Error if the item could not be added.
* Error code 555 is a scheduling conflict.
*/
public function add($p_showInstance, $p_datetime, $p_audioFileId = null, $p_playlistId = null, $p_options = null) {
global $CC_CONFIG, $CC_DBC;
if (!is_null($p_audioFileId)) {
// Schedule a single audio track
// Load existing track
$track = Application_Model_StoredFile::Recall($p_audioFileId);
if (is_null($track)) {
return new PEAR_Error("Could not find audio track.");
}
// Check if there are any conflicts with existing entries
$metadata = $track->getMetadata();
$length = $metadata['MDATA_KEY_DURATION'];
if (empty($length)) {
return new PEAR_Error("Length is empty.");
}
// Insert into the table
$this->groupId = $CC_DBC->GetOne("SELECT nextval('schedule_group_id_seq')");
$sql = "INSERT INTO ".$CC_CONFIG["scheduleTable"]
." (instance_id, starts, ends, clip_length, group_id, file_id, cue_out)"
." VALUES ($p_showInstance, TIMESTAMP '$p_datetime', "
." (TIMESTAMP '$p_datetime' + INTERVAL '$length'),"
." '$length',"
." {$this->groupId}, $p_audioFileId, '$length')";
$result = $CC_DBC->query($sql);
if (PEAR::isError($result)) {
//var_dump($sql);
return $result;
}
}
elseif (!is_null($p_playlistId)){
// Schedule a whole playlist
// Load existing playlist
$playlist = Application_Model_Playlist::Recall($p_playlistId);
if (is_null($playlist)) {
return new PEAR_Error("Could not find playlist.");
}
// Check if there are any conflicts with existing entries
$length = trim($playlist->getLength());
//var_dump($length);
if (empty($length)) {
return new PEAR_Error("Length is empty.");
}
// Insert all items into the schedule
$this->groupId = $CC_DBC->GetOne("SELECT nextval('schedule_group_id_seq')");
$itemStartTime = $p_datetime;
$plItems = $playlist->getContents();
//var_dump($plItems);
foreach ($plItems as $row) {
$trackLength = $row["cliplength"];
//var_dump($trackLength);
$sql = "INSERT INTO ".$CC_CONFIG["scheduleTable"]
." (instance_id, playlist_id, starts, ends, group_id, file_id,"
." clip_length, cue_in, cue_out, fade_in, fade_out)"
." VALUES ($p_showInstance, $p_playlistId, TIMESTAMP '$itemStartTime', "
." (TIMESTAMP '$itemStartTime' + INTERVAL '$trackLength'),"
." '{$this->groupId}', '{$row['file_id']}', '$trackLength', '{$row['cuein']}',"
." '{$row['cueout']}', '{$row['fadein']}','{$row['fadeout']}')";
$result = $CC_DBC->query($sql);
if (PEAR::isError($result)) {
//var_dump($sql);
return $result;
}
$itemStartTime = $CC_DBC->getOne("SELECT TIMESTAMP '$itemStartTime' + INTERVAL '$trackLength'");
}
}
RabbitMq::PushSchedule();
return $this->groupId;
}
public function addFileAfter($show_instance, $p_groupId, $p_audioFileId) {
global $CC_CONFIG, $CC_DBC;
// Get the end time for the given entry
$sql = "SELECT MAX(ends) FROM ".$CC_CONFIG["scheduleTable"]
." WHERE group_id=$p_groupId";
$startTime = $CC_DBC->GetOne($sql);
return $this->add($show_instance, $startTime, $p_audioFileId);
}
public function addPlaylistAfter($show_instance, $p_groupId, $p_playlistId) {
global $CC_CONFIG, $CC_DBC;
// Get the end time for the given entry
$sql = "SELECT MAX(ends) FROM ".$CC_CONFIG["scheduleTable"]
." WHERE group_id=$p_groupId";
$startTime = $CC_DBC->GetOne($sql);
return $this->add($show_instance, $startTime, null, $p_playlistId);
}
/**
* Remove the group from the schedule.
* Note: does not check if it is in the past, you can remove anything.
*
* @return boolean
* TRUE on success, false if there is no group ID defined.
*/
public function remove() {
global $CC_CONFIG, $CC_DBC;
if (is_null($this->groupId) || !is_numeric($this->groupId)) {
return false;
}
$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"]
." WHERE group_id = ".$this->groupId;
//echo $sql;
$retVal = $CC_DBC->query($sql);
RabbitMq::PushSchedule();
return $retVal;
}
/**
* Return the number of items in this group.
* @return string
*/
public function count() {
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT COUNT(*) FROM {$CC_CONFIG['scheduleTable']}"
." WHERE group_id={$this->groupId}";
return $CC_DBC->GetOne($sql);
}
/*
* Return the list of items in this group as a 2D array.
* @return array
*/
public function getItems() {
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT "
." st.id,"
." st.file_id,"
." st.cue_in,"
." st.cue_out,"
." st.clip_length,"
." st.fade_in,"
." st.fade_out,"
." st.starts,"
." st.ends"
." FROM $CC_CONFIG[scheduleTable] as st"
." LEFT JOIN $CC_CONFIG[showInstances] as si"
." ON st.instance_id = si.id"
." WHERE st.group_id=$this->groupId"
." AND st.starts < si.ends"
." ORDER BY st.starts";
return $CC_DBC->GetAll($sql);
}
public function notifyGroupStartPlay() {
global $CC_CONFIG, $CC_DBC;
$sql = "UPDATE ".$CC_CONFIG['scheduleTable']
." SET schedule_group_played=TRUE"
." WHERE group_id=".$this->groupId;
$retVal = $CC_DBC->query($sql);
return $retVal;
}
public function notifyMediaItemStartPlay($p_fileId) {
global $CC_CONFIG, $CC_DBC;
$sql = "UPDATE ".$CC_CONFIG['scheduleTable']
." SET media_item_played=TRUE"
." WHERE group_id=".$this->groupId
." AND file_id=".pg_escape_string($p_fileId);
$retVal = $CC_DBC->query($sql);
return $retVal;
}
}
class Schedule {
function __construct() {
}
class Application_Model_Schedule {
/**
* Return true if there is nothing in the schedule for the given start time
@ -234,7 +15,7 @@ class Schedule {
public static function isScheduleEmptyInRange($p_datetime, $p_length) {
global $CC_CONFIG, $CC_DBC;
if (empty($p_length)) {
return new PEAR_Error("Schedule::isSchedulerEmptyInRange: param p_length is empty.");
return new PEAR_Error("Application_Model_Schedule::isSchedulerEmptyInRange: param p_length is empty.");
}
$sql = "SELECT COUNT(*) FROM ".$CC_CONFIG["scheduleTable"]
." WHERE (starts >= '$p_datetime') "
@ -659,18 +440,18 @@ class Schedule {
$t1 = new DateTime("@".time());
$range_start = $t1->format("Y-m-d H:i:s");
} else {
$range_start = Schedule::PypoTimeToAirtimeTime($p_fromDateTime);
$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 = Schedule::PypoTimeToAirtimeTime($p_toDateTime);
$range_end = Application_Model_Schedule::PypoTimeToAirtimeTime($p_toDateTime);
}
// Scheduler wants everything in a playlist
$data = Schedule::GetItems($range_start, $range_end, true);
$data = Application_Model_Schedule::GetItems($range_start, $range_end, true);
$playlists = array();
if (is_array($data)){
@ -681,7 +462,7 @@ class Schedule {
$start = substr($start, 0, 19);
//Start time is the array key, needs to be in the format "YYYY-MM-DD-HH-mm-ss"
$pkey = Schedule::AirtimeTimeToPypoTime($start);
$pkey = Application_Model_Schedule::AirtimeTimeToPypoTime($start);
$timestamp = strtotime($start);
$playlists[$pkey]['source'] = "PLAYLIST";
$playlists[$pkey]['x_ident'] = $dx['group_id'];
@ -690,19 +471,19 @@ class Schedule {
$playlists[$pkey]['played'] = '0';
$playlists[$pkey]['schedule_id'] = $dx['group_id'];
$playlists[$pkey]['show_name'] = $dx['show_name'];
$playlists[$pkey]['show_start'] = Schedule::AirtimeTimeToPypoTime($dx['show_start']);
$playlists[$pkey]['show_end'] = Schedule::AirtimeTimeToPypoTime($dx['show_end']);
$playlists[$pkey]['show_start'] = Application_Model_Schedule::AirtimeTimeToPypoTime($dx['show_start']);
$playlists[$pkey]['show_end'] = Application_Model_Schedule::AirtimeTimeToPypoTime($dx['show_end']);
$playlists[$pkey]['user_id'] = 0;
$playlists[$pkey]['id'] = $dx['group_id'];
$playlists[$pkey]['start'] = Schedule::AirtimeTimeToPypoTime($dx["start"]);
$playlists[$pkey]['end'] = Schedule::AirtimeTimeToPypoTime($dx["end"]);
$playlists[$pkey]['start'] = Application_Model_Schedule::AirtimeTimeToPypoTime($dx["start"]);
$playlists[$pkey]['end'] = Application_Model_Schedule::AirtimeTimeToPypoTime($dx["end"]);
}
}
ksort($playlists);
foreach ($playlists as &$playlist)
{
$scheduleGroup = new ScheduleGroup($playlist["schedule_id"]);
$scheduleGroup = new Application_Model_ScheduleGroup($playlist["schedule_id"]);
$items = $scheduleGroup->getItems();
$medias = array();
foreach ($items as $item)
@ -710,19 +491,19 @@ class Schedule {
$storedFile = Application_Model_StoredFile::Recall($item["file_id"]);
$uri = $storedFile->getFileUrl();
$starts = Schedule::AirtimeTimeToPypoTime($item["starts"]);
$starts = Application_Model_Schedule::AirtimeTimeToPypoTime($item["starts"]);
$medias[$starts] = array(
'row_id' => $item["id"],
'id' => $storedFile->getGunid(),
'uri' => $uri,
'fade_in' => Schedule::WallTimeToMillisecs($item["fade_in"]),
'fade_out' => Schedule::WallTimeToMillisecs($item["fade_out"]),
'fade_in' => Application_Model_Schedule::WallTimeToMillisecs($item["fade_in"]),
'fade_out' => Application_Model_Schedule::WallTimeToMillisecs($item["fade_out"]),
'fade_cross' => 0,
'cue_in' => DateHelper::CalculateLengthInSeconds($item["cue_in"]),
'cue_out' => DateHelper::CalculateLengthInSeconds($item["cue_out"]),
'export_source' => 'scheduler',
'start' => $starts,
'end' => Schedule::AirtimeTimeToPypoTime($item["ends"])
'end' => Application_Model_Schedule::AirtimeTimeToPypoTime($item["ends"])
);
}
ksort($medias);