diff --git a/airtime_mvc/application/services/ShowFormService.php b/airtime_mvc/application/services/ShowFormService.php index 92ffa4907..8af6a78fa 100644 --- a/airtime_mvc/application/services/ShowFormService.php +++ b/airtime_mvc/application/services/ShowFormService.php @@ -155,19 +155,18 @@ class Application_Service_ShowFormService if ($ccShowDay->isShowStartInPast()) { //for a non-repeating show, we should never allow user to change the start time. //for a repeating show, we should allow because the form works as repeating template form - $form->disableStartDateAndTime(); - - // Removing this - if there is no future instance, this will throw an error. - // If there is a future instance, then we get a WHEN block representing the next instance - // which may be confusing. - /*if (!$ccShowDay->isRepeating()) { + if (!$ccShowDay->isRepeating()) { $form->disableStartDateAndTime(); } else { - list($showStart, $showEnd) = $this->getNextFutureRepeatShowTime(); + $showStartAndEnd = $this->getNextFutureRepeatShowTime(); + if (!is_null($showStartAndEnd)) { + $showStart = $showStartAndEnd["starts"]; + $showEnd = $showStartAndEnd["ends"]; + } if ($this->hasShowStarted($showStart)) { $form->disableStartDateAndTime(); } - }*/ + } } $form->populate( @@ -183,6 +182,29 @@ class Application_Service_ShowFormService return $showStart; } + public function getNextFutureRepeatShowTime() + { + $ccShowInstance = CcShowInstancesQuery::create() + ->filterByDbShowId($this->ccShow->getDbId()) + ->filterByDbModifiedInstance(false) + ->filterByDbStarts(gmdate("Y-m-d H:i:s"), Criteria::GREATER_THAN) + ->orderByDbStarts() + ->findOne(); + + if (!$ccShowInstance) { + return null; + } + + $starts = new DateTime($ccShowInstance->getDbStarts(), new DateTimeZone("UTC")); + $ends = new DateTime($ccShowInstance->getDbEnds(), new DateTimeZone("UTC")); + $showTimezone = $this->ccShow->getFirstCcShowDay()->getDbTimezone(); + + $starts->setTimezone(new DateTimeZone($showTimezone)); + $ends->setTimezone(new DateTimeZone($showTimezone)); + + return array("starts" => $starts, "ends" => $ends); + } + private function populateInstanceFormWhen($form) { $ccShowInstance = CcShowInstancesQuery::create()->findPk($this->instanceId); @@ -437,7 +459,7 @@ class Application_Service_ShowFormService $ccShowInstance = CcShowInstancesQuery::create() ->filterByDbShowId($this->ccShow->getDbId()) ->filterByDbModifiedInstance(false) - ->filterByDbStarts(gmdate("Y-m-d"), Criteria::GREATER_EQUAL) + ->filterByDbStarts(gmdate("Y-m-d H:i:s"), Criteria::GREATER_EQUAL) ->orderByDbStarts() ->findOne();