public static function fillPreservedLinkedShowContent($ccShow, $showStamp) { $item = $showStamp->getFirst(); $timeFilled = $item->getCcShowInstances()->getDbTimeFilled(); foreach ($ccShow->getCcShowInstancess() as $ccShowInstance) { $ccSchedules = CcScheduleQuery::create()->filterByDbInstanceId($ccShowInstance->getDbId())->find(); if ($ccSchedules->isEmpty()) { $nextStartDT = $ccShowInstance->getDbStarts(null); foreach ($showStamp as $item) { $endTimeDT = self::findEndTime($nextStartDT, $item->getDbClipLength()); $ccSchedule = new CcSchedule(); $ccSchedule->setDbStarts($nextStartDT)->setDbEnds($endTimeDT)->setDbFileId($item->getDbFileId())->setDbStreamId($item->getDbStreamId())->setDbClipLength($item->getDbClipLength())->setDbFadeIn($item->getDbFadeIn())->setDbFadeOut($item->getDbFadeOut())->setDbCuein($item->getDbCueIn())->setDbCueOut($item->getDbCueOut())->setDbInstanceId($ccShowInstance->getDbId())->setDbPosition($item->getDbPosition())->save(); $nextStartDT = self::findTimeDifference($endTimeDT, Application_Model_Preference::GetDefaultCrossfadeDuration()); } //foreach show item $ccShowInstance->setDbTimeFilled($timeFilled)->setDbLastScheduled(gmdate("Y-m-d H:i:s"))->save(); } } }
private function insertAfter($scheduleItems, $schedFiles, $adjustSched = true) { try { $affectedShowInstances = array(); //dont want to recalculate times for moved items. $excludeIds = array(); foreach ($schedFiles as $file) { if (isset($file["sched_id"])) { $excludeIds[] = intval($file["sched_id"]); } } $startProfile = microtime(true); foreach ($scheduleItems as $schedule) { $id = intval($schedule["id"]); if ($id !== 0) { $schedItem = CcScheduleQuery::create()->findPK($id, $this->con); $instance = $schedItem->getCcShowInstances($this->con); $schedItemEndDT = $schedItem->getDbEnds(null); $nextStartDT = $this->findNextStartTime($schedItemEndDT, $instance); } else { $instance = CcShowInstancesQuery::create()->findPK($schedule["instance"], $this->con); $showStartDT = $instance->getDbStarts(null); $nextStartDT = $this->findNextStartTime($showStartDT, $instance); } if (!in_array($instance->getDbId(), $affectedShowInstances)) { $affectedShowInstances[] = $instance->getDbId(); } if ($adjustSched === true) { $pstart = microtime(true); $followingSchedItems = CcScheduleQuery::create()->filterByDBStarts($nextStartDT->format("Y-m-d H:i:s.u"), Criteria::GREATER_EQUAL)->filterByDbInstanceId($instance->getDbId())->filterByDbId($excludeIds, Criteria::NOT_IN)->orderByDbStarts()->find($this->con); $pend = microtime(true); Logging::debug("finding all following items."); Logging::debug(floatval($pend) - floatval($pstart)); } foreach ($schedFiles as $file) { $endTimeDT = $this->findEndTime($nextStartDT, $file['cliplength']); //item existed previously and is being moved. //need to keep same id for resources if we want REST. if (isset($file['sched_id'])) { $sched = CcScheduleQuery::create()->findPK($file['sched_id'], $this->con); } else { $sched = new CcSchedule(); } Logging::info($file); $sched->setDbStarts($nextStartDT)->setDbEnds($endTimeDT)->setDbCueIn($file['cuein'])->setDbCueOut($file['cueout'])->setDbFadeIn($file['fadein'])->setDbFadeOut($file['fadeout'])->setDbClipLength($file['cliplength'])->setDbInstanceId($instance->getDbId()); switch ($file["type"]) { case 0: $sched->setDbFileId($file['id']); break; case 1: $sched->setDbStreamId($file['id']); break; default: break; } $sched->save($this->con); $nextStartDT = $endTimeDT; } if ($adjustSched === true) { $pstart = microtime(true); //recalculate the start/end times after the inserted items. foreach ($followingSchedItems as $item) { $endTimeDT = $this->findEndTime($nextStartDT, $item->getDbClipLength()); $item->setDbStarts($nextStartDT); $item->setDbEnds($endTimeDT); $item->save($this->con); $nextStartDT = $endTimeDT; } $pend = microtime(true); Logging::debug("adjusting all following items."); Logging::debug(floatval($pend) - floatval($pstart)); } } $endProfile = microtime(true); Logging::debug("finished adding scheduled items."); Logging::debug(floatval($endProfile) - floatval($startProfile)); //update the status flag in cc_schedule. $instances = CcShowInstancesQuery::create()->filterByPrimaryKeys($affectedShowInstances)->find($this->con); $startProfile = microtime(true); foreach ($instances as $instance) { $instance->updateScheduleStatus($this->con); } $endProfile = microtime(true); Logging::debug("updating show instances status."); Logging::debug(floatval($endProfile) - floatval($startProfile)); $startProfile = microtime(true); //update the last scheduled timestamp. CcShowInstancesQuery::create()->filterByPrimaryKeys($affectedShowInstances)->update(array('DbLastScheduled' => new DateTime("now", new DateTimeZone("UTC"))), $this->con); $endProfile = microtime(true); Logging::debug("updating last scheduled timestamp."); Logging::debug(floatval($endProfile) - floatval($startProfile)); } catch (Exception $e) { Logging::debug($e->getMessage()); throw $e; } }
private function findNextStartTime($DT, $instanceId) { $sEpoch = $DT->format("U.u"); $nEpoch = $this->epochNow; //check for if the show has started. if (bccomp($nEpoch, $sEpoch, 6) === 1) { $this->applyCrossfades = false; //need some kind of placeholder for cc_schedule. //playout_status will be -1. $nextDT = $this->nowDT; $length = bcsub($nEpoch, $sEpoch, 6); $cliplength = Application_Common_DateHelper::secondsToPlaylistTime($length); //fillers are for only storing a chunk of time space that has already passed. $filler = new CcSchedule(); $filler->setDbStarts($DT)->setDbEnds($this->nowDT)->setDbClipLength($cliplength)->setDbCueIn('00:00:00')->setDbCueOut('00:00:00')->setDbPlayoutStatus(-1)->setDbInstanceId($instanceId)->save($this->con); } else { $nextDT = $DT; } return $nextDT; }