CC-2833: Use ClassLoaders for PHP Files
-Done for class Schedule and ScheduleGroup
This commit is contained in:
parent
cd95170b06
commit
1e9a8a28fe
|
@ -15,7 +15,7 @@ require_once 'Soundcloud.php';
|
|||
//require_once 'MusicDir.php';
|
||||
//require_once 'Playlist.php';
|
||||
//require_once 'StoredFile.php';
|
||||
require_once 'Schedule.php';
|
||||
//require_once 'Schedule.php';
|
||||
require_once 'Preference.php';
|
||||
//require_once 'Shows.php';
|
||||
require_once 'Users.php';
|
||||
|
|
|
@ -219,7 +219,7 @@ class ApiController extends Zend_Controller_Action
|
|||
|
||||
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
||||
|
||||
$result = Schedule::GetScheduledPlaylists();
|
||||
$result = Application_Model_Schedule::GetScheduledPlaylists();
|
||||
echo json_encode($result);
|
||||
}
|
||||
|
||||
|
@ -241,7 +241,7 @@ class ApiController extends Zend_Controller_Action
|
|||
|
||||
$schedule_group_id = $this->_getParam("schedule_id");
|
||||
$media_id = $this->_getParam("media_id");
|
||||
$result = Schedule::UpdateMediaPlayedStatus($media_id);
|
||||
$result = Application_Model_Schedule::UpdateMediaPlayedStatus($media_id);
|
||||
|
||||
if (!PEAR::isError($result)) {
|
||||
echo json_encode(array("status"=>1, "message"=>""));
|
||||
|
@ -270,7 +270,7 @@ class ApiController extends Zend_Controller_Action
|
|||
|
||||
$schedule_group_id = $this->_getParam("schedule_id");
|
||||
if (is_numeric($schedule_group_id)) {
|
||||
$sg = new ScheduleGroup($schedule_group_id);
|
||||
$sg = new Application_Model_ScheduleGroup($schedule_group_id);
|
||||
if ($sg->exists()) {
|
||||
$result = $sg->notifyGroupStartPlay();
|
||||
if (!PEAR::isError($result)) {
|
||||
|
|
|
@ -55,7 +55,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
$this->view->headLink()->appendStylesheet($baseUrl.'/css/contextmenu.css');
|
||||
$this->view->headLink()->appendStylesheet($baseUrl.'/css/qtip/jquery.qtip.min.css');
|
||||
|
||||
Schedule::createNewFormSections($this->view);
|
||||
Application_Model_Schedule::createNewFormSections($this->view);
|
||||
|
||||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||
$user = new User($userInfo->id);
|
||||
|
@ -252,7 +252,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
|
||||
public function getCurrentPlaylistAction()
|
||||
{
|
||||
$this->view->entries = Schedule::GetPlayOrderRange();
|
||||
$this->view->entries = Application_Model_Schedule::GetPlayOrderRange();
|
||||
}
|
||||
|
||||
public function findPlaylistsAction()
|
||||
|
@ -482,7 +482,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
}
|
||||
|
||||
public function getFormAction(){
|
||||
Schedule::createNewFormSections($this->view);
|
||||
Application_Model_Schedule::createNewFormSections($this->view);
|
||||
$this->view->form = $this->view->render('schedule/add-show-form.phtml');
|
||||
}
|
||||
|
||||
|
@ -631,7 +631,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
}
|
||||
|
||||
//send back a new form for the user.
|
||||
Schedule::createNewFormSections($this->view);
|
||||
Application_Model_Schedule::createNewFormSections($this->view);
|
||||
|
||||
$this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
|
||||
}
|
||||
|
@ -643,7 +643,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
}
|
||||
|
||||
//send back a new form for the user.
|
||||
Schedule::createNewFormSections($this->view);
|
||||
Application_Model_Schedule::createNewFormSections($this->view);
|
||||
|
||||
$this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ class RabbitMqPlugin extends Zend_Controller_Plugin_Abstract
|
|||
public function dispatchLoopShutdown()
|
||||
{
|
||||
if (RabbitMq::$doPush) {
|
||||
$md = array('schedule' => Schedule::GetScheduledPlaylists());
|
||||
$md = array('schedule' => Application_Model_Schedule::GetScheduledPlaylists());
|
||||
RabbitMq::SendMessageToPypo("update_schedule", $md);
|
||||
RabbitMq::SendMessageToShowRecorder("update_schedule");
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ class Application_Model_Dashboard
|
|||
//name. Else return the last item from the schedule.
|
||||
|
||||
$showInstance = Application_Model_ShowInstance::GetLastShowInstance($p_timeNow);
|
||||
$row = Schedule::GetLastScheduleItem($p_timeNow);
|
||||
$row = Application_Model_Schedule::GetLastScheduleItem($p_timeNow);
|
||||
|
||||
if (is_null($showInstance)){
|
||||
if (count($row) == 0){
|
||||
|
@ -56,7 +56,7 @@ class Application_Model_Dashboard
|
|||
$showInstance = Application_Model_ShowInstance::GetCurrentShowInstance($p_timeNow);
|
||||
if (!is_null($showInstance)){
|
||||
$instanceId = $showInstance->getShowInstanceId();
|
||||
$row = Schedule::GetCurrentScheduleItem($p_timeNow, $instanceId);
|
||||
$row = Application_Model_Schedule::GetCurrentScheduleItem($p_timeNow, $instanceId);
|
||||
}
|
||||
if (is_null($showInstance)){
|
||||
if (count($row) == 0){
|
||||
|
@ -99,7 +99,7 @@ class Application_Model_Dashboard
|
|||
//name. Else return the last item from the schedule.
|
||||
|
||||
$showInstance = Application_Model_ShowInstance::GetNextShowInstance($p_timeNow);
|
||||
$row = Schedule::GetNextScheduleItem($p_timeNow);
|
||||
$row = Application_Model_Schedule::GetNextScheduleItem($p_timeNow);
|
||||
|
||||
if (is_null($showInstance)){
|
||||
if (count($row) == 0){
|
||||
|
|
|
@ -336,7 +336,7 @@ class Application_Model_Preference
|
|||
$outputArray['NUM_OF_USERS'] = User::getUserCount();
|
||||
$outputArray['NUM_OF_SONGS'] = Application_Model_StoredFile::getFileCount();
|
||||
$outputArray['NUM_OF_PLAYLISTS'] = Application_Model_Playlist::getPlaylistCount();
|
||||
$outputArray['NUM_OF_SCHEDULED_PLAYLISTS'] = Schedule::getSchduledPlaylistCount();
|
||||
$outputArray['NUM_OF_SCHEDULED_PLAYLISTS'] = Application_Model_Schedule::getSchduledPlaylistCount();
|
||||
$outputArray['NUM_OF_PAST_SHOWS'] = Application_Model_ShowInstance::GetShowInstanceCount(date("Y-m-d H:i:s"));
|
||||
$outputArray['UNIQUE_ID'] = self::GetUniqueId();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -0,0 +1,216 @@
|
|||
<?php
|
||||
|
||||
class Application_Model_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;
|
||||
}
|
||||
}
|
|
@ -286,7 +286,7 @@ class Application_Model_ShowInstance {
|
|||
*/
|
||||
public function addPlaylistToShow($plId)
|
||||
{
|
||||
$sched = new ScheduleGroup();
|
||||
$sched = new Application_Model_ScheduleGroup();
|
||||
$lastGroupId = $this->getLastGroupId();
|
||||
|
||||
if (is_null($lastGroupId)) {
|
||||
|
@ -306,7 +306,7 @@ class Application_Model_ShowInstance {
|
|||
*/
|
||||
public function addFileToShow($file_id)
|
||||
{
|
||||
$sched = new ScheduleGroup();
|
||||
$sched = new Application_Model_ScheduleGroup();
|
||||
$lastGroupId = $this->getLastGroupId();
|
||||
|
||||
if (is_null($lastGroupId)) {
|
||||
|
@ -415,7 +415,7 @@ class Application_Model_ShowInstance {
|
|||
|
||||
$s_epoch = strtotime($start_timestamp);
|
||||
$e_epoch = strtotime($end_timestamp);
|
||||
$i_epoch = Schedule::WallTimeToMillisecs($time_filled) / 1000;
|
||||
$i_epoch = Application_Model_Schedule::WallTimeToMillisecs($time_filled) / 1000;
|
||||
|
||||
$percent = ceil(($i_epoch / ($e_epoch - $s_epoch)) * 100);
|
||||
|
||||
|
|
|
@ -338,7 +338,7 @@ class Application_Model_StoredFile {
|
|||
}
|
||||
|
||||
// Check if the file is scheduled to be played in the future
|
||||
if (Schedule::IsFileScheduledInTheFuture($this->getId())) {
|
||||
if (Application_Model_Schedule::IsFileScheduledInTheFuture($this->getId())) {
|
||||
return PEAR::raiseError('Cannot delete a file that is scheduled in the future.');
|
||||
}
|
||||
|
||||
|
|
|
@ -30,12 +30,12 @@ class SchedulerExportTests extends PHPUnit_TestCase {
|
|||
$result = $playlist->addAudioClip($this->storedFile2->getId());
|
||||
|
||||
// Schedule it
|
||||
$i = new ScheduleGroup();
|
||||
$i = new Application_Model_ScheduleGroup();
|
||||
$this->groupIdCreated = $i->add('2010-11-11 01:30:23', null, $playlist->getId());
|
||||
}
|
||||
|
||||
public function testExport() {
|
||||
echo Schedule::ExportRangeAsJson("2010-01-01 00:00:00", "2011-01-01 00:00:00");
|
||||
echo Application_Model_Schedule::ExportRangeAsJson("2010-01-01 00:00:00", "2011-01-01 00:00:00");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,14 +29,14 @@ class SchedulerTests extends PHPUnit_TestCase {
|
|||
|
||||
function testDateToId() {
|
||||
$dateStr = "2006-04-02 10:20:08.123456";
|
||||
$id = ScheduleGroup::dateToId($dateStr);
|
||||
$id = Application_Model_ScheduleGroup::dateToId($dateStr);
|
||||
$expected = "20060402102008123";
|
||||
if ($id != $expected) {
|
||||
$this->fail("Did not convert date to ID correctly #1: $id != $expected");
|
||||
}
|
||||
|
||||
$dateStr = "2006-04-02 10:20:08";
|
||||
$id = ScheduleGroup::dateToId($dateStr);
|
||||
$id = Application_Model_ScheduleGroup::dateToId($dateStr);
|
||||
$expected = "20060402102008000";
|
||||
if ($id != $expected) {
|
||||
$this->fail("Did not convert date to ID correctly #2: $id != $expected");
|
||||
|
@ -44,13 +44,13 @@ class SchedulerTests extends PHPUnit_TestCase {
|
|||
}
|
||||
|
||||
function testAddAndRemoveAudioFile() {
|
||||
$i = new ScheduleGroup();
|
||||
$i = new Application_Model_ScheduleGroup();
|
||||
$this->groupIdCreated = $i->add('2010-10-10 01:30:23', $this->storedFile->getId());
|
||||
if (PEAR::isError($this->groupIdCreated)) {
|
||||
$this->fail("Failed to create scheduled item: ". $this->groupIdCreated->getMessage());
|
||||
}
|
||||
|
||||
$i = new ScheduleGroup($this->groupIdCreated);
|
||||
$i = new Application_Model_ScheduleGroup($this->groupIdCreated);
|
||||
$result = $i->remove();
|
||||
if ($result != 1) {
|
||||
$this->fail("Did not remove item.");
|
||||
|
@ -65,12 +65,12 @@ class SchedulerTests extends PHPUnit_TestCase {
|
|||
$result = $playlist->addAudioClip($this->storedFile2->getId());
|
||||
$result = $playlist->addAudioClip($this->storedFile2->getId());
|
||||
|
||||
$i = new ScheduleGroup();
|
||||
$i = new Application_Model_ScheduleGroup();
|
||||
$this->groupIdCreated = $i->add('2010-11-11 01:30:23', null, $playlist->getId());
|
||||
if (PEAR::isError($this->groupIdCreated)) {
|
||||
$this->fail("Failed to create scheduled item: ". $this->groupIdCreated->getMessage());
|
||||
}
|
||||
$group = new ScheduleGroup($this->groupIdCreated);
|
||||
$group = new Application_Model_ScheduleGroup($this->groupIdCreated);
|
||||
if ($group->count() != 3) {
|
||||
$this->fail("Wrong number of items added.");
|
||||
}
|
||||
|
@ -88,13 +88,13 @@ class SchedulerTests extends PHPUnit_TestCase {
|
|||
}
|
||||
|
||||
function testIsScheduleEmptyInRange() {
|
||||
$i = new ScheduleGroup();
|
||||
$i = new Application_Model_ScheduleGroup();
|
||||
$this->groupIdCreated = $i->add('2011-10-10 01:30:23', $this->storedFile->getId());
|
||||
if (PEAR::isError($this->groupIdCreated)) {
|
||||
$this->fail($this->groupIdCreated->getMessage());
|
||||
return;
|
||||
}
|
||||
if (Schedule::isScheduleEmptyInRange('2011-10-10 01:30:23', '00:00:12.555')) {
|
||||
if (Application_Model_Schedule::isScheduleEmptyInRange('2011-10-10 01:30:23', '00:00:12.555')) {
|
||||
$this->fail("Reporting empty schedule when it isnt.");
|
||||
return;
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ class SchedulerTests extends PHPUnit_TestCase {
|
|||
$this->fail("Failed to delete schedule group.");
|
||||
return;
|
||||
}
|
||||
if (!Schedule::isScheduleEmptyInRange('2011-10-10 01:30:23', '00:00:12.555')) {
|
||||
if (!Application_Model_Schedule::isScheduleEmptyInRange('2011-10-10 01:30:23', '00:00:12.555')) {
|
||||
$this->fail("Reporting booked schedule when it isnt.");
|
||||
return;
|
||||
}
|
||||
|
@ -112,11 +112,11 @@ class SchedulerTests extends PHPUnit_TestCase {
|
|||
|
||||
/*
|
||||
function testGetItems() {
|
||||
$i1 = new ScheduleGroup();
|
||||
$i1 = new Application_Model_ScheduleGroup();
|
||||
$groupId1 = $i1->add('2008-01-01 12:00:00.000', $this->storedFile->getId());
|
||||
$i2 = new ScheduleGroup();
|
||||
$i2 = new Application_Model_ScheduleGroup();
|
||||
$i2->addAfter($groupId1, $this->storedFile->getId());
|
||||
$items = Schedule::GetItems("2008-01-01", "2008-01-02");
|
||||
$items = Application_Model_Schedule::GetItems("2008-01-01", "2008-01-02");
|
||||
if (count($items) != 2) {
|
||||
$this->fail("Wrong number of items returned.");
|
||||
return;
|
||||
|
|
|
@ -98,7 +98,7 @@ while ($showTime < $endDate) {
|
|||
}
|
||||
|
||||
if (RabbitMq::$doPush) {
|
||||
$md = array('schedule' => Schedule::GetScheduledPlaylists());
|
||||
$md = array('schedule' => Application_Model_Schedule::GetScheduledPlaylists());
|
||||
RabbitMq::SendMessageToPypo("update_schedule", $md);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue