Obj::TYPE_REGULAR, 'moreInfoType' => Obj::MORE_INFO_NONE, 'durationType' => Obj::DURATION_SINGLE, 'show' => 'y', 'showWaiver' => 'n', ); public function init() { parent::init(); $this->_initDefaults(); $this->addFormRule(array($this, '_validateForm')); return $this; } protected function _initDefaults() { if (!isset($this->_defaults['startDate'])) { $this->_defaults['startDate'] = date('Y-m-d', strtotime('+1 day')); } if (!isset($this->_defaults['endDate'])) { $this->_defaults['endDate'] = $this->_defaults['startDate']; } return $this; } protected function _validateForm() { $data = $this->getValues(); $errors = array(); $type = $this->_getData('type'); $durationType = $this->_getData('durationType'); $startDate = $data['startDate']; $endDate = $data['endDate']; if ((Obj::TYPE_COMMITTEE === $type) && Obj::DURATION_SINGLE !== $durationType) { $errors['durationType'][] = 'Selected event type compatible only with Duration "Single Day"'; } if (Obj::DURATION_SINGLE === $durationType) { if ($startDate && $endDate && $startDate != $endDate) { $errors['startDate'][] = 'Wrong End Date'; } } else { if ($startDate && $endDate && $startDate > $endDate) { $errors['startDate'][] = 'Start Date should be less that End Date'; } } if (Obj::TYPE_COMMITTEE == $type) { //check time ranges if (!$data['timeRanges']) { $errors['timeRanges'] = 'Value is required and can not be empty'; } else { foreach($data['timeRanges'] as $ranges) { if (empty($ranges[0])|| empty($ranges[1])) { $errors['timeRanges'] = 'Value is required and can not be empty'; } break; } } } if(Obj::TYPE_REGULAR === $type || Obj::TYPE_GROUP === $type) { $startTS = strtotime($startDate . ' ' . reset($data['timeRanges'])[0]); $regStartTS = strtotime($data['registrationStartDate'] . ' ' . $data['registrationStartTime']); $regEndTS = strtotime($data['registrationEndDate'] . ' ' . $data['registrationEndTime']); if ($data['registrationStartDate'] && $data['registrationEndDate'] && $regStartTS >= $regEndTS) { $errors['registrationEndDate'][] = 'Registration End Date should be greater than Registration Start Date'; } if ($data['registrationStartDate'] && $startDate && $regStartTS >= $startTS) { $errors['registrationStartDate'][] = 'Registration Start Date should be less than Event Start Date'; } if ($data['registrationEndDate'] && $startDate && $regEndTS > $startTS) { $errors['registrationEndDate'][] = 'Registration End Date should be less than Event Start Date'; } } return ($errors) ? $errors : true; } protected function _addTitleElement() { $this->addElement('text', 'title', array('label' => 'Title', 'required' => true)); return $this; } protected function _addMoreInfoElement() { $moreInfoType = $this->_getData('moreInfoType'); $this->addElement( 'radio', 'moreInfoType', array( 'label' => '"More Info" button on the Calendar pop-up box', 'multiOptions' => View::$moreInfoTypes, 'separator' => ' ', 'required' => true ) ); $this->addElement( 'text', 'moreInfoUrl', array( 'label' => 'URL', 'validators' => array('url'), 'description' => $this->_urlDescription, 'required' => (Obj::MORE_INFO_URL === $moreInfoType) ) ); $this->addElement( 'select', 'moreInfoPage', array( 'label' => 'Site Page', 'escapeLabel' => false, 'multiOptions' => array('' => '- Select Page -') + \App_Cms_Obj::getInstance()->getPages4Select(0), 'required' => (Obj::MORE_INFO_PAGE === $moreInfoType) ) ); $this->addDisplayGroup( array('moreInfoType', 'moreInfoUrl', 'moreInfoPage'), 'moreInfoGroup' ); foreach (array('moreInfoUrl', 'moreInfoPage') as $element) { $this->getElement($element)->getDecorator('Label')->setOption('class', 'required'); } return $this; } protected function _addTypeElement() { $this->addElement( 'radio', 'type', array( 'label' => 'Type', 'multiOptions' => View::$eventTypes, 'separator' => ' ', 'required' => true ) ); return $this; } protected function _getDuration() { $durationType = $this->_getData('durationType'); $duration = 1; if (Obj::DURATION_MULTIPLE === $durationType && ($startDate = $this->_getData('startDate')) && ($endDate = $this->_getData('endDate')) ) { try { $duration = \DateTime::createFromFormat('Y-m-d', $startDate)->diff( \DateTime::createFromFormat('Y-m-d', $endDate) )->days; $duration = ($duration >= 0) ? (int) $duration + 1 : 1; } catch (\Exception $e) {} } return $duration; } protected function _addDurationElement() { $durationType = $this->_getData('durationType'); $duration = $this->_getDuration(); $this->addElement( 'radio', 'durationType', array( 'label' => 'Event Duration', 'multiOptions' => View::$eventDurations, 'separator' => ' ', 'required' => true ) ); $this->addElement( 'date', 'startDate', array( 'label' => 'Start Date', 'required' => true ) ); $this->addElement( 'date', 'endDate', array( 'label' => 'End Date', 'required' => (Obj::DURATION_MULTIPLE === $durationType) ) ); $this->getElement('endDate')->getDecorator('Label')->setOption('class', 'required'); $this->addElement( 'timeRanges', 'timeRanges', array( 'label' => 'Time', 'count' => $duration, 'emptyOptions' => Obj::TYPE_COMMITTEE == $this->_getData('type'), 'required' => Obj::TYPE_COMMITTEE == $this->_getData('type') ) ); $this->addDisplayGroup( array('durationType', 'startDate', 'endDate', 'timeRanges'), 'durationGroup', array('legend' => 'Event Time') ); return $this; } protected function _addRegistrationTimeElement() { $type = $this->_getData('type'); $this->addElement( 'date', 'registrationStartDate', array( 'label' => 'Registration Start Date', ) ); $this->addElement( 'time', 'registrationStartTime', array('label' => 'Registration Start Time', 'emptyOptions' => false) ); $this->addElement( 'date', 'registrationEndDate', array( 'label' => 'Registration End Date', ) ); $this->addElement( 'time', 'registrationEndTime', array('label' => 'Registration End Time', 'emptyOptions' => false) ); $this->addElement( 'static', 'registrationAttention', array( 'label' => "Registration is not possible without both registration dates indicated " ) ); $this->getElement('registrationAttention')->getDecorator('Label')->setOption('escape', false); $this->addDisplayGroup( array('registrationStartDate', 'registrationStartTime', 'registrationEndDate', 'registrationEndTime', 'registrationAttention'), 'registrationGroup', array('legend' => 'Registration Time') ); return $this; } protected function _addLocationElement() { $type = $this->_getData('type'); $this->addElement('text', 'location', array('label' => 'Location', 'required' => Obj::TYPE_COMMITTEE === $type)); return $this; } protected function _addGoogleMapUrlElement() { $this->addElement( 'text', 'googleMapUrl', array( 'label' => 'Google Maps Event URL', 'validators' => array('url'), 'description' => $this->_urlDescription, ) ); return $this; } protected function _addDescriptionElement() { $this->addElement('htmlEditor', 'description', array('label' => 'Description', 'hasMsWordNote' => true)); return $this; } /** * For "Regular" and "Other" type only * @return AbstractForm */ protected function _addRegistrationUrlElement() { $this->addElement( 'text', 'registrationUrl', array( 'label' => 'Event Registration URL', 'validators' => array('url'), 'description' => $this->_urlDescription, ) ); return $this; } protected function _addGroupLimitElement() { $this->addElement( 'numeric', 'groupLimit', array( 'label' => 'Group Limit', 'precision' => 0, 'negative' => false, ) ); return $this; } protected function _addRegistrationLimitElement() { $this->addElement( 'numeric', 'registrationLimit', array( 'label' => 'Registration Limit', 'precision' => 0, 'negative' => false, ) ); return $this; } /** * For "Committee" type only * @return AbstractForm */ protected function _addCommitteeElement() { $type = $this->_getData('type'); $this->addElement( 'select', 'committeeId', array( 'label' => 'Committee', 'multiOptions' => array('' => 'Select One') + (array) $this->_getCommittees4Select(), 'required' => (Obj::TYPE_COMMITTEE === $type) ) ); $this->getElement('committeeId')->getDecorator('Label')->setOption('class', 'required'); return $this; } /** * For "Committee" type only * @return AbstractForm */ protected function _addAgendaElement() { $this->addElement( 'extendedFile', 'agendaFileName', array( 'label' => 'Meeting Agenda (.pdf)', 'validators' => array( array('File_Extension', false, array('pdf')) ) ) ); $this->getElement('agendaFileName')->getValidator('File_Extension')->setMessage( 'Only .pdf files allowed', \Qs_Validate_File_Extension::FALSE_EXTENSION ); return $this; } /** * For "Regular" type only * @return AbstractForm */ protected function _addRegularPriceElement() { $type = $this->_getData('type'); $this->addElement( 'numeric', 'regularPrice', array( 'label' => 'Regular Price', 'negative' => false, ) ); $this->getElement('regularPrice')->getDecorator('Numeric')->setAdditionalHtmlBeforeElement('$ '); return $this; } /** * For "Regular" and "Group" type only * @return AbstractForm */ protected function _addMemberPriceElement() { $type = $this->_getData('type'); $this->addElement( 'numeric', 'memberPrice', array( 'label' => 'Member Price', 'negative' => false, ) ); $this->getElement('memberPrice')->getDecorator('Numeric')->setAdditionalHtmlBeforeElement('$ '); return $this; } protected function _addShowElement() { $this->addElement('checkbox', 'show', array('label' => 'Show on user end', 'decoration' => 'simple')); return $this; } protected function _addShowWaiverElement() { $this->addElement('checkbox', 'showWaiver', array('label' => 'Show Waiver Paragraph', 'decoration' => 'simple')); return $this; } protected function _getCommittees4Select() { $table = new \Qs_Db_Table('Committee'); return $table->get4Select(); } }