2012-01-27 21:06:04 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Application_Model_Scheduler {
|
|
|
|
|
2012-01-31 18:59:27 +01:00
|
|
|
private $con;
|
2012-02-02 18:13:20 +01:00
|
|
|
private $fileInfo = array(
|
|
|
|
"id" => "",
|
|
|
|
"cliplength" => "",
|
|
|
|
"cuein" => "00:00:00",
|
|
|
|
"cueout" => "00:00:00",
|
|
|
|
"fadein" => "00:00:00",
|
|
|
|
"fadeout" => "00:00:00",
|
|
|
|
"sched_id" => null,
|
|
|
|
);
|
2012-01-27 21:06:04 +01:00
|
|
|
|
|
|
|
public function __construct($id = null) {
|
|
|
|
|
2012-02-02 23:15:39 +01:00
|
|
|
$this->con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
|
2012-01-27 21:06:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-01-31 18:59:27 +01:00
|
|
|
* @param $id
|
|
|
|
* @param $type
|
|
|
|
*
|
|
|
|
* @return $files
|
|
|
|
*/
|
2012-02-01 18:47:08 +01:00
|
|
|
private function retrieveMediaFiles($id, $type) {
|
2012-01-31 18:59:27 +01:00
|
|
|
|
|
|
|
$files = array();
|
|
|
|
|
2012-02-01 18:47:08 +01:00
|
|
|
if ($type === "audioclip") {
|
2012-02-02 23:15:39 +01:00
|
|
|
$file = CcFilesQuery::create()->findPK($id, $this->con);
|
2012-01-31 18:59:27 +01:00
|
|
|
|
2012-02-16 19:46:14 +01:00
|
|
|
if (is_null($file) || !$file->getDbFileExists()) {
|
|
|
|
throw new Exception("A selected File does not exist!");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$data = $this->fileInfo;
|
|
|
|
$data["id"] = $id;
|
|
|
|
$data["cliplength"] = $file->getDbLength();
|
2012-02-24 16:18:15 +01:00
|
|
|
$data["cueout"] = $file->getDbLength();
|
2012-01-31 18:59:27 +01:00
|
|
|
|
2012-02-27 21:29:02 +01:00
|
|
|
$defaultFade = Application_Model_Preference::GetDefaultFade();
|
|
|
|
if ($defaultFade !== "") {
|
|
|
|
//fade is in format SS.uuuuuu
|
|
|
|
$data["fadein"] = $defaultFade;
|
|
|
|
$data["fadeout"] = $defaultFade;
|
|
|
|
}
|
|
|
|
|
2012-02-16 19:46:14 +01:00
|
|
|
$files[] = $data;
|
|
|
|
}
|
2012-01-31 18:59:27 +01:00
|
|
|
}
|
|
|
|
else if ($type === "playlist") {
|
|
|
|
|
2012-02-02 23:15:39 +01:00
|
|
|
$contents = CcPlaylistcontentsQuery::create()
|
|
|
|
->orderByDbPosition()
|
|
|
|
->filterByDbPlaylistId($id)
|
|
|
|
->find($this->con);
|
|
|
|
|
2012-02-16 19:46:14 +01:00
|
|
|
if (is_null($contents)) {
|
|
|
|
throw new Exception("A selected Playlist does not exist!");
|
|
|
|
}
|
|
|
|
|
2012-02-02 23:15:39 +01:00
|
|
|
foreach ($contents as $plItem) {
|
|
|
|
|
2012-02-16 19:46:14 +01:00
|
|
|
$file = $plItem->getCcFiles($this->con);
|
|
|
|
if (isset($file) && $file->getDbFileExists()) {
|
2012-02-02 23:15:39 +01:00
|
|
|
|
2012-02-16 19:46:14 +01:00
|
|
|
$data = $this->fileInfo;
|
|
|
|
$data["id"] = $plItem->getDbFileId();
|
|
|
|
$data["cliplength"] = $plItem->getDbCliplength();
|
|
|
|
$data["cuein"] = $plItem->getDbCuein();
|
|
|
|
$data["cueout"] = $plItem->getDbCueout();
|
|
|
|
$data["fadein"] = $plItem->getDbFadein();
|
|
|
|
$data["fadeout"] = $plItem->getDbFadeout();
|
|
|
|
|
|
|
|
$files[] = $data;
|
|
|
|
}
|
2012-02-02 23:15:39 +01:00
|
|
|
}
|
2012-01-31 18:59:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $files;
|
|
|
|
}
|
|
|
|
|
2012-02-01 18:47:08 +01:00
|
|
|
/*
|
2012-02-07 17:29:52 +01:00
|
|
|
* @param DateTime startDT in UTC
|
2012-02-01 18:47:08 +01:00
|
|
|
* @param string duration
|
|
|
|
* in format H:i:s.u (could be more that 24 hours)
|
2012-02-07 17:29:52 +01:00
|
|
|
*
|
|
|
|
* @return DateTime endDT in UTC
|
2012-02-01 18:47:08 +01:00
|
|
|
*/
|
2012-02-13 18:29:39 +01:00
|
|
|
public static function findEndTime($p_startDT, $p_duration) {
|
2012-02-07 17:29:52 +01:00
|
|
|
|
|
|
|
$startEpoch = $p_startDT->format("U.u");
|
|
|
|
$durationSeconds = Application_Model_Playlist::playlistTimeToSeconds($p_duration);
|
|
|
|
|
|
|
|
//add two float numbers to 6 subsecond precision
|
|
|
|
//DateTime::createFromFormat("U.u") will have a problem if there is no decimal in the resulting number.
|
|
|
|
$endEpoch = bcadd($startEpoch , (string) $durationSeconds, 6);
|
|
|
|
|
2012-02-27 22:26:17 +01:00
|
|
|
Logging::log("start DateTime created {$p_startDT->format("Y-m-d H:i:s.u")}");
|
2012-02-07 17:29:52 +01:00
|
|
|
Logging::log("start epoch is {$startEpoch}");
|
|
|
|
Logging::log("duration in seconds is {$durationSeconds}");
|
|
|
|
Logging::log("end epoch is {$endEpoch}");
|
|
|
|
|
|
|
|
$dt = DateTime::createFromFormat("U.u", $endEpoch, new DateTimeZone("UTC"));
|
2012-02-01 18:47:08 +01:00
|
|
|
|
2012-02-07 17:29:52 +01:00
|
|
|
Logging::log("end DateTime created {$dt->format("Y-m-d H:i:s.u")}");
|
|
|
|
|
|
|
|
return $dt;
|
2012-02-01 18:47:08 +01:00
|
|
|
}
|
|
|
|
|
2012-02-02 18:13:20 +01:00
|
|
|
/*
|
|
|
|
* @param array $scheduledIds
|
|
|
|
* @param array $fileIds
|
|
|
|
* @param array $playlistIds
|
|
|
|
*/
|
|
|
|
private function insertAfter($scheduleItems, $schedFiles, $adjustSched = true) {
|
|
|
|
|
|
|
|
try {
|
2012-01-31 18:59:27 +01:00
|
|
|
|
2012-02-16 19:46:14 +01:00
|
|
|
$affectedShowInstances = array();
|
|
|
|
|
2012-02-06 01:51:22 +01:00
|
|
|
//dont want to recalculate times for moved items.
|
|
|
|
$excludeIds = array();
|
|
|
|
foreach ($schedFiles as $file) {
|
|
|
|
if (isset($file["sched_id"])) {
|
|
|
|
$excludeIds[] = intval($file["sched_id"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-01 18:47:08 +01:00
|
|
|
foreach ($scheduleItems as $schedule) {
|
|
|
|
$id = intval($schedule["id"]);
|
2012-02-16 19:46:14 +01:00
|
|
|
$ts = intval($schedule["timestamp"]);
|
2012-01-31 18:59:27 +01:00
|
|
|
|
2012-02-01 18:47:08 +01:00
|
|
|
Logging::log("scheduling after scheduled item: ".$id);
|
2012-02-03 18:15:10 +01:00
|
|
|
Logging::log("in show: ".intval($schedule["instance"]));
|
2012-01-31 18:59:27 +01:00
|
|
|
|
2012-02-01 18:47:08 +01:00
|
|
|
if ($id !== 0) {
|
2012-02-02 23:15:39 +01:00
|
|
|
$schedItem = CcScheduleQuery::create()->findPK($id, $this->con);
|
2012-02-28 17:16:43 +01:00
|
|
|
if (is_null($schedItem)) {
|
|
|
|
throw new OutDatedScheduleException("The schedule you're viewing is out of date!");
|
|
|
|
}
|
2012-02-16 19:46:14 +01:00
|
|
|
$instance = $schedItem->getCcShowInstances($this->con);
|
|
|
|
if (intval($schedule["instance"]) !== $instance->getDbId()) {
|
|
|
|
throw new OutDatedScheduleException("The schedule you're viewing is out of date!");
|
2012-02-01 18:47:08 +01:00
|
|
|
}
|
|
|
|
$nextStartDT = $schedItem->getDbEnds(null);
|
|
|
|
}
|
|
|
|
//selected empty row to add after
|
|
|
|
else {
|
2012-02-16 19:46:14 +01:00
|
|
|
$instance = CcShowInstancesQuery::create()->findPK($schedule["instance"], $this->con);
|
2012-02-17 12:19:42 +01:00
|
|
|
$nextStartDT = $instance->getDbStarts(null);
|
2012-02-16 19:46:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$currTs = intval($instance->getDbLastScheduled("U")) ? : 0;
|
|
|
|
//user has an old copy of the time line opened.
|
|
|
|
if ($ts !== $currTs) {
|
|
|
|
Logging::log("currTs {$currTs}, ts {$ts}");
|
|
|
|
$show = $instance->getCcShow($this->con);
|
|
|
|
throw new OutDatedScheduleException("The show {$show->getDbName()} has been previously updated!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_array($instance->getDbId(), $affectedShowInstances)) {
|
|
|
|
$affectedShowInstances[] = $instance->getDbId();
|
2012-02-01 18:47:08 +01:00
|
|
|
}
|
|
|
|
|
2012-02-06 01:51:22 +01:00
|
|
|
Logging::log("finding items >= {$nextStartDT->format("Y-m-d H:i:s.u")}");
|
|
|
|
if ($adjustSched === true) {
|
2012-01-31 18:59:27 +01:00
|
|
|
$followingSchedItems = CcScheduleQuery::create()
|
2012-02-06 01:51:22 +01:00
|
|
|
->filterByDBStarts($nextStartDT->format("Y-m-d H:i:s.u"), Criteria::GREATER_EQUAL)
|
2012-02-16 19:46:14 +01:00
|
|
|
->filterByDbInstanceId($instance->getDbId())
|
2012-02-06 01:51:22 +01:00
|
|
|
->filterByDbId($excludeIds, Criteria::NOT_IN)
|
2012-01-31 18:59:27 +01:00
|
|
|
->orderByDbStarts()
|
2012-02-02 23:15:39 +01:00
|
|
|
->find($this->con);
|
2012-02-06 01:51:22 +01:00
|
|
|
|
|
|
|
foreach ($excludeIds as $id) {
|
|
|
|
Logging::log("Excluding id {$id}");
|
|
|
|
}
|
2012-01-31 18:59:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach($schedFiles as $file) {
|
|
|
|
|
2012-02-01 18:47:08 +01:00
|
|
|
Logging::log("adding file with id: ".$file["id"]);
|
|
|
|
|
2012-02-13 18:29:39 +01:00
|
|
|
$endTimeDT = self::findEndTime($nextStartDT, $file['cliplength']);
|
2012-01-31 18:59:27 +01:00
|
|
|
|
2012-02-02 18:13:20 +01:00
|
|
|
//item existed previously and is being moved.
|
|
|
|
//need to keep same id for resources if we want REST.
|
|
|
|
if (isset($file['sched_id'])) {
|
2012-02-02 23:15:39 +01:00
|
|
|
$sched = CcScheduleQuery::create()->findPK($file['sched_id'], $this->con);
|
2012-02-02 18:38:56 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$sched = new CcSchedule();
|
2012-02-02 18:13:20 +01:00
|
|
|
}
|
2012-02-06 01:51:22 +01:00
|
|
|
Logging::log("id {$sched->getDbId()}");
|
|
|
|
Logging::log("start time {$nextStartDT->format("Y-m-d H:i:s.u")}");
|
|
|
|
Logging::log("end time {$endTimeDT->format("Y-m-d H:i:s.u")}");
|
2012-02-02 18:13:20 +01:00
|
|
|
|
|
|
|
$sched->setDbStarts($nextStartDT);
|
|
|
|
$sched->setDbEnds($endTimeDT);
|
|
|
|
$sched->setDbFileId($file['id']);
|
|
|
|
$sched->setDbCueIn($file['cuein']);
|
|
|
|
$sched->setDbCueOut($file['cueout']);
|
|
|
|
$sched->setDbFadeIn($file['fadein']);
|
|
|
|
$sched->setDbFadeOut($file['fadeout']);
|
2012-02-07 17:29:52 +01:00
|
|
|
$sched->setDbClipLength($file['cliplength']);
|
2012-02-16 19:46:14 +01:00
|
|
|
$sched->setDbInstanceId($instance->getDbId());
|
2012-02-02 18:13:20 +01:00
|
|
|
$sched->save($this->con);
|
2012-01-31 18:59:27 +01:00
|
|
|
|
2012-02-01 18:47:08 +01:00
|
|
|
$nextStartDT = $endTimeDT;
|
2012-01-31 18:59:27 +01:00
|
|
|
}
|
|
|
|
|
2012-02-06 01:51:22 +01:00
|
|
|
if ($adjustSched === true) {
|
2012-01-31 18:59:27 +01:00
|
|
|
|
|
|
|
//recalculate the start/end times after the inserted items.
|
2012-02-01 18:47:08 +01:00
|
|
|
foreach($followingSchedItems as $item) {
|
2012-01-31 18:59:27 +01:00
|
|
|
|
2012-02-06 01:51:22 +01:00
|
|
|
Logging::log("adjusting iterm {$item->getDbId()}");
|
|
|
|
|
2012-02-13 18:29:39 +01:00
|
|
|
$endTimeDT = self::findEndTime($nextStartDT, $item->getDbClipLength());
|
2012-01-31 18:59:27 +01:00
|
|
|
|
2012-02-01 18:47:08 +01:00
|
|
|
$item->setDbStarts($nextStartDT);
|
|
|
|
$item->setDbEnds($endTimeDT);
|
|
|
|
$item->save($this->con);
|
2012-01-27 21:06:04 +01:00
|
|
|
|
2012-02-01 18:47:08 +01:00
|
|
|
$nextStartDT = $endTimeDT;
|
2012-01-31 18:59:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-01 18:47:08 +01:00
|
|
|
|
2012-02-16 19:46:14 +01:00
|
|
|
//update the last scheduled timestamp.
|
|
|
|
CcShowInstancesQuery::create()
|
2012-02-17 11:14:44 +01:00
|
|
|
->filterByPrimaryKeys($affectedShowInstances)
|
2012-02-16 19:46:14 +01:00
|
|
|
->update(array('DbLastScheduled' => new DateTime("now", new DateTimeZone("UTC"))), $this->con);
|
2012-02-02 18:13:20 +01:00
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-02 18:38:56 +01:00
|
|
|
/*
|
2012-02-27 14:33:56 +01:00
|
|
|
* @param array $scheduleItems
|
|
|
|
* @param array $mediaItems
|
2012-02-02 18:38:56 +01:00
|
|
|
*/
|
|
|
|
public function scheduleAfter($scheduleItems, $mediaItems, $adjustSched = true) {
|
|
|
|
|
|
|
|
$this->con->beginTransaction();
|
|
|
|
|
|
|
|
$schedFiles = array();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
2012-02-28 17:16:43 +01:00
|
|
|
foreach ($mediaItems as $media) {
|
2012-02-02 18:38:56 +01:00
|
|
|
Logging::log("Media Id ".$media["id"]);
|
|
|
|
Logging::log("Type ".$media["type"]);
|
|
|
|
|
|
|
|
$schedFiles = array_merge($schedFiles, $this->retrieveMediaFiles($media["id"], $media["type"]));
|
|
|
|
}
|
|
|
|
$this->insertAfter($scheduleItems, $schedFiles, $adjustSched);
|
|
|
|
|
|
|
|
$this->con->commit();
|
2012-02-09 21:19:21 +01:00
|
|
|
|
|
|
|
Application_Model_RabbitMq::PushSchedule();
|
2012-02-02 18:38:56 +01:00
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
$this->con->rollback();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-02 18:13:20 +01:00
|
|
|
/*
|
|
|
|
* @param array $selectedItem
|
|
|
|
* @param array $afterItem
|
|
|
|
*/
|
2012-02-16 19:46:14 +01:00
|
|
|
public function moveItem($selectedItems, $afterItems, $adjustSched = true) {
|
2012-02-02 18:13:20 +01:00
|
|
|
|
|
|
|
$this->con->beginTransaction();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
2012-02-16 19:46:14 +01:00
|
|
|
$origSelTs = intval($selectedItems[0]["timestamp"]);
|
|
|
|
$origAfterTs = intval($afterItems[0]["timestamp"]);
|
2012-02-02 18:13:20 +01:00
|
|
|
|
2012-02-16 19:46:14 +01:00
|
|
|
Logging::log("Moving item {$selectedItems[0]["id"]}");
|
|
|
|
Logging::log("After {$afterItems[0]["id"]}");
|
2012-02-02 18:13:20 +01:00
|
|
|
|
2012-02-16 19:46:14 +01:00
|
|
|
$selected = CcScheduleQuery::create()->findPk($selectedItems[0]["id"], $this->con);
|
2012-02-17 12:19:42 +01:00
|
|
|
if (is_null($selected)) {
|
2012-02-16 19:46:14 +01:00
|
|
|
throw new OutDatedScheduleException("The schedule you're viewing is out of date!");
|
2012-02-02 18:13:20 +01:00
|
|
|
}
|
2012-02-16 19:46:14 +01:00
|
|
|
$selectedInstance = $selected->getCcShowInstances($this->con);
|
2012-02-17 12:19:42 +01:00
|
|
|
|
|
|
|
if (intval($afterItems[0]["id"]) === 0) {
|
|
|
|
|
|
|
|
$afterInstance = CcShowInstancesQuery::create()->findPK($afterItems[0]["instance"], $this->con);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$after = CcScheduleQuery::create()->findPk($afterItems[0]["id"], $this->con);
|
|
|
|
if (is_null($after)) {
|
|
|
|
throw new OutDatedScheduleException("The schedule you're viewing is out of date!");
|
|
|
|
}
|
|
|
|
$afterInstance = $after->getCcShowInstances($this->con);
|
|
|
|
}
|
2012-02-02 18:13:20 +01:00
|
|
|
|
2012-02-16 19:46:14 +01:00
|
|
|
if (is_null($selectedInstance) || is_null($afterInstance)) {
|
|
|
|
throw new OutDatedScheduleException("The schedule you're viewing is out of date!");
|
|
|
|
}
|
|
|
|
|
|
|
|
$currTs = intval($selectedInstance->getDbLastScheduled("U")) ? : 0;
|
|
|
|
if ($origSelTs !== $currTs) {
|
|
|
|
$show = $selectedInstance->getCcShow($this->con);
|
|
|
|
throw new OutDatedScheduleException("The show {$show->getDbName()} has been previously updated!");
|
|
|
|
}
|
2012-02-02 18:13:20 +01:00
|
|
|
|
2012-02-16 19:46:14 +01:00
|
|
|
$currTs = intval($afterInstance->getDbLastScheduled("U")) ? : 0;
|
|
|
|
if ($origAfterTs !== $currTs) {
|
|
|
|
$show = $afterInstance->getCcShow($this->con);
|
|
|
|
throw new OutDatedScheduleException("The show {$show->getDbName()} has been previously updated!");
|
2012-02-02 18:13:20 +01:00
|
|
|
}
|
|
|
|
|
2012-02-16 19:46:14 +01:00
|
|
|
$this->removeGaps($selectedInstance->getDbId(), $selected->getDbId());
|
|
|
|
|
2012-02-02 18:13:20 +01:00
|
|
|
$data = $this->fileInfo;
|
|
|
|
$data["id"] = $selected->getDbFileId();
|
|
|
|
$data["cliplength"] = $selected->getDbClipLength();
|
|
|
|
$data["cuein"] = $selected->getDbCueIn();
|
|
|
|
$data["cueout"] = $selected->getDbCueOut();
|
|
|
|
$data["fadein"] = $selected->getDbFadeIn();
|
|
|
|
$data["fadeout"] = $selected->getDbFadeOut();
|
|
|
|
$data["sched_id"] = $selected->getDbId();
|
|
|
|
|
2012-02-16 19:46:14 +01:00
|
|
|
$this->insertAfter($afterItems, array($data), $adjustSched);
|
2012-02-02 18:13:20 +01:00
|
|
|
|
2012-02-01 18:47:08 +01:00
|
|
|
$this->con->commit();
|
2012-02-09 21:19:21 +01:00
|
|
|
|
|
|
|
Application_Model_RabbitMq::PushSchedule();
|
2012-01-31 18:59:27 +01:00
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
2012-02-01 18:47:08 +01:00
|
|
|
$this->con->rollback();
|
2012-01-31 18:59:27 +01:00
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-15 18:27:59 +01:00
|
|
|
public function removeItems($scheduledItems, $adjustSched = true) {
|
2012-01-31 18:59:27 +01:00
|
|
|
|
|
|
|
$showInstances = array();
|
|
|
|
$this->con->beginTransaction();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
2012-02-15 18:27:59 +01:00
|
|
|
$scheduledIds = array();
|
|
|
|
foreach ($scheduledItems as $item) {
|
2012-02-16 19:46:14 +01:00
|
|
|
$scheduledIds[$item["id"]] = intval($item["timestamp"]);
|
2012-02-16 16:29:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$removedItems = CcScheduleQuery::create()->findPks(array_keys($scheduledIds));
|
|
|
|
|
|
|
|
//check to make sure all items selected are up to date
|
|
|
|
foreach ($removedItems as $removedItem) {
|
|
|
|
$ts = $scheduledIds[$removedItem->getDbId()];
|
|
|
|
$instance = $removedItem->getCcShowInstances($this->con);
|
2012-02-16 19:46:14 +01:00
|
|
|
if (is_null($instance)) {
|
|
|
|
throw new OutDatedScheduleException("The schedule you're viewing is out of date!");
|
|
|
|
}
|
2012-02-16 16:29:11 +01:00
|
|
|
$currTs = intval($instance->getDbLastScheduled("U")) ? : 0;
|
|
|
|
|
|
|
|
if ($ts !== $currTs) {
|
|
|
|
$show = $instance->getCcShow($this->con);
|
2012-02-16 19:46:14 +01:00
|
|
|
throw new OutDatedScheduleException("The show {$show->getDbName()} has been previously updated!");
|
2012-02-16 16:29:11 +01:00
|
|
|
}
|
2012-02-15 18:27:59 +01:00
|
|
|
}
|
|
|
|
|
2012-01-31 18:59:27 +01:00
|
|
|
$removedItems->delete($this->con);
|
|
|
|
|
|
|
|
if ($adjustSched === true) {
|
|
|
|
//get the show instances of the shows we must adjust times for.
|
|
|
|
foreach ($removedItems as $item) {
|
|
|
|
|
|
|
|
$instance = $item->getDBInstanceId();
|
|
|
|
if (!in_array($instance, $showInstances)) {
|
|
|
|
$showInstances[] = $instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($showInstances as $instance) {
|
2012-02-01 18:47:08 +01:00
|
|
|
$this->removeGaps($instance);
|
2012-01-31 18:59:27 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-31 21:39:34 +01:00
|
|
|
|
2012-02-16 19:46:14 +01:00
|
|
|
//update the last scheduled timestamp.
|
|
|
|
CcShowInstancesQuery::create()
|
|
|
|
->filterByPrimaryKeys($showInstances)
|
|
|
|
->update(array('DbLastScheduled' => new DateTime("now", new DateTimeZone("UTC"))), $this->con);
|
|
|
|
|
2012-01-31 21:39:34 +01:00
|
|
|
$this->con->commit();
|
2012-02-09 21:19:21 +01:00
|
|
|
|
|
|
|
Application_Model_RabbitMq::PushSchedule();
|
2012-01-31 18:59:27 +01:00
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
$this->con->rollback();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-02 18:38:56 +01:00
|
|
|
/*
|
|
|
|
* @param int $showInstance
|
|
|
|
* @param array $exclude
|
|
|
|
* ids of sched items to remove from the calulation.
|
|
|
|
*/
|
2012-02-16 19:46:14 +01:00
|
|
|
private function removeGaps($showInstance, $exclude=null) {
|
2012-01-31 18:59:27 +01:00
|
|
|
|
|
|
|
Logging::log("removing gaps from show instance #".$showInstance);
|
|
|
|
|
2012-02-02 23:15:39 +01:00
|
|
|
$instance = CcShowInstancesQuery::create()->findPK($showInstance, $this->con);
|
2012-02-16 19:46:14 +01:00
|
|
|
if (is_null($instance)) {
|
|
|
|
throw new OutDatedScheduleException("The schedule you're viewing is out of date!");
|
|
|
|
}
|
2012-02-16 16:29:11 +01:00
|
|
|
|
2012-01-31 18:59:27 +01:00
|
|
|
$itemStartDT = $instance->getDbStarts(null);
|
|
|
|
|
|
|
|
$schedule = CcScheduleQuery::create()
|
|
|
|
->filterByDbInstanceId($showInstance)
|
2012-02-02 18:38:56 +01:00
|
|
|
->filterByDbId($exclude, Criteria::NOT_IN)
|
2012-01-31 18:59:27 +01:00
|
|
|
->orderByDbStarts()
|
2012-02-02 23:15:39 +01:00
|
|
|
->find($this->con);
|
2012-01-31 18:59:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
foreach ($schedule as $item) {
|
|
|
|
|
|
|
|
Logging::log("adjusting item #".$item->getDbId());
|
|
|
|
|
2012-02-13 18:29:39 +01:00
|
|
|
$itemEndDT = self::findEndTime($itemStartDT, $item->getDbClipLength());
|
2012-01-31 18:59:27 +01:00
|
|
|
|
2012-02-07 17:29:52 +01:00
|
|
|
$item->setDbStarts($itemStartDT);
|
|
|
|
$item->setDbEnds($itemEndDT);
|
|
|
|
$item->save($this->con);
|
2012-01-31 18:59:27 +01:00
|
|
|
|
2012-02-07 17:29:52 +01:00
|
|
|
$itemStartDT = $itemEndDT;
|
2012-01-31 18:59:27 +01:00
|
|
|
}
|
2012-01-27 21:06:04 +01:00
|
|
|
}
|
2012-02-16 16:29:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class OutDatedScheduleException extends Exception {}
|