Renamed ScheduleItem class to ScheduleGroup.
Added support for adding playlists to the scheduler. Also added count() and getItems() functions. Added "clip_length" to the scheduler database table, no doubt it will come in handy. Fixed bug in Playlist where it didnt remember it's own ID after creation. Updated documention for the playlist.
This commit is contained in:
parent
202fcbd254
commit
47e0233e47
|
@ -56,6 +56,8 @@ ALTER TABLE cc_schedule RENAME playlist TO playlist_id;
|
|||
ALTER TABLE cc_schedule ALTER playlist_id TYPE integer;
|
||||
ALTER TABLE cc_schedule ADD COLUMN group_id integer;
|
||||
ALTER TABLE cc_schedule ADD COLUMN file_id integer;
|
||||
ALTER TABLE cc_schedule
|
||||
ADD COLUMN clip_length time without time zone DEFAULT '00:00:00.000000';
|
||||
ALTER TABLE cc_schedule
|
||||
ADD COLUMN fade_in time without time zone DEFAULT '00:00:00.000';
|
||||
ALTER TABLE cc_schedule
|
||||
|
|
|
@ -62,7 +62,7 @@ class uiScheduler extends uiCalendar {
|
|||
private $availablePlaylists;
|
||||
|
||||
public $firstDayOfWeek;
|
||||
private $scriptError;
|
||||
private $scriptError;
|
||||
public $error;
|
||||
|
||||
|
||||
|
@ -298,9 +298,9 @@ class uiScheduler extends uiCalendar {
|
|||
{
|
||||
// build array within all entrys of current week
|
||||
$this->buildWeek();
|
||||
$thisWeekStart = strftime("%Y%m%d", $this->Week[0]['timestamp']);
|
||||
$nextWeekStart = strftime("%Y%m%d", $this->Week[6]['timestamp'] + 86400);
|
||||
$arr = $this->displayScheduleMethod($thisWeekStart.'T00:00:00', $nextWeekStart.'T00:00:00');
|
||||
$thisWeekStart = strftime("%Y-%m-%d", $this->Week[0]['timestamp']);
|
||||
$nextWeekStart = strftime("%Y-%m-%d", $this->Week[6]['timestamp'] + 86400);
|
||||
$arr = $this->displayScheduleMethod($thisWeekStart.' 00:00:00', $nextWeekStart.' 00:00:00');
|
||||
|
||||
if (!is_array($arr)) {
|
||||
return FALSE;
|
||||
|
@ -330,16 +330,16 @@ class uiScheduler extends uiCalendar {
|
|||
/**
|
||||
* Get all items scheduled for a given day.
|
||||
*
|
||||
* @return false|array
|
||||
* @return array|false
|
||||
*/
|
||||
public function getDayEntrys()
|
||||
{
|
||||
// build array within all entrys of current day
|
||||
$this->buildDay();
|
||||
$thisDay = strftime("%Y%m%d", $this->Day[0]['timestamp']);
|
||||
$nextDay = strftime("%Y%m%d", $this->Day[0]['timestamp'] + 86400);
|
||||
$arr = $this->displayScheduleMethod($thisDay.'T00:00:00', $nextDay.'T00:00:00');
|
||||
|
||||
$thisDay = strftime("%Y-%m-%d", $this->Day[0]['timestamp']);
|
||||
$nextDay = strftime("%Y-%m-%d", $this->Day[0]['timestamp'] + 86400);
|
||||
$arr = $this->displayScheduleMethod($thisDay.' 00:00:00', $nextDay.' 00:00:00');
|
||||
//$_SESSION["debug"] = $arr;
|
||||
if (!is_array($arr)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -440,8 +440,8 @@ class uiScheduler extends uiCalendar {
|
|||
/*
|
||||
function getDayHourlyEntrys($year, $month, $day)
|
||||
{
|
||||
$date = $year.$month.$day;
|
||||
$arr = $this->displayScheduleMethod($date.'T00:00:00', $date.'T23:59:59.999999');
|
||||
$date = $year.'-'.$month.'-'.$day;
|
||||
$arr = $this->displayScheduleMethod($date.' 00:00:00', $date.' 23:59:59.999999');
|
||||
if (!count($arr))
|
||||
return FALSE;
|
||||
foreach ($arr as $key => $val) {
|
||||
|
@ -460,8 +460,8 @@ class uiScheduler extends uiCalendar {
|
|||
private function getDayUsage($year, $month, $day)
|
||||
{
|
||||
$thisDay = $year.$month.$day;
|
||||
$nextDay = strftime("%Y%m%d", strtotime('+1 day', strtotime("$year-$month-$day")));
|
||||
$arr = $this->displayScheduleMethod($thisDay.'T00:00:00', $nextDay.'T00:00:00');
|
||||
$nextDay = strftime("%Y-%m-%d", strtotime('+1 day', strtotime("$year-$month-$day")));
|
||||
$arr = $this->displayScheduleMethod($thisDay.' 00:00:00', $nextDay.' 00:00:00');
|
||||
|
||||
if (!is_array($arr)) {
|
||||
return FALSE;
|
||||
|
@ -595,8 +595,8 @@ class uiScheduler extends uiCalendar {
|
|||
public function getScheduledPlaylist($p_playlist_nr=0, $p_period=3600)
|
||||
{
|
||||
$now = time();
|
||||
$start = strftime('%Y%m%dT%H:%M:%S', $now);
|
||||
$end = $p_playlist_nr ? strftime('%Y%m%dT%H:%M:%S', $now + $p_period) : strftime('%Y%m%dT%H:%M:%S', $now);
|
||||
$start = strftime('%Y-%m-%d %H:%M:%S', $now);
|
||||
$end = $p_playlist_nr ? strftime('%Y-%m-%d %H:%M:%S', $now + $p_period) : strftime('%Y-%m-%d %H:%M:%S', $now);
|
||||
$playlists = $this->displayScheduleMethod($start, $end);
|
||||
|
||||
if (!is_array($playlists) || !count($playlists)) {
|
||||
|
@ -803,8 +803,8 @@ class uiScheduler extends uiCalendar {
|
|||
|
||||
private function _receiveScheduledDays($dfrom, $dto)
|
||||
{
|
||||
$dfrom = $dfrom.'T00:00:00';
|
||||
$dto = $dto.'T23:59:59';
|
||||
$dfrom = $dfrom.' 00:00:00';
|
||||
$dto = $dto.' 23:59:59';
|
||||
if (($pArr = $this->displayScheduleMethod($dfrom, $dto)) === FALSE) {
|
||||
return array(FALSE);
|
||||
}
|
||||
|
@ -1033,14 +1033,17 @@ class uiScheduler extends uiCalendar {
|
|||
{
|
||||
$gunid = $formdata['playlist'];
|
||||
$datetime = $formdata['date']['Y']
|
||||
.'-'
|
||||
.sprintf('%02d', $formdata['date']['m'])
|
||||
.'-'
|
||||
.sprintf('%02d', $formdata['date']['d'])
|
||||
.' '.sprintf('%02d', $formdata['time']['H'])
|
||||
.':'.sprintf('%02d', $formdata['time']['i'])
|
||||
.':'.sprintf('%02d', $formdata['time']['s']);
|
||||
|
||||
$item = new ScheduleItem();
|
||||
$groupId = $item->add($datetime, $gunid);
|
||||
$item = new ScheduleGroup();
|
||||
$groupId = $item->add($datetime, null, $gunid);
|
||||
$_SESSION["debug"] = $groupId;
|
||||
return is_numeric($groupId);
|
||||
// $r = $this->spc->UploadPlaylistMethod($this->Base->sessid, $gunid, $datetime);
|
||||
// if ($this->_isError($r)) {
|
||||
|
@ -1060,7 +1063,7 @@ class uiScheduler extends uiCalendar {
|
|||
*/
|
||||
function removeFromScheduleMethod($p_groupId)
|
||||
{
|
||||
$item = new ScheduleItem($p_groupId);
|
||||
$item = new ScheduleGroup($p_groupId);
|
||||
$success = $item->remove();
|
||||
//$r = $this->spc->removeFromScheduleMethod($this->Base->sessid, $id);
|
||||
if (!$success) {
|
||||
|
@ -1077,14 +1080,16 @@ class uiScheduler extends uiCalendar {
|
|||
* Get the scheduled items between the $from and $to dates.
|
||||
*
|
||||
* @param string $from
|
||||
* In the format YYYMMDDTHH:MM:SS
|
||||
* In the format "YYYY-MM-DD HH:MM:SS.nnnnnn"
|
||||
* @param string $to
|
||||
* In the format YYYMMDDTHH:MM:SS
|
||||
* In the format "YYYY-MM-DD HH:MM:SS.nnnnnn"
|
||||
* @return array|false
|
||||
*/
|
||||
function displayScheduleMethod($from, $to)
|
||||
{
|
||||
// NOTE: Need to fix times.
|
||||
//$_SESSION["debug"] = "FROM: $from, TO: $to<br>";
|
||||
//$from = substr($from, 0, 4)."-".
|
||||
$items = Schedule::GetItems($from, $to);
|
||||
return $items;
|
||||
// $r = $this->spc->displayScheduleMethod($this->Base->sessid, $from, $to);
|
||||
|
|
|
@ -47,40 +47,40 @@ class Playlist {
|
|||
* @var timestamp
|
||||
*/
|
||||
private $mtime;
|
||||
|
||||
|
||||
/**
|
||||
* @var MetaData
|
||||
*/
|
||||
public $md;
|
||||
|
||||
|
||||
private $categories = array("dc:title" => "name", "dc:creator" => "creator", "dc:description" => "description", "dcterms:extent" => "length");
|
||||
|
||||
|
||||
|
||||
|
||||
public function __construct($p_gunid=NULL)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function Insert($p_values)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
// Create the StoredPlaylist object
|
||||
$storedPlaylist = new Playlist();
|
||||
$storedPlaylist->name = isset($p_values['filename']) ? $p_values['filename'] : date("H:i:s");
|
||||
|
||||
$storedPlaylist->name = isset($p_values['filename']) ? $p_values['filename'] : date("H:i:s");
|
||||
|
||||
// NOTE: POSTGRES-SPECIFIC KEYWORD "DEFAULT" BEING USED, WOULD BE "NULL" IN MYSQL
|
||||
$storedPlaylist->id = isset($p_values['id']) && is_integer($p_values['id'])?"'".$p_values['id']."'":'DEFAULT';
|
||||
|
||||
|
||||
// Insert record into the database
|
||||
$escapedName = pg_escape_string($storedPlaylist->name);
|
||||
|
||||
|
||||
$CC_DBC->query("BEGIN");
|
||||
$sql = "INSERT INTO ".$CC_CONFIG['playListTable']
|
||||
."(id, name, state, mtime)"
|
||||
." VALUES ({$storedPlaylist->id}, '{$escapedName}', "
|
||||
." 'incomplete', now())";
|
||||
|
||||
|
||||
$res = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($res)) {
|
||||
$CC_DBC->query("ROLLBACK");
|
||||
|
@ -89,31 +89,31 @@ class Playlist {
|
|||
|
||||
if (!is_integer($storedPlaylist->id)) {
|
||||
// NOTE: POSTGRES-SPECIFIC
|
||||
$sql = "SELECT currval('".$CC_CONFIG["playListSequence"]."_seq')";
|
||||
$sql = "SELECT currval('".$CC_CONFIG["playListSequence"]."_seq')";
|
||||
$storedPlaylist->id = $CC_DBC->getOne($sql);
|
||||
}
|
||||
|
||||
// Save state
|
||||
|
||||
// Save state
|
||||
$res = $storedPlaylist->setState('ready');
|
||||
|
||||
|
||||
// Commit changes
|
||||
$res = $CC_DBC->query("COMMIT");
|
||||
if (PEAR::isError($res)) {
|
||||
$CC_DBC->query("ROLLBACK");
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
// Recall the object to get all the proper values
|
||||
//$storedPlaylist = Playlist::Recall($storedPlaylist->id);
|
||||
return $storedPlaylist->id;
|
||||
}
|
||||
|
||||
|
||||
public static function Delete($id) {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
|
||||
$CC_DBC->query("BEGIN");
|
||||
$sql = "DELETE FROM ".$CC_CONFIG['playListTable']. " WHERE id='{$id}'";
|
||||
|
||||
|
||||
$res = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($res)) {
|
||||
$CC_DBC->query("ROLLBACK");
|
||||
|
@ -126,49 +126,50 @@ class Playlist {
|
|||
$CC_DBC->query("ROLLBACK");
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch instance of StoredPlaylist object.<br>
|
||||
* @param string $p_gunid
|
||||
* global unique id of file
|
||||
* @return StoredFile|Playlist|NULL
|
||||
* Fetch instance of Playlist object.<br>
|
||||
*
|
||||
* @param string $id
|
||||
* DB id of file
|
||||
* @return Playlist|NULL
|
||||
* Return NULL if the object doesnt exist in the DB.
|
||||
*/
|
||||
public static function Recall($id) {
|
||||
|
||||
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
|
||||
|
||||
$escapedID = pg_escape_string($id);
|
||||
|
||||
|
||||
$sql = "SELECT id,"
|
||||
." name, state, currentlyaccessing, editedby, "
|
||||
." mtime"
|
||||
." FROM ".$CC_CONFIG['playListTable']
|
||||
." WHERE id ='{$escapedID}'";
|
||||
$row = $CC_DBC->getRow($sql);
|
||||
|
||||
|
||||
if (PEAR::isError($row)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (is_null($row)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
$storedPlaylist = new Playlist($id);
|
||||
|
||||
|
||||
$storedPlaylist->id = $row['id'];
|
||||
$storedPlaylist->name = $row['name'];
|
||||
$storedPlaylist->state = $row['state'];
|
||||
$storedPlaylist->currentlyaccessing = $row['currentlyaccessing'];
|
||||
$storedPlaylist->editedby = $row['editedby'];
|
||||
$storedPlaylist->mtime = $row['mtime'];
|
||||
|
||||
|
||||
return $storedPlaylist;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Rename stored virtual playlist
|
||||
*
|
||||
|
@ -189,7 +190,7 @@ class Playlist {
|
|||
$this->name = $p_newname;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get mnemonic playlist name
|
||||
*
|
||||
|
@ -207,7 +208,7 @@ class Playlist {
|
|||
." WHERE id='$id'";
|
||||
return $CC_DBC->getOne($sql);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set state of virtual playlist
|
||||
*
|
||||
|
@ -233,7 +234,7 @@ class Playlist {
|
|||
$this->editedby = $p_editedby;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get storage-internal file state
|
||||
*
|
||||
|
@ -252,7 +253,7 @@ class Playlist {
|
|||
." WHERE id='$id'";
|
||||
return $CC_DBC->getOne($sql);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO have to change this.
|
||||
* */
|
||||
|
@ -269,7 +270,7 @@ class Playlist {
|
|||
return $scheduled;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if virtual file is currently in use.<br>
|
||||
* Static or dynamic call is possible.
|
||||
|
@ -295,7 +296,7 @@ class Playlist {
|
|||
}
|
||||
return ($ca > 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns id of user editing playlist
|
||||
*
|
||||
|
@ -304,13 +305,13 @@ class Playlist {
|
|||
* @return int id of user editing playlist
|
||||
*/
|
||||
public function isEdited() {
|
||||
|
||||
if($this->state === 'edited') {
|
||||
|
||||
if($this->state === 'edited') {
|
||||
return $this->editedby;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set playlist edit flag
|
||||
*
|
||||
|
@ -325,16 +326,16 @@ class Playlist {
|
|||
* @return boolean
|
||||
* TRUE on success.
|
||||
*/
|
||||
|
||||
|
||||
public function setEditFlag($p_val=TRUE, $p_sessid=NULL, $p_subjid=NULL) {
|
||||
|
||||
|
||||
if (!is_null($p_sessid)) {
|
||||
$p_subjid = Alib::GetSessUserId($p_sessid);
|
||||
if (PEAR::isError($p_subjid)) {
|
||||
return $p_subjid;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$state = $this->state;
|
||||
if ($p_val) {
|
||||
$r = $this->setState('edited', $p_subjid);
|
||||
|
@ -346,7 +347,7 @@ class Playlist {
|
|||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return local ID of virtual file.
|
||||
*
|
||||
|
@ -355,53 +356,51 @@ class Playlist {
|
|||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
|
||||
private function getNextPos() {
|
||||
|
||||
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$sql = "SELECT MAX(position) AS nextPos
|
||||
|
||||
$sql = "SELECT MAX(position) AS nextPos
|
||||
FROM cc_playlistcontents
|
||||
WHERE playlist_id='{$this->getId()}'";
|
||||
|
||||
|
||||
$res = $CC_DBC->getOne($sql);
|
||||
|
||||
|
||||
if(is_null($res))
|
||||
return 0;
|
||||
|
||||
|
||||
if(PEAR::isError($res)){
|
||||
return $res;
|
||||
}
|
||||
|
||||
return $res + 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the entire playlist as a two dimentional array, sorted in order of play.
|
||||
* @return array
|
||||
*/
|
||||
public function getContents() {
|
||||
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM cc_playlistcontents C JOIN cc_files F ON C.file_id = F.id
|
||||
$sql = "SELECT *
|
||||
FROM cc_playlistcontents C JOIN cc_files F ON C.file_id = F.id
|
||||
WHERE C.playlist_id='{$this->getId()}' ORDER BY C.position";
|
||||
|
||||
return $CC_DBC->getAll($sql);
|
||||
}
|
||||
|
||||
|
||||
public function getLength() {
|
||||
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$sql = "SELECT SUM(cliplength) AS length FROM ".$CC_CONFIG['playListContentsTable']
|
||||
." WHERE playlist_id='{$this->getId()}' group by playlist_id";
|
||||
|
||||
$res = $CC_DBC->getRow($sql);
|
||||
if (PEAR::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
if(is_null($res))
|
||||
return '00:00:00.000000';
|
||||
|
||||
|
||||
return $res['length'];
|
||||
}
|
||||
|
||||
|
@ -419,8 +418,8 @@ class Playlist {
|
|||
if (PEAR::isError($pl_id)) {
|
||||
return $pl_id;
|
||||
}
|
||||
|
||||
return $pl_id;
|
||||
$this->id = $pl_id;
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -448,7 +447,7 @@ class Playlist {
|
|||
|
||||
|
||||
/**
|
||||
* Unlock playlist
|
||||
* Unlock playlist
|
||||
*
|
||||
* @param sessId
|
||||
* reference to GreenBox object
|
||||
|
@ -456,37 +455,33 @@ class Playlist {
|
|||
* previous state or error object
|
||||
*/
|
||||
public function unlock($sessid)
|
||||
{
|
||||
{
|
||||
$r = $this->lock($sessid, NULL, FALSE);
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add audioClip specified by local id to the playlist
|
||||
* Add audio clip to the playlist
|
||||
*
|
||||
* @param string $acId
|
||||
* @param string $p_id
|
||||
* local ID of added file
|
||||
* @param string $fadeIn
|
||||
* @param string $p_position
|
||||
* optional, Which position in the playlist to insert the audio clip
|
||||
* @param string $p_fadeIn
|
||||
* optional, in time format hh:mm:ss.ssssss - total duration
|
||||
* @param string $fadeOut
|
||||
* @param string $p_fadeOut
|
||||
* optional, in time format hh:mm:ss.ssssss - total duration
|
||||
* @param string $plElGunid
|
||||
* optional playlist element gunid
|
||||
* @param string $length
|
||||
* @param string $p_clipLength
|
||||
* optional length in in time format hh:mm:ss.ssssss -
|
||||
* for webstream (or for overrule length of audioclip)
|
||||
* @param string $clipstart
|
||||
* optional clipstart in time format hh:mm:ss.ssssss - relative to begin
|
||||
* @param string $clipend
|
||||
* optional $clipend in time format hh:mm:ss.ssssss - relative to begin
|
||||
* @return string
|
||||
* generated playlistElement gunid
|
||||
* @return true|PEAR_Error
|
||||
* TRUE on success
|
||||
*/
|
||||
public function addAudioClip($acId, $pos=NULL, $fadeIn=NULL, $fadeOut=NULL, $cliplength=NULL, $cuein=NULL, $cueout=NULL)
|
||||
public function addAudioClip($p_id, $p_position=NULL, $p_fadeIn=NULL, $p_fadeOut=NULL, $p_clipLength=NULL, $p_cuein=NULL, $p_cueout=NULL)
|
||||
{
|
||||
//get audio clip.
|
||||
$ac = StoredFile::Recall($acId);
|
||||
$ac = StoredFile::Recall($p_id);
|
||||
if (is_null($ac) || PEAR::isError($ac)) {
|
||||
return $ac;
|
||||
}
|
||||
|
@ -496,31 +491,31 @@ class Playlist {
|
|||
return $acInfo;
|
||||
}
|
||||
extract($acInfo); // 'acGunid', 'acLen', 'acTit', 'elType'
|
||||
if (!is_null($cliplength)) {
|
||||
$acLen = $cliplength;
|
||||
if (!is_null($p_clipLength)) {
|
||||
$acLen = $p_clipLength;
|
||||
}
|
||||
|
||||
//insert at end of playlist.
|
||||
if(is_null($pos))
|
||||
$pos = $this->getNextPos();
|
||||
if (PEAR::isError($pos)) {
|
||||
return $pos;
|
||||
|
||||
// insert at end of playlist.
|
||||
if (is_null($p_position))
|
||||
$p_position = $this->getNextPos();
|
||||
if (PEAR::isError($p_position)) {
|
||||
return $p_position;
|
||||
}
|
||||
|
||||
|
||||
// insert default values if parameter was empty
|
||||
$cuein = !is_null($cuein) ? $cuein : '00:00:00.000000';
|
||||
$cueout = !is_null($cueout) ? $cueout : $acLen;
|
||||
$p_cuein = !is_null($p_cuein) ? $p_cuein : '00:00:00.000000';
|
||||
$p_cueout = !is_null($p_cueout) ? $p_cueout : $acLen;
|
||||
|
||||
$acLengthS = $clipLengthS = self::playlistTimeToSeconds($acLen);
|
||||
if (!is_null($cuein)) {
|
||||
$clipLengthS = $acLengthS - self::playlistTimeToSeconds($cuein);
|
||||
if (!is_null($p_cuein)) {
|
||||
$clipLengthS = $acLengthS - self::playlistTimeToSeconds($p_cuein);
|
||||
}
|
||||
if (!is_null($cueout)) {
|
||||
$clipLengthS = $clipLengthS - ($acLengthS - self::playlistTimeToSeconds($cueout));
|
||||
if (!is_null($p_cueout)) {
|
||||
$clipLengthS = $clipLengthS - ($acLengthS - self::playlistTimeToSeconds($p_cueout));
|
||||
}
|
||||
$clipLength = self::secondsToPlaylistTime($clipLengthS);
|
||||
$p_clipLength = self::secondsToPlaylistTime($clipLengthS);
|
||||
|
||||
$res = $this->insertPlaylistElement($this->getId(), $acId, $pos, $clipLength, $cuein, $cueout, $fadeIn, $fadeOut);
|
||||
$res = $this->insertPlaylistElement($this->getId(), $p_id, $p_position, $p_clipLength, $p_cuein, $p_cueout, $p_fadeIn, $p_fadeOut);
|
||||
if (PEAR::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
|
@ -538,10 +533,10 @@ class Playlist {
|
|||
public function delAudioClip($pos)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
|
||||
$CC_DBC->query("BEGIN");
|
||||
$sql = "DELETE FROM ".$CC_CONFIG['playListContentsTable']. " WHERE playlist_id='{$this->getId()}' AND position='{$pos}'";
|
||||
|
||||
|
||||
$res = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($res)) {
|
||||
$CC_DBC->query("ROLLBACK");
|
||||
|
@ -554,10 +549,10 @@ class Playlist {
|
|||
$CC_DBC->query("ROLLBACK");
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move audioClip to the new position in the playlist
|
||||
*
|
||||
|
@ -570,10 +565,10 @@ class Playlist {
|
|||
public function moveAudioClip($oldPos, $newPos)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
|
||||
$CC_DBC->query("BEGIN");
|
||||
$sql = "SELECT * FROM ".$CC_CONFIG['playListContentsTable']. " WHERE playlist_id='{$this->getId()}' AND position='{$oldPos}'";
|
||||
|
||||
|
||||
$ac = $CC_DBC->getRow($sql);
|
||||
if (PEAR::isError($ac)) {
|
||||
return $ac;
|
||||
|
@ -582,11 +577,11 @@ class Playlist {
|
|||
$res = $this->delAudioClip($oldPos);
|
||||
if($res !== TRUE)
|
||||
return FALSE;
|
||||
|
||||
|
||||
$res = $this->addAudioClip($ac['file_id'], $newPos, $ac['fadein'], $ac['fadeOut'], $ac['cliplength'], $ac['cuein'], $ac['cueout']);
|
||||
if($res !== TRUE)
|
||||
return FALSE;
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -605,11 +600,11 @@ class Playlist {
|
|||
public function changeFadeInfo($pos, $fadeIn, $fadeOut)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
|
||||
$CC_DBC->query("BEGIN");
|
||||
$sql = "UPDATE ".$CC_CONFIG['playListContentsTable']. " SET fadein='{$fadeIn}', fadeout='{$fadeOut}' " .
|
||||
$sql = "UPDATE ".$CC_CONFIG['playListContentsTable']. " SET fadein='{$fadeIn}', fadeout='{$fadeOut}' " .
|
||||
"WHERE playlist_id='{$this->getId()}' AND position='{$pos}'";
|
||||
|
||||
|
||||
$res = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($res)) {
|
||||
$CC_DBC->query("ROLLBACK");
|
||||
|
@ -622,7 +617,7 @@ class Playlist {
|
|||
$CC_DBC->query("ROLLBACK");
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -640,11 +635,11 @@ class Playlist {
|
|||
public function changeClipLength($pos, $cueIn, $cueOut)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
|
||||
$CC_DBC->query("BEGIN");
|
||||
$sql = "UPDATE ".$CC_CONFIG['playListContentsTable']. " SET cuein='{$cueIn}', cueout='{$cueOut}' " .
|
||||
$sql = "UPDATE ".$CC_CONFIG['playListContentsTable']. " SET cuein='{$cueIn}', cueout='{$cueOut}' " .
|
||||
"WHERE playlist_id='{$this->getId()}' AND position='{$pos}'";
|
||||
|
||||
|
||||
$res = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($res)) {
|
||||
$CC_DBC->query("ROLLBACK");
|
||||
|
@ -657,7 +652,7 @@ class Playlist {
|
|||
$CC_DBC->query("ROLLBACK");
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -678,21 +673,21 @@ class Playlist {
|
|||
*/
|
||||
public function getPlaylistClipAtPosition($pos)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getPLMetaData($category)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$cat = $this->categories[$category];
|
||||
if($cat === 'length') {
|
||||
return $this->getLength();
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT {$cat} AS mdata FROM ".$CC_CONFIG['playListTable'].
|
||||
" WHERE id='{$this->getId()}'";
|
||||
|
||||
|
||||
$res = $CC_DBC->getOne($sql);
|
||||
if (PEAR::isError($res)) {
|
||||
return FALSE;
|
||||
|
@ -700,16 +695,16 @@ class Playlist {
|
|||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
public function setPLMetaData($category, $value)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$cat = $this->categories[$category];
|
||||
|
||||
$sql = "UPDATE ".$CC_CONFIG['playListTable']. " SET {$cat}='{$value}'" .
|
||||
|
||||
$sql = "UPDATE ".$CC_CONFIG['playListTable']. " SET {$cat}='{$value}'" .
|
||||
" WHERE id='{$this->getId()}'";
|
||||
|
||||
|
||||
$res = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($res)) {
|
||||
return $res;
|
||||
|
@ -1001,15 +996,15 @@ class Playlist {
|
|||
private function getAudioClipInfo($ac)
|
||||
{
|
||||
$ac_id = BasicStor::IdFromGunid($ac->gunid);
|
||||
|
||||
$r = $ac->md['dcterms:extent'];
|
||||
|
||||
$r = $ac->md['dcterms:extent'];
|
||||
if (isset($r)) {
|
||||
$acLen = $r;
|
||||
} else {
|
||||
$acLen = '00:00:00.000000';
|
||||
}
|
||||
|
||||
$r = $ac->md['dc:title'];
|
||||
|
||||
$r = $ac->md['dc:title'];
|
||||
if (isset($r)) {
|
||||
$acTit = $r;
|
||||
} else {
|
||||
|
@ -1018,7 +1013,7 @@ class Playlist {
|
|||
$elType = BasicStor::GetObjType($ac_id);
|
||||
$trTbl = array('audioclip'=>'audioClip', 'webstream'=>'audioClip','playlist'=>'playlist');
|
||||
$elType = $trTbl[$elType];
|
||||
|
||||
|
||||
return compact('acGunid', 'acLen', 'acTit', 'elType');
|
||||
}
|
||||
|
||||
|
@ -1132,7 +1127,7 @@ class Playlist {
|
|||
* fadeIn value in ss.ssssss or extent format
|
||||
* @param string $fadeOut
|
||||
* fadeOut value in ss.ssssss or extent format
|
||||
|
||||
|
||||
* @return array with fields:
|
||||
* <ul>
|
||||
* <li>plElId int - record id of playlistElement</li>
|
||||
|
@ -1144,17 +1139,17 @@ class Playlist {
|
|||
private function insertPlaylistElement($plId, $fileId, $pos, $clipLength, $cuein, $cueout, $fadeIn=NULL, $fadeOut=NULL)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
|
||||
if(is_null($fadeIn))
|
||||
$fadeIn = '00:00:00.000';
|
||||
if(is_null($fadeOut))
|
||||
$fadeOut = '00:00:00.000';
|
||||
|
||||
|
||||
$CC_DBC->query("BEGIN");
|
||||
$sql = "INSERT INTO ".$CC_CONFIG['playListContentsTable']
|
||||
. "(playlist_id, file_id, position, cliplength, cuein, cueout, fadein, fadeout)"
|
||||
. "VALUES ('{$plId}', '{$fileId}', '{$pos}', '{$clipLength}', '{$cuein}', '{$cueout}', '{$fadeIn}', '{$fadeOut}')";
|
||||
|
||||
|
||||
$res = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($res)) {
|
||||
$CC_DBC->query("ROLLBACK");
|
||||
|
@ -1167,7 +1162,7 @@ class Playlist {
|
|||
$CC_DBC->query("ROLLBACK");
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
class ScheduleItem {
|
||||
class ScheduleGroup {
|
||||
|
||||
private $groupId;
|
||||
|
||||
|
@ -46,10 +46,15 @@ class ScheduleItem {
|
|||
/**
|
||||
* Add a music clip or playlist to the schedule.
|
||||
*
|
||||
* @param $p_audioFileId
|
||||
* @param $p_playlistId
|
||||
* @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.
|
||||
*/
|
||||
|
@ -78,9 +83,10 @@ class ScheduleItem {
|
|||
$this->groupId = $CC_DBC->GetOne("SELECT nextval('schedule_group_id_seq')");
|
||||
$id = $this->dateToId($p_datetime);
|
||||
$sql = "INSERT INTO ".$CC_CONFIG["scheduleTable"]
|
||||
." (id, playlist_id, starts, ends, group_id, file_id)"
|
||||
." (id, playlist_id, starts, ends, clip_length, group_id, file_id)"
|
||||
." VALUES ($id, 0, TIMESTAMP '$p_datetime', "
|
||||
." (TIMESTAMP '$p_datetime' + INTERVAL '$length'),"
|
||||
." '$length',"
|
||||
." {$this->groupId}, $p_audioFileId)";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
|
@ -91,9 +97,47 @@ class ScheduleItem {
|
|||
|
||||
} elseif (!is_null($p_playlistId)){
|
||||
// Schedule a whole playlist
|
||||
}
|
||||
|
||||
// return group ID
|
||||
// Load existing playlist
|
||||
$playlist = 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());
|
||||
if (empty($length)) {
|
||||
return new PEAR_Error("Length is empty.");
|
||||
}
|
||||
if (!Schedule::isScheduleEmptyInRange($p_datetime, $length)) {
|
||||
return new PEAR_Error("Schedule conflict.");
|
||||
}
|
||||
|
||||
// Insert all items into the schedule
|
||||
$this->groupId = $CC_DBC->GetOne("SELECT nextval('schedule_group_id_seq')");
|
||||
$id = $this->dateToId($p_datetime);
|
||||
$itemStartTime = $p_datetime;
|
||||
|
||||
$plItems = $playlist->getContents();
|
||||
foreach ($plItems as $row) {
|
||||
$trackLength = $row["cliplength"];
|
||||
$sql = "INSERT INTO ".$CC_CONFIG["scheduleTable"]
|
||||
." (id, playlist_id, starts, ends, group_id, file_id,"
|
||||
." clip_length, cue_in, cue_out, fade_in, fade_out)"
|
||||
." VALUES ($id, $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'");
|
||||
$id = $this->dateToId($itemStartTime);
|
||||
}
|
||||
return $this->groupId;
|
||||
}
|
||||
}
|
||||
|
||||
public function addAfter($p_groupId, $p_audioFileId) {
|
||||
|
@ -126,6 +170,28 @@ class ScheduleItem {
|
|||
return $CC_DBC->query($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 * FROM {$CC_CONFIG['scheduleTable']}"
|
||||
." WHERE group_id={$this->groupId}";
|
||||
return $CC_DBC->GetAll($sql);
|
||||
}
|
||||
|
||||
public function reschedule($toDateTime) {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
// $sql = "UPDATE ".$CC_CONFIG["scheduleTable"]. " SET id=, starts=,ends="
|
||||
|
|
|
@ -403,6 +403,7 @@ if (!camp_db_table_exists($CC_CONFIG['scheduleTable'])) {
|
|||
." ends timestamp without time zone NOT NULL,"
|
||||
." group_id integer,"
|
||||
." file_id integer,"
|
||||
." clip_length time without time zone DEFAULT '00:00:00'::time without time zone,"
|
||||
." fade_in time without time zone DEFAULT '00:00:00'::time without time zone,"
|
||||
." fade_out time without time zone DEFAULT '00:00:00'::time without time zone,"
|
||||
." cue_in time without time zone DEFAULT '00:00:00'::time without time zone,"
|
||||
|
|
|
@ -106,7 +106,7 @@ if (camp_db_table_exists($CC_CONFIG['filesTable'])) {
|
|||
|
||||
if (camp_db_table_exists($CC_CONFIG['playListTable'])) {
|
||||
echo " * Removing database table ".$CC_CONFIG['playListTable']."...";
|
||||
$sql = "DROP TABLE ".$CC_CONFIG['playListTable'];
|
||||
$sql = "DROP TABLE ".$CC_CONFIG['playListTable']." CASCADE";
|
||||
camp_install_query($sql);
|
||||
$CC_DBC->dropSequence($CC_CONFIG['playListTable']."_id");
|
||||
|
||||
|
|
|
@ -4,11 +4,12 @@ require_once('DB.php');
|
|||
require_once('PHPUnit.php');
|
||||
require_once 'BasicStorTests.php';
|
||||
require_once 'SchedulerTests.php';
|
||||
//require_once 'PlayListTests.php';
|
||||
require_once 'PlayListTests.php';
|
||||
|
||||
$suite = new PHPUnit_TestSuite("BasicStorTest");
|
||||
//$suite = new PHPUnit_TestSuite("SchedulerTests");
|
||||
$suite->addTestSuite("SchedulerTests");
|
||||
//$suite->addTestSuite("PlayListTests");
|
||||
$suite->addTestSuite("PlayListTests");
|
||||
$result = PHPUnit::run($suite);
|
||||
|
||||
echo $result->toString();
|
||||
|
|
|
@ -5,6 +5,7 @@ class SchedulerTests extends PHPUnit_TestCase {
|
|||
|
||||
private $groupIdCreated;
|
||||
private $storedFile;
|
||||
private $storedFile2;
|
||||
|
||||
function setup() {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
@ -17,6 +18,10 @@ class SchedulerTests extends PHPUnit_TestCase {
|
|||
$values = array("filepath" => dirname(__FILE__)."/test10001.mp3");
|
||||
$this->storedFile = StoredFile::Insert($values, false);
|
||||
|
||||
// Add a file
|
||||
$values = array("filepath" => dirname(__FILE__)."/test10002.mp3");
|
||||
$this->storedFile2 = StoredFile::Insert($values, false);
|
||||
|
||||
// Clear the schedule table
|
||||
$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"];
|
||||
$CC_DBC->query($sql);
|
||||
|
@ -24,36 +29,67 @@ class SchedulerTests extends PHPUnit_TestCase {
|
|||
|
||||
function testDateToId() {
|
||||
$dateStr = "2006-04-02 10:20:08.123456";
|
||||
$id = ScheduleItem::dateToId($dateStr);
|
||||
$id = 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 = ScheduleItem::dateToId($dateStr);
|
||||
$id = ScheduleGroup::dateToId($dateStr);
|
||||
$expected = "20060402102008000";
|
||||
if ($id != $expected) {
|
||||
$this->fail("Did not convert date to ID correctly #2: $id != $expected");
|
||||
}
|
||||
}
|
||||
|
||||
function testAddAndRemove() {
|
||||
$i = new ScheduleItem();
|
||||
function testAddAndRemoveAudioFile() {
|
||||
$i = new 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 ScheduleItem($this->groupIdCreated);
|
||||
$i = new ScheduleGroup($this->groupIdCreated);
|
||||
$result = $i->remove();
|
||||
if ($result != 1) {
|
||||
$this->fail("Did not remove item.");
|
||||
}
|
||||
}
|
||||
|
||||
function testAddAndRemovePlaylist() {
|
||||
// Create a playlist
|
||||
$playlist = new Playlist();
|
||||
$playlist->create("Scheduler Unit Test");
|
||||
$result = $playlist->addAudioClip($this->storedFile->getId());
|
||||
$result = $playlist->addAudioClip($this->storedFile2->getId());
|
||||
$result = $playlist->addAudioClip($this->storedFile2->getId());
|
||||
|
||||
$i = new 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);
|
||||
if ($group->count() != 3) {
|
||||
$this->fail("Wrong number of items added.");
|
||||
}
|
||||
$items = $group->getItems();
|
||||
if ($items[1]["starts"] != "2010-11-11 01:30:34.231") {
|
||||
$this->fail("Wrong start time for 2nd item.");
|
||||
}
|
||||
|
||||
$result = $group->remove();
|
||||
if ($result != 1) {
|
||||
$this->fail("Did not remove item.");
|
||||
}
|
||||
|
||||
Playlist::Delete($playlist->getId());
|
||||
}
|
||||
|
||||
function testIsScheduleEmptyInRange() {
|
||||
$i = new ScheduleItem();
|
||||
$i = new ScheduleGroup();
|
||||
$this->groupIdCreated = $i->add('2011-10-10 01:30:23', $this->storedFile->getId());
|
||||
if (Schedule::isScheduleEmptyInRange('2011-10-10 01:30:23', '00:00:01.432153')) {
|
||||
$this->fail("Reporting empty schedule when it isnt.");
|
||||
|
@ -65,9 +101,9 @@ class SchedulerTests extends PHPUnit_TestCase {
|
|||
}
|
||||
|
||||
function testGetItems() {
|
||||
$i1 = new ScheduleItem();
|
||||
$i1 = new ScheduleGroup();
|
||||
$groupId1 = $i1->add('2008-01-01 12:00:00.000', $this->storedFile->getId());
|
||||
$i2 = new ScheduleItem();
|
||||
$i2 = new ScheduleGroup();
|
||||
$i2->addAfter($groupId1, $this->storedFile->getId());
|
||||
$items = Schedule::GetItems("2008-01-01", "2008-01-02");
|
||||
if (count($items) != 2) {
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue