CC-1985 : Automatic rebroadcast of recorded content

scheduling the recorded file in any rebroadcast shows.
This commit is contained in:
naomiaro 2011-03-22 12:08:09 -04:00
parent 864cda6c34
commit fae71ed051
5 changed files with 39 additions and 56 deletions

View file

@ -24,41 +24,6 @@ class ScheduleGroup {
return $result != "0"; return $result != "0";
} }
/**
* Convert a date to an ID by stripping out all characters
* and padding with zeros.
*
* @param string $p_dateStr
*/
public static function dateToId($p_dateStr) {
$p_dateStr = str_replace(":", "", $p_dateStr);
$p_dateStr = str_replace(" ", "", $p_dateStr);
$p_dateStr = str_replace(".", "", $p_dateStr);
$p_dateStr = str_replace("-", "", $p_dateStr);
$p_dateStr = substr($p_dateStr, 0, 17);
$p_dateStr = str_pad($p_dateStr, 17, "0");
return $p_dateStr;
}
/**
* Add the two times together, return the result.
*
* @param string $p_baseTime
* Specified as YYYY-MM-DD HH:MM:SS
*
* @param string $p_addTime
* Specified as HH:MM:SS.nnnnnn
*
* @return string
* The end time, to the nearest second.
*/
// protected function calculateEndTime($p_startTime, $p_trackTime) {
// $p_trackTime = substr($p_startTime, 0, );
// $start = new DateTime();
// $interval = new DateInterval()
//
// }
/** /**
* Add a music clip or playlist to the schedule. * Add a music clip or playlist to the schedule.
* *
@ -77,6 +42,7 @@ class ScheduleGroup {
*/ */
public function add($show_instance, $p_datetime, $p_audioFileId = null, $p_playlistId = null, $p_options = null) { public function add($show_instance, $p_datetime, $p_audioFileId = null, $p_playlistId = null, $p_options = null) {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
if (!is_null($p_audioFileId)) { if (!is_null($p_audioFileId)) {
// Schedule a single audio track // Schedule a single audio track
@ -92,19 +58,16 @@ class ScheduleGroup {
if (empty($length)) { if (empty($length)) {
return new PEAR_Error("Length is empty."); return new PEAR_Error("Length is empty.");
} }
if (!Schedule::isScheduleEmptyInRange($p_datetime, $length)) {
return new PEAR_Error("Schedule conflict.", 555);
}
// Insert into the table // Insert into the table
$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);
$sql = "INSERT INTO ".$CC_CONFIG["scheduleTable"] $sql = "INSERT INTO ".$CC_CONFIG["scheduleTable"]
." (playlist_id, starts, ends, clip_length, group_id, file_id)" ." (instance_id, starts, ends, clip_length, group_id, file_id, cue_out)"
." VALUES (0, TIMESTAMP '$p_datetime', " ." VALUES ($show_instance, TIMESTAMP '$p_datetime', "
." (TIMESTAMP '$p_datetime' + INTERVAL '$length')," ." (TIMESTAMP '$p_datetime' + INTERVAL '$length'),"
." '$length'," ." '$length',"
." {$this->groupId}, $p_audioFileId)"; ." {$this->groupId}, $p_audioFileId, '$length')";
$result = $CC_DBC->query($sql); $result = $CC_DBC->query($sql);
if (PEAR::isError($result)) { if (PEAR::isError($result)) {
//var_dump($sql); //var_dump($sql);
@ -112,7 +75,8 @@ class ScheduleGroup {
} }
return $this->groupId; return $this->groupId;
} elseif (!is_null($p_playlistId)){ }
elseif (!is_null($p_playlistId)){
// Schedule a whole playlist // Schedule a whole playlist
// Load existing playlist // Load existing playlist
@ -130,7 +94,6 @@ class ScheduleGroup {
// Insert all items into the schedule // Insert all items into the schedule
$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);
$itemStartTime = $p_datetime; $itemStartTime = $p_datetime;
$plItems = $playlist->getContents(); $plItems = $playlist->getContents();
@ -157,7 +120,7 @@ class ScheduleGroup {
} }
} }
public function addAfter($show_instance, $p_groupId, $p_audioFileId) { public function addFileAfter($show_instance, $p_groupId, $p_audioFileId) {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
// Get the end time for the given entry // Get the end time for the given entry
$sql = "SELECT MAX(ends) FROM ".$CC_CONFIG["scheduleTable"] $sql = "SELECT MAX(ends) FROM ".$CC_CONFIG["scheduleTable"]
@ -176,10 +139,6 @@ class ScheduleGroup {
return $this->add($show_instance, $startTime, null, $p_playlistId); return $this->add($show_instance, $startTime, null, $p_playlistId);
} }
public function update() {
}
/** /**
* Remove the group from the schedule. * Remove the group from the schedule.
* Note: does not check if it is in the past, you can remove anything. * Note: does not check if it is in the past, you can remove anything.

View file

@ -652,8 +652,8 @@ class ShowInstance {
return $res; return $res;
} }
public function addPlaylistToShow($plId) { public function addPlaylistToShow($plId)
{
$sched = new ScheduleGroup(); $sched = new ScheduleGroup();
$lastGroupId = $this->getLastGroupId(); $lastGroupId = $this->getLastGroupId();
@ -666,6 +666,20 @@ class ShowInstance {
} }
} }
public function addFileToShow($file_id)
{
$sched = new ScheduleGroup();
$lastGroupId = $this->getLastGroupId();
if(is_null($lastGroupId)) {
$groupId = $sched->add($this->_instanceId, $this->getShowStart(), $file_id);
}
else {
$groupId = $sched->addFileAfter($this->_instanceId, $lastGroupId, $file_id);
}
}
public function scheduleShow($plIds) { public function scheduleShow($plIds) {
foreach($plIds as $plId) { foreach($plIds as $plId) {
@ -713,6 +727,16 @@ class ShowInstance {
->findPK($this->_instanceId); ->findPK($this->_instanceId);
$showInstance->setDbRecordedFile($file_id) $showInstance->setDbRecordedFile($file_id)
->save(); ->save();
$rebroadcasts = CcShowInstancesQuery::create()
->filterByDbOriginalShow($this->_instanceId)
->find();
foreach ($rebroadcasts as $rebroadcast) {
$rebroad = new ShowInstance($rebroadcast->getDbId());
$rebroad->addFileToShow($file_id);
}
} }
public function getTimeScheduled() { public function getTimeScheduled() {

View file

@ -39,7 +39,7 @@ class CcScheduleTableMap extends TableMap {
$this->setPrimaryKeyMethodInfo('cc_schedule_id_seq'); $this->setPrimaryKeyMethodInfo('cc_schedule_id_seq');
// columns // columns
$this->addPrimaryKey('ID', 'DbId', 'INTEGER', true, null, null); $this->addPrimaryKey('ID', 'DbId', 'INTEGER', true, null, null);
$this->addColumn('PLAYLIST_ID', 'DbPlaylistId', 'INTEGER', true, null, null); $this->addColumn('PLAYLIST_ID', 'DbPlaylistId', 'INTEGER', false, null, null);
$this->addColumn('STARTS', 'DbStarts', 'TIMESTAMP', true, null, null); $this->addColumn('STARTS', 'DbStarts', 'TIMESTAMP', true, null, null);
$this->addColumn('ENDS', 'DbEnds', 'TIMESTAMP', true, null, null); $this->addColumn('ENDS', 'DbEnds', 'TIMESTAMP', true, null, null);
$this->addColumn('GROUP_ID', 'DbGroupId', 'INTEGER', false, null, null); $this->addColumn('GROUP_ID', 'DbGroupId', 'INTEGER', false, null, null);

View file

@ -234,7 +234,7 @@
</table> </table>
<table name="cc_schedule" phpName="CcSchedule"> <table name="cc_schedule" phpName="CcSchedule">
<column name="id" phpName="DbId" type="INTEGER" primaryKey="true" autoIncrement="true" required="true"/> <column name="id" phpName="DbId" type="INTEGER" primaryKey="true" autoIncrement="true" required="true"/>
<column name="playlist_id" phpName="DbPlaylistId" type="INTEGER" required="true"/> <column name="playlist_id" phpName="DbPlaylistId" type="INTEGER" required="false"/>
<column name="starts" phpName="DbStarts" type="TIMESTAMP" required="true"/> <column name="starts" phpName="DbStarts" type="TIMESTAMP" required="true"/>
<column name="ends" phpName="DbEnds" type="TIMESTAMP" required="true"/> <column name="ends" phpName="DbEnds" type="TIMESTAMP" required="true"/>
<column name="group_id" phpName="DbGroupId" type="INTEGER" required="false"/> <column name="group_id" phpName="DbGroupId" type="INTEGER" required="false"/>

View file

@ -345,7 +345,7 @@ DROP TABLE "cc_schedule" CASCADE;
CREATE TABLE "cc_schedule" CREATE TABLE "cc_schedule"
( (
"id" serial NOT NULL, "id" serial NOT NULL,
"playlist_id" INTEGER NOT NULL, "playlist_id" INTEGER,
"starts" TIMESTAMP NOT NULL, "starts" TIMESTAMP NOT NULL,
"ends" TIMESTAMP NOT NULL, "ends" TIMESTAMP NOT NULL,
"group_id" INTEGER, "group_id" INTEGER,