CC-5122: Calendar -> linked show: Change the repeating weekday will lost all the contents

This commit is contained in:
denise 2013-05-10 14:17:54 -04:00
parent f5fa033207
commit 13458ad687
2 changed files with 129 additions and 60 deletions

View File

@ -145,71 +145,114 @@ class Application_Service_SchedulerService
return $dt; return $dt;
} }
public static function fillLinkedShows($ccShow) public static function fillNewLinkedInstances($ccShow)
{ {
if ($ccShow->isLinked()) { /* First check if any linked instances have content
/* First check if any linked instances have content * If all instances are empty then we don't need to fill
* If all instances are empty then we don't need to fill * any other instances with content
* any other instances with content */
$instanceIds = $ccShow->getInstanceIds();
$ccSchedules = CcScheduleQuery::create()
->filterByDbInstanceId($instanceIds, Criteria::IN)
->find();
if (!$ccSchedules->isEmpty()) {
/* Find the show contents of just one of the instances. It doesn't
* matter which instance we use since all the content is the same
*/ */
$instanceIds = $ccShow->getInstanceIds(); $ccSchedule = $ccSchedules->getFirst();
$ccSchedules = CcScheduleQuery::create() $showStamp = CcScheduleQuery::create()
->filterByDbInstanceId($instanceIds, Criteria::IN) ->filterByDbInstanceId($ccSchedule->getDbInstanceId())
->orderByDbStarts()
->find(); ->find();
if (!$ccSchedules->isEmpty()) {
/* Find the show contents of just one of the instances. It doesn't //get time_filled so we can update cc_show_instances
* matter which instance we use since all the content is the same $timeFilled = $ccSchedule->getCcShowInstances()->getDbTimeFilled();
*/
$ccSchedule = $ccSchedules->getFirst(); //need to find out which linked instances are empty
$showStamp = CcScheduleQuery::create() foreach ($ccShow->getCcShowInstancess() as $ccShowInstance) {
->filterByDbInstanceId($ccSchedule->getDbInstanceId()) $ccSchedules = CcScheduleQuery::create()
->orderByDbStarts() ->filterByDbInstanceId($ccShowInstance->getDbId())
->find(); ->find();
/* If the show instance is empty OR it has different content than
* the first instance, we cant to fill/replace with the show stamp
* (The show stamp is taken from the first show instance's content)
*/
if ($ccSchedules->isEmpty() ||
self::replaceInstanceContentCheck($ccShowInstance, $showStamp)) {
//get time_filled so we can update cc_show_instances $nextStartDT = $ccShowInstance->getDbStarts(null);
$timeFilled = $ccSchedule->getCcShowInstances()->getDbTimeFilled();
//need to find out which linked instances are empty foreach ($showStamp as $item) {
foreach ($ccShow->getCcShowInstancess() as $ccShowInstance) { $endTimeDT = self::findEndTime($nextStartDT, $item->getDbClipLength());
$ccSchedules = CcScheduleQuery::create()
->filterByDbInstanceId($ccShowInstance->getDbId())
->find();
/* If the show instance is empty OR it has different content than
* the first instance, we cant to fill/replace with the show stamp
* (The show stamp is taken from the first show instance's content)
*/
if ($ccSchedules->isEmpty() || self::replaceInstanceContentCheck($ccShowInstance, $showStamp)) {
$nextStartDT = $ccShowInstance->getDbStarts(null);
foreach ($showStamp as $item) { $ccSchedule = new CcSchedule();
$endTimeDT = self::findEndTime($nextStartDT, $item->getDbClipLength()); $ccSchedule
->setDbStarts($nextStartDT)
$ccSchedule = new CcSchedule(); ->setDbEnds($endTimeDT)
$ccSchedule ->setDbFileId($item->getDbFileId())
->setDbStarts($nextStartDT) ->setDbStreamId($item->getDbStreamId())
->setDbEnds($endTimeDT) ->setDbClipLength($item->getDbClipLength())
->setDbFileId($item->getDbFileId()) ->setDbFadeIn($item->getDbFadeIn())
->setDbStreamId($item->getDbStreamId()) ->setDbFadeOut($item->getDbFadeOut())
->setDbClipLength($item->getDbClipLength()) ->setDbCuein($item->getDbCueIn())
->setDbFadeIn($item->getDbFadeIn()) ->setDbCueOut($item->getDbCueOut())
->setDbFadeOut($item->getDbFadeOut()) ->setDbInstanceId($ccShowInstance->getDbId())
->setDbCuein($item->getDbCueIn()) ->setDbPosition($item->getDbPosition())
->setDbCueOut($item->getDbCueOut())
->setDbInstanceId($ccShowInstance->getDbId())
->setDbPosition($item->getDbPosition())
->save();
$nextStartDT = $endTimeDT;
} //foreach show item
//update time_filled in cc_show_instances
$ccShowInstance
->setDbTimeFilled($timeFilled)
->setDbLastScheduled(gmdate("Y-m-d H:i:s"))
->save(); ->save();
}
} //foreach linked instance $nextStartDT = $endTimeDT;
} //if at least one linked instance has content } //foreach show item
//update time_filled in cc_show_instances
$ccShowInstance
->setDbTimeFilled($timeFilled)
->setDbLastScheduled(gmdate("Y-m-d H:i:s"))
->save();
}
} //foreach linked instance
} //if at least one linked instance has content
}
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 = $endTimeDT;
} //foreach show item
$ccShowInstance
->setDbTimeFilled($timeFilled)
->setDbLastScheduled(gmdate("Y-m-d H:i:s"))
->save();
}
} }
} }

View File

@ -13,6 +13,7 @@ class Application_Service_ShowService
private $isRebroadcast; private $isRebroadcast;
private $repeatType; private $repeatType;
private $isUpdate; private $isUpdate;
private $linkedShowContent;
public function __construct($showId=null, $showData=null, $isUpdate=false) public function __construct($showId=null, $showData=null, $isUpdate=false)
{ {
@ -217,10 +218,16 @@ class Application_Service_ShowService
} }
} }
if (isset($this->ccShow) && ($this->isUpdate || $fillInstances)) { if (isset($this->ccShow) && ($this->isUpdate || $fillInstances) &&
Application_Service_SchedulerService::fillLinkedShows( $this->ccShow->isLinked()) {
$this->ccShow); Application_Service_SchedulerService::fillNewLinkedInstances($this->ccShow);
} }
if (isset($this->linkedShowContent)) {
Application_Service_SchedulerService::fillPreservedLinkedShowContent(
$this->ccShow, $this->linkedShowContent);
}
return $this->ccShow; return $this->ccShow;
} }
@ -379,6 +386,9 @@ SQL;
if (count($daysRemoved) > 0) { if (count($daysRemoved) > 0) {
//delete repeating show instances for the repeating //delete repeating show instances for the repeating
//days that were removed //days that were removed
if ($this->ccShow->isLinked()) {
$this->preserveLinkedShowContent();
}
$this->deleteRemovedShowDayInstances($daysRemoved, $this->deleteRemovedShowDayInstances($daysRemoved,
$ccShowDays, $showId); $ccShowDays, $showId);
} }
@ -423,6 +433,22 @@ SQL;
return $daysAdded; return $daysAdded;
} }
private function preserveLinkedShowContent()
{
/* Get show content from any linekd instance. It doesn't
* matter which instance since content is the same in all.
*/
$ccShowInstance = $this->ccShow->getCcShowInstancess()->getFirst();
$ccSchedules = CcScheduleQuery::create()
->filterByDbInstanceId($ccShowInstance->getDbId())
->find();
if (!$ccSchedules->isEmpty()) {
$this->linkedShowContent = $ccSchedules;
}
}
public function getRepeatingEndDate() public function getRepeatingEndDate()
{ {
$sql = <<<SQL $sql = <<<SQL