diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index 4760e7f3d..157d86f14 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -98,6 +98,9 @@ class ScheduleController extends Zend_Controller_Action $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.FixedColumns.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.columnFilter.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'js/libs/moment.min.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'js/libs/moment-timezone-with-data-2010-2020.min.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'js/airtime/buttons/buttons.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/events/library_showbuilder.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/library.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); @@ -584,7 +587,20 @@ class ScheduleController extends Zend_Controller_Action $forms = $this->createShowFormAction(); $this->view->addNewShow = true; - + + if ($data['add_show_start_now'] == "now") { + + //have to use the timezone the user has entered in the form to check past/present + $showTimezone = new DateTimeZone($data["add_show_timezone"]); + $nowDateTime = new DateTime("now", $showTimezone); + //$showStartDateTime = new DateTime($start_time, $showTimezone); + //$showEndDateTime = new DateTime($end_time, $showTimezone); + + $data['add_show_start_time'] = $nowDateTime->format("H:i"); + $data['add_show_start_date'] = $nowDateTime->format("Y-m-d"); + } + + if ($service_showForm->validateShowForms($forms, $data)) { // Get the show ID from the show service to pass as a parameter to the RESTful ShowImageController $this->view->showId = $service_show->addUpdateShow($data); diff --git a/airtime_mvc/application/forms/AddShowWhen.php b/airtime_mvc/application/forms/AddShowWhen.php index d6edbe0cd..0f8f4094e 100644 --- a/airtime_mvc/application/forms/AddShowWhen.php +++ b/airtime_mvc/application/forms/AddShowWhen.php @@ -15,11 +15,26 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm "/^[0-2]?[0-9]:[0-5][0-9]$/", _("'%value%' does not fit the time format 'HH:mm'")); + + // Add start date element + $startNow = new Zend_Form_Element_Radio('add_show_start_now'); + $startNow->setRequired(false) + ->setLabel(_('Start Time:')) + ->addMultiOptions(array( + 'now' => 'Now', + 'future' => 'In the Future:' + )) + ->setValue('future') + ->setDecorators(array('ViewHelper')); + //$startDate->setAttrib('alt', 'date'); + $this->addElement($startNow); + + // Add start date element $startDate = new Zend_Form_Element_Text('add_show_start_date'); $startDate->class = 'input_text'; $startDate->setRequired(true) - ->setLabel(_('Date/Time Start:')) + ->setLabel(_('In the Future:')) ->setValue(date("Y-m-d")) ->setFilters(array('StringTrim')) ->setValidators(array( @@ -46,7 +61,7 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm $endDate = new Zend_Form_Element_Text('add_show_end_date_no_repeat'); $endDate->class = 'input_text'; $endDate->setRequired(true) - ->setLabel(_('Date/Time End:')) + ->setLabel(_('End Time:')) ->setValue(date("Y-m-d")) ->setFilters(array('StringTrim')) ->setValidators(array( @@ -119,7 +134,7 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm $showStartDateTime = new DateTime($start_time, $showTimezone); $showEndDateTime = new DateTime($end_time, $showTimezone); - if ($validateStartDate) { + if ($validateStartDate && ($formData['add_show_start_now'] != "now")) { if ($showStartDateTime < $nowDateTime) { $this->getElement('add_show_start_time')->setErrors(array(_('Cannot create show in the past'))); $valid = false; diff --git a/airtime_mvc/application/services/ShowFormService.php b/airtime_mvc/application/services/ShowFormService.php index 92ffa4907..962a4de67 100644 --- a/airtime_mvc/application/services/ShowFormService.php +++ b/airtime_mvc/application/services/ShowFormService.php @@ -155,21 +155,23 @@ 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(); } - }*/ + } } + //Disable starting a show 'now' when editing an existing show. + $form->getElement('add_show_start_now')->setAttrib('disable', array('now')); + $form->populate( array( 'add_show_start_date' => $showStart->format("Y-m-d"), @@ -183,6 +185,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); @@ -203,8 +228,12 @@ class Application_Service_ShowFormService $form->disableStartDateAndTime(); } + //Disable starting a show 'now' when editing an existing show. + $form->getElement('add_show_start_now')->setAttrib('disable', array('now')); + $form->populate( array( + 'add_show_start_now' => 'future', 'add_show_start_date' => $showStart->format("Y-m-d"), 'add_show_start_time' => $showStart->format("H:i"), 'add_show_end_date_no_repeat' => $showEnd->format("Y-m-d"), @@ -437,7 +466,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(); diff --git a/airtime_mvc/application/views/scripts/form/add-show-when.phtml b/airtime_mvc/application/views/scripts/form/add-show-when.phtml index 5a5cc1725..e33d2f3a5 100644 --- a/airtime_mvc/application/views/scripts/form/add-show-when.phtml +++ b/airtime_mvc/application/views/scripts/form/add-show-when.phtml @@ -1,8 +1,18 @@
+
+ +
+
+ element->getElement('add_show_start_now') ?> +
+ +
@@ -19,6 +29,9 @@ + + +