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 ALTER playlist_id TYPE integer;
|
||||||
ALTER TABLE cc_schedule ADD COLUMN group_id 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 file_id integer;
|
||||||
|
ALTER TABLE cc_schedule
|
||||||
|
ADD COLUMN clip_length time without time zone DEFAULT '00:00:00.000000';
|
||||||
ALTER TABLE cc_schedule
|
ALTER TABLE cc_schedule
|
||||||
ADD COLUMN fade_in time without time zone DEFAULT '00:00:00.000';
|
ADD COLUMN fade_in time without time zone DEFAULT '00:00:00.000';
|
||||||
ALTER TABLE cc_schedule
|
ALTER TABLE cc_schedule
|
||||||
|
|
|
@ -298,9 +298,9 @@ class uiScheduler extends uiCalendar {
|
||||||
{
|
{
|
||||||
// build array within all entrys of current week
|
// build array within all entrys of current week
|
||||||
$this->buildWeek();
|
$this->buildWeek();
|
||||||
$thisWeekStart = strftime("%Y%m%d", $this->Week[0]['timestamp']);
|
$thisWeekStart = strftime("%Y-%m-%d", $this->Week[0]['timestamp']);
|
||||||
$nextWeekStart = strftime("%Y%m%d", $this->Week[6]['timestamp'] + 86400);
|
$nextWeekStart = strftime("%Y-%m-%d", $this->Week[6]['timestamp'] + 86400);
|
||||||
$arr = $this->displayScheduleMethod($thisWeekStart.'T00:00:00', $nextWeekStart.'T00:00:00');
|
$arr = $this->displayScheduleMethod($thisWeekStart.' 00:00:00', $nextWeekStart.' 00:00:00');
|
||||||
|
|
||||||
if (!is_array($arr)) {
|
if (!is_array($arr)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -330,16 +330,16 @@ class uiScheduler extends uiCalendar {
|
||||||
/**
|
/**
|
||||||
* Get all items scheduled for a given day.
|
* Get all items scheduled for a given day.
|
||||||
*
|
*
|
||||||
* @return false|array
|
* @return array|false
|
||||||
*/
|
*/
|
||||||
public function getDayEntrys()
|
public function getDayEntrys()
|
||||||
{
|
{
|
||||||
// build array within all entrys of current day
|
// build array within all entrys of current day
|
||||||
$this->buildDay();
|
$this->buildDay();
|
||||||
$thisDay = strftime("%Y%m%d", $this->Day[0]['timestamp']);
|
$thisDay = strftime("%Y-%m-%d", $this->Day[0]['timestamp']);
|
||||||
$nextDay = strftime("%Y%m%d", $this->Day[0]['timestamp'] + 86400);
|
$nextDay = strftime("%Y-%m-%d", $this->Day[0]['timestamp'] + 86400);
|
||||||
$arr = $this->displayScheduleMethod($thisDay.'T00:00:00', $nextDay.'T00:00:00');
|
$arr = $this->displayScheduleMethod($thisDay.' 00:00:00', $nextDay.' 00:00:00');
|
||||||
|
//$_SESSION["debug"] = $arr;
|
||||||
if (!is_array($arr)) {
|
if (!is_array($arr)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -440,8 +440,8 @@ class uiScheduler extends uiCalendar {
|
||||||
/*
|
/*
|
||||||
function getDayHourlyEntrys($year, $month, $day)
|
function getDayHourlyEntrys($year, $month, $day)
|
||||||
{
|
{
|
||||||
$date = $year.$month.$day;
|
$date = $year.'-'.$month.'-'.$day;
|
||||||
$arr = $this->displayScheduleMethod($date.'T00:00:00', $date.'T23:59:59.999999');
|
$arr = $this->displayScheduleMethod($date.' 00:00:00', $date.' 23:59:59.999999');
|
||||||
if (!count($arr))
|
if (!count($arr))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
foreach ($arr as $key => $val) {
|
foreach ($arr as $key => $val) {
|
||||||
|
@ -460,8 +460,8 @@ class uiScheduler extends uiCalendar {
|
||||||
private function getDayUsage($year, $month, $day)
|
private function getDayUsage($year, $month, $day)
|
||||||
{
|
{
|
||||||
$thisDay = $year.$month.$day;
|
$thisDay = $year.$month.$day;
|
||||||
$nextDay = strftime("%Y%m%d", strtotime('+1 day', strtotime("$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');
|
$arr = $this->displayScheduleMethod($thisDay.' 00:00:00', $nextDay.' 00:00:00');
|
||||||
|
|
||||||
if (!is_array($arr)) {
|
if (!is_array($arr)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -595,8 +595,8 @@ class uiScheduler extends uiCalendar {
|
||||||
public function getScheduledPlaylist($p_playlist_nr=0, $p_period=3600)
|
public function getScheduledPlaylist($p_playlist_nr=0, $p_period=3600)
|
||||||
{
|
{
|
||||||
$now = time();
|
$now = time();
|
||||||
$start = strftime('%Y%m%dT%H:%M:%S', $now);
|
$start = strftime('%Y-%m-%d %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);
|
$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);
|
$playlists = $this->displayScheduleMethod($start, $end);
|
||||||
|
|
||||||
if (!is_array($playlists) || !count($playlists)) {
|
if (!is_array($playlists) || !count($playlists)) {
|
||||||
|
@ -803,8 +803,8 @@ class uiScheduler extends uiCalendar {
|
||||||
|
|
||||||
private function _receiveScheduledDays($dfrom, $dto)
|
private function _receiveScheduledDays($dfrom, $dto)
|
||||||
{
|
{
|
||||||
$dfrom = $dfrom.'T00:00:00';
|
$dfrom = $dfrom.' 00:00:00';
|
||||||
$dto = $dto.'T23:59:59';
|
$dto = $dto.' 23:59:59';
|
||||||
if (($pArr = $this->displayScheduleMethod($dfrom, $dto)) === FALSE) {
|
if (($pArr = $this->displayScheduleMethod($dfrom, $dto)) === FALSE) {
|
||||||
return array(FALSE);
|
return array(FALSE);
|
||||||
}
|
}
|
||||||
|
@ -1033,14 +1033,17 @@ class uiScheduler extends uiCalendar {
|
||||||
{
|
{
|
||||||
$gunid = $formdata['playlist'];
|
$gunid = $formdata['playlist'];
|
||||||
$datetime = $formdata['date']['Y']
|
$datetime = $formdata['date']['Y']
|
||||||
|
.'-'
|
||||||
.sprintf('%02d', $formdata['date']['m'])
|
.sprintf('%02d', $formdata['date']['m'])
|
||||||
|
.'-'
|
||||||
.sprintf('%02d', $formdata['date']['d'])
|
.sprintf('%02d', $formdata['date']['d'])
|
||||||
.' '.sprintf('%02d', $formdata['time']['H'])
|
.' '.sprintf('%02d', $formdata['time']['H'])
|
||||||
.':'.sprintf('%02d', $formdata['time']['i'])
|
.':'.sprintf('%02d', $formdata['time']['i'])
|
||||||
.':'.sprintf('%02d', $formdata['time']['s']);
|
.':'.sprintf('%02d', $formdata['time']['s']);
|
||||||
|
|
||||||
$item = new ScheduleItem();
|
$item = new ScheduleGroup();
|
||||||
$groupId = $item->add($datetime, $gunid);
|
$groupId = $item->add($datetime, null, $gunid);
|
||||||
|
$_SESSION["debug"] = $groupId;
|
||||||
return is_numeric($groupId);
|
return is_numeric($groupId);
|
||||||
// $r = $this->spc->UploadPlaylistMethod($this->Base->sessid, $gunid, $datetime);
|
// $r = $this->spc->UploadPlaylistMethod($this->Base->sessid, $gunid, $datetime);
|
||||||
// if ($this->_isError($r)) {
|
// if ($this->_isError($r)) {
|
||||||
|
@ -1060,7 +1063,7 @@ class uiScheduler extends uiCalendar {
|
||||||
*/
|
*/
|
||||||
function removeFromScheduleMethod($p_groupId)
|
function removeFromScheduleMethod($p_groupId)
|
||||||
{
|
{
|
||||||
$item = new ScheduleItem($p_groupId);
|
$item = new ScheduleGroup($p_groupId);
|
||||||
$success = $item->remove();
|
$success = $item->remove();
|
||||||
//$r = $this->spc->removeFromScheduleMethod($this->Base->sessid, $id);
|
//$r = $this->spc->removeFromScheduleMethod($this->Base->sessid, $id);
|
||||||
if (!$success) {
|
if (!$success) {
|
||||||
|
@ -1077,14 +1080,16 @@ class uiScheduler extends uiCalendar {
|
||||||
* Get the scheduled items between the $from and $to dates.
|
* Get the scheduled items between the $from and $to dates.
|
||||||
*
|
*
|
||||||
* @param string $from
|
* @param string $from
|
||||||
* In the format YYYMMDDTHH:MM:SS
|
* In the format "YYYY-MM-DD HH:MM:SS.nnnnnn"
|
||||||
* @param string $to
|
* @param string $to
|
||||||
* In the format YYYMMDDTHH:MM:SS
|
* In the format "YYYY-MM-DD HH:MM:SS.nnnnnn"
|
||||||
* @return array|false
|
* @return array|false
|
||||||
*/
|
*/
|
||||||
function displayScheduleMethod($from, $to)
|
function displayScheduleMethod($from, $to)
|
||||||
{
|
{
|
||||||
// NOTE: Need to fix times.
|
// NOTE: Need to fix times.
|
||||||
|
//$_SESSION["debug"] = "FROM: $from, TO: $to<br>";
|
||||||
|
//$from = substr($from, 0, 4)."-".
|
||||||
$items = Schedule::GetItems($from, $to);
|
$items = Schedule::GetItems($from, $to);
|
||||||
return $items;
|
return $items;
|
||||||
// $r = $this->spc->displayScheduleMethod($this->Base->sessid, $from, $to);
|
// $r = $this->spc->displayScheduleMethod($this->Base->sessid, $from, $to);
|
||||||
|
|
|
@ -131,10 +131,11 @@ class Playlist {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch instance of StoredPlaylist object.<br>
|
* Fetch instance of Playlist object.<br>
|
||||||
* @param string $p_gunid
|
*
|
||||||
* global unique id of file
|
* @param string $id
|
||||||
* @return StoredFile|Playlist|NULL
|
* DB id of file
|
||||||
|
* @return Playlist|NULL
|
||||||
* Return NULL if the object doesnt exist in the DB.
|
* Return NULL if the object doesnt exist in the DB.
|
||||||
*/
|
*/
|
||||||
public static function Recall($id) {
|
public static function Recall($id) {
|
||||||
|
@ -376,24 +377,22 @@ class Playlist {
|
||||||
return $res + 1;
|
return $res + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the entire playlist as a two dimentional array, sorted in order of play.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function getContents() {
|
public function getContents() {
|
||||||
|
|
||||||
global $CC_CONFIG, $CC_DBC;
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
|
||||||
$sql = "SELECT *
|
$sql = "SELECT *
|
||||||
FROM cc_playlistcontents C JOIN cc_files F ON C.file_id = F.id
|
FROM cc_playlistcontents C JOIN cc_files F ON C.file_id = F.id
|
||||||
WHERE C.playlist_id='{$this->getId()}' ORDER BY C.position";
|
WHERE C.playlist_id='{$this->getId()}' ORDER BY C.position";
|
||||||
|
|
||||||
return $CC_DBC->getAll($sql);
|
return $CC_DBC->getAll($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLength() {
|
public function getLength() {
|
||||||
|
|
||||||
global $CC_CONFIG, $CC_DBC;
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
|
||||||
$sql = "SELECT SUM(cliplength) AS length FROM ".$CC_CONFIG['playListContentsTable']
|
$sql = "SELECT SUM(cliplength) AS length FROM ".$CC_CONFIG['playListContentsTable']
|
||||||
." WHERE playlist_id='{$this->getId()}' group by playlist_id";
|
." WHERE playlist_id='{$this->getId()}' group by playlist_id";
|
||||||
|
|
||||||
$res = $CC_DBC->getRow($sql);
|
$res = $CC_DBC->getRow($sql);
|
||||||
if (PEAR::isError($res)) {
|
if (PEAR::isError($res)) {
|
||||||
return $res;
|
return $res;
|
||||||
|
@ -419,8 +418,8 @@ class Playlist {
|
||||||
if (PEAR::isError($pl_id)) {
|
if (PEAR::isError($pl_id)) {
|
||||||
return $pl_id;
|
return $pl_id;
|
||||||
}
|
}
|
||||||
|
$this->id = $pl_id;
|
||||||
return $pl_id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -463,30 +462,26 @@ class Playlist {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
* 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
|
* 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
|
* optional, in time format hh:mm:ss.ssssss - total duration
|
||||||
* @param string $plElGunid
|
* @param string $p_clipLength
|
||||||
* optional playlist element gunid
|
|
||||||
* @param string $length
|
|
||||||
* optional length in in time format hh:mm:ss.ssssss -
|
* optional length in in time format hh:mm:ss.ssssss -
|
||||||
* for webstream (or for overrule length of audioclip)
|
* for webstream (or for overrule length of audioclip)
|
||||||
* @param string $clipstart
|
* @return true|PEAR_Error
|
||||||
* optional clipstart in time format hh:mm:ss.ssssss - relative to begin
|
* TRUE on success
|
||||||
* @param string $clipend
|
|
||||||
* optional $clipend in time format hh:mm:ss.ssssss - relative to begin
|
|
||||||
* @return string
|
|
||||||
* generated playlistElement gunid
|
|
||||||
*/
|
*/
|
||||||
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.
|
//get audio clip.
|
||||||
$ac = StoredFile::Recall($acId);
|
$ac = StoredFile::Recall($p_id);
|
||||||
if (is_null($ac) || PEAR::isError($ac)) {
|
if (is_null($ac) || PEAR::isError($ac)) {
|
||||||
return $ac;
|
return $ac;
|
||||||
}
|
}
|
||||||
|
@ -496,31 +491,31 @@ class Playlist {
|
||||||
return $acInfo;
|
return $acInfo;
|
||||||
}
|
}
|
||||||
extract($acInfo); // 'acGunid', 'acLen', 'acTit', 'elType'
|
extract($acInfo); // 'acGunid', 'acLen', 'acTit', 'elType'
|
||||||
if (!is_null($cliplength)) {
|
if (!is_null($p_clipLength)) {
|
||||||
$acLen = $cliplength;
|
$acLen = $p_clipLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert at end of playlist.
|
// insert at end of playlist.
|
||||||
if(is_null($pos))
|
if (is_null($p_position))
|
||||||
$pos = $this->getNextPos();
|
$p_position = $this->getNextPos();
|
||||||
if (PEAR::isError($pos)) {
|
if (PEAR::isError($p_position)) {
|
||||||
return $pos;
|
return $p_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert default values if parameter was empty
|
// insert default values if parameter was empty
|
||||||
$cuein = !is_null($cuein) ? $cuein : '00:00:00.000000';
|
$p_cuein = !is_null($p_cuein) ? $p_cuein : '00:00:00.000000';
|
||||||
$cueout = !is_null($cueout) ? $cueout : $acLen;
|
$p_cueout = !is_null($p_cueout) ? $p_cueout : $acLen;
|
||||||
|
|
||||||
$acLengthS = $clipLengthS = self::playlistTimeToSeconds($acLen);
|
$acLengthS = $clipLengthS = self::playlistTimeToSeconds($acLen);
|
||||||
if (!is_null($cuein)) {
|
if (!is_null($p_cuein)) {
|
||||||
$clipLengthS = $acLengthS - self::playlistTimeToSeconds($cuein);
|
$clipLengthS = $acLengthS - self::playlistTimeToSeconds($p_cuein);
|
||||||
}
|
}
|
||||||
if (!is_null($cueout)) {
|
if (!is_null($p_cueout)) {
|
||||||
$clipLengthS = $clipLengthS - ($acLengthS - self::playlistTimeToSeconds($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)) {
|
if (PEAR::isError($res)) {
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class ScheduleItem {
|
class ScheduleGroup {
|
||||||
|
|
||||||
private $groupId;
|
private $groupId;
|
||||||
|
|
||||||
|
@ -46,10 +46,15 @@ class ScheduleItem {
|
||||||
/**
|
/**
|
||||||
* Add a music clip or playlist to the schedule.
|
* Add a music clip or playlist to the schedule.
|
||||||
*
|
*
|
||||||
* @param $p_audioFileId
|
|
||||||
* @param $p_playlistId
|
|
||||||
* @param $p_datetime
|
* @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
|
* @param $p_options
|
||||||
|
* Does nothing at the moment.
|
||||||
|
*
|
||||||
* @return int|PEAR_Error
|
* @return int|PEAR_Error
|
||||||
* Return PEAR_Error if the item could not be added.
|
* 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')");
|
$this->groupId = $CC_DBC->GetOne("SELECT nextval('schedule_group_id_seq')");
|
||||||
$id = $this->dateToId($p_datetime);
|
$id = $this->dateToId($p_datetime);
|
||||||
$sql = "INSERT INTO ".$CC_CONFIG["scheduleTable"]
|
$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', "
|
." VALUES ($id, 0, TIMESTAMP '$p_datetime', "
|
||||||
." (TIMESTAMP '$p_datetime' + INTERVAL '$length'),"
|
." (TIMESTAMP '$p_datetime' + INTERVAL '$length'),"
|
||||||
|
." '$length',"
|
||||||
." {$this->groupId}, $p_audioFileId)";
|
." {$this->groupId}, $p_audioFileId)";
|
||||||
$result = $CC_DBC->query($sql);
|
$result = $CC_DBC->query($sql);
|
||||||
if (PEAR::isError($result)) {
|
if (PEAR::isError($result)) {
|
||||||
|
@ -91,9 +97,47 @@ class ScheduleItem {
|
||||||
|
|
||||||
} elseif (!is_null($p_playlistId)){
|
} elseif (!is_null($p_playlistId)){
|
||||||
// Schedule a whole playlist
|
// Schedule a whole playlist
|
||||||
|
|
||||||
|
// Load existing playlist
|
||||||
|
$playlist = Playlist::Recall($p_playlistId);
|
||||||
|
if (is_null($playlist)) {
|
||||||
|
return new PEAR_Error("Could not find playlist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// return group ID
|
// 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) {
|
public function addAfter($p_groupId, $p_audioFileId) {
|
||||||
|
@ -126,6 +170,28 @@ class ScheduleItem {
|
||||||
return $CC_DBC->query($sql);
|
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) {
|
public function reschedule($toDateTime) {
|
||||||
global $CC_CONFIG, $CC_DBC;
|
global $CC_CONFIG, $CC_DBC;
|
||||||
// $sql = "UPDATE ".$CC_CONFIG["scheduleTable"]. " SET id=, starts=,ends="
|
// $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,"
|
." ends timestamp without time zone NOT NULL,"
|
||||||
." group_id integer,"
|
." group_id integer,"
|
||||||
." file_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_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,"
|
." 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,"
|
." 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'])) {
|
if (camp_db_table_exists($CC_CONFIG['playListTable'])) {
|
||||||
echo " * Removing database table ".$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);
|
camp_install_query($sql);
|
||||||
$CC_DBC->dropSequence($CC_CONFIG['playListTable']."_id");
|
$CC_DBC->dropSequence($CC_CONFIG['playListTable']."_id");
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,12 @@ require_once('DB.php');
|
||||||
require_once('PHPUnit.php');
|
require_once('PHPUnit.php');
|
||||||
require_once 'BasicStorTests.php';
|
require_once 'BasicStorTests.php';
|
||||||
require_once 'SchedulerTests.php';
|
require_once 'SchedulerTests.php';
|
||||||
//require_once 'PlayListTests.php';
|
require_once 'PlayListTests.php';
|
||||||
|
|
||||||
$suite = new PHPUnit_TestSuite("BasicStorTest");
|
$suite = new PHPUnit_TestSuite("BasicStorTest");
|
||||||
|
//$suite = new PHPUnit_TestSuite("SchedulerTests");
|
||||||
$suite->addTestSuite("SchedulerTests");
|
$suite->addTestSuite("SchedulerTests");
|
||||||
//$suite->addTestSuite("PlayListTests");
|
$suite->addTestSuite("PlayListTests");
|
||||||
$result = PHPUnit::run($suite);
|
$result = PHPUnit::run($suite);
|
||||||
|
|
||||||
echo $result->toString();
|
echo $result->toString();
|
||||||
|
|
|
@ -5,6 +5,7 @@ class SchedulerTests extends PHPUnit_TestCase {
|
||||||
|
|
||||||
private $groupIdCreated;
|
private $groupIdCreated;
|
||||||
private $storedFile;
|
private $storedFile;
|
||||||
|
private $storedFile2;
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
global $CC_CONFIG, $CC_DBC;
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
@ -17,6 +18,10 @@ class SchedulerTests extends PHPUnit_TestCase {
|
||||||
$values = array("filepath" => dirname(__FILE__)."/test10001.mp3");
|
$values = array("filepath" => dirname(__FILE__)."/test10001.mp3");
|
||||||
$this->storedFile = StoredFile::Insert($values, false);
|
$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
|
// Clear the schedule table
|
||||||
$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"];
|
$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"];
|
||||||
$CC_DBC->query($sql);
|
$CC_DBC->query($sql);
|
||||||
|
@ -24,36 +29,67 @@ class SchedulerTests extends PHPUnit_TestCase {
|
||||||
|
|
||||||
function testDateToId() {
|
function testDateToId() {
|
||||||
$dateStr = "2006-04-02 10:20:08.123456";
|
$dateStr = "2006-04-02 10:20:08.123456";
|
||||||
$id = ScheduleItem::dateToId($dateStr);
|
$id = ScheduleGroup::dateToId($dateStr);
|
||||||
$expected = "20060402102008123";
|
$expected = "20060402102008123";
|
||||||
if ($id != $expected) {
|
if ($id != $expected) {
|
||||||
$this->fail("Did not convert date to ID correctly #1: $id != $expected");
|
$this->fail("Did not convert date to ID correctly #1: $id != $expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
$dateStr = "2006-04-02 10:20:08";
|
$dateStr = "2006-04-02 10:20:08";
|
||||||
$id = ScheduleItem::dateToId($dateStr);
|
$id = ScheduleGroup::dateToId($dateStr);
|
||||||
$expected = "20060402102008000";
|
$expected = "20060402102008000";
|
||||||
if ($id != $expected) {
|
if ($id != $expected) {
|
||||||
$this->fail("Did not convert date to ID correctly #2: $id != $expected");
|
$this->fail("Did not convert date to ID correctly #2: $id != $expected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function testAddAndRemove() {
|
function testAddAndRemoveAudioFile() {
|
||||||
$i = new ScheduleItem();
|
$i = new ScheduleGroup();
|
||||||
$this->groupIdCreated = $i->add('2010-10-10 01:30:23', $this->storedFile->getId());
|
$this->groupIdCreated = $i->add('2010-10-10 01:30:23', $this->storedFile->getId());
|
||||||
if (PEAR::isError($this->groupIdCreated)) {
|
if (PEAR::isError($this->groupIdCreated)) {
|
||||||
$this->fail("Failed to create scheduled item: ". $this->groupIdCreated->getMessage());
|
$this->fail("Failed to create scheduled item: ". $this->groupIdCreated->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
$i = new ScheduleItem($this->groupIdCreated);
|
$i = new ScheduleGroup($this->groupIdCreated);
|
||||||
$result = $i->remove();
|
$result = $i->remove();
|
||||||
if ($result != 1) {
|
if ($result != 1) {
|
||||||
$this->fail("Did not remove item.");
|
$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() {
|
function testIsScheduleEmptyInRange() {
|
||||||
$i = new ScheduleItem();
|
$i = new ScheduleGroup();
|
||||||
$this->groupIdCreated = $i->add('2011-10-10 01:30:23', $this->storedFile->getId());
|
$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')) {
|
if (Schedule::isScheduleEmptyInRange('2011-10-10 01:30:23', '00:00:01.432153')) {
|
||||||
$this->fail("Reporting empty schedule when it isnt.");
|
$this->fail("Reporting empty schedule when it isnt.");
|
||||||
|
@ -65,9 +101,9 @@ class SchedulerTests extends PHPUnit_TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
function testGetItems() {
|
function testGetItems() {
|
||||||
$i1 = new ScheduleItem();
|
$i1 = new ScheduleGroup();
|
||||||
$groupId1 = $i1->add('2008-01-01 12:00:00.000', $this->storedFile->getId());
|
$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());
|
$i2->addAfter($groupId1, $this->storedFile->getId());
|
||||||
$items = Schedule::GetItems("2008-01-01", "2008-01-02");
|
$items = Schedule::GetItems("2008-01-01", "2008-01-02");
|
||||||
if (count($items) != 2) {
|
if (count($items) != 2) {
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue