'Member', AttendeeForm::TYPE_NONMEMBER => 'Nonmember' ]; protected $_renderMode = NewForm::RENDER_MODE_FULL; protected $_adminMode; protected $_editMode; protected $_currentUserId; protected $_currentUserName; protected $_allowMembers; protected $_allowNonMembers; protected $_allowCurrentUser; protected $_allowStatusChange = true; protected $_showStaticAttendeeType; protected $_deletedMemberAttendee; protected $_userAutocompleteUrl; protected $_allowDelete = true; protected $_isSpouse = false; protected $_hasSpouse = false; protected $_hasStatus = false; protected $_index; protected $_event; public function init() { parent::init(); if (NewForm::RENDER_MODE_FULL === $this->getRenderMode() && !$this->isSubmitted()) { $this->_defaults['attendType'] = ($this->getAllowCurrentUser()) ? AttendeeForm::ATTEND_MYSELF : AttendeeForm::ATTEND_OTHER; } $this->_initDFRelations(); return $this; } protected function _initPaths() { parent::_initPaths(); $this->addPrefixPath('App\\Event\\Form\\Element', 'App/Event/Form/Element/', 'element'); $this->addPrefixPath('App\\Event\\Form\\Decorator', 'App/Event/Form/Decorator/', 'decorator'); return $this; } public function hasSpouse() { return $this->_hasSpouse; } public function setHasSpouse($hasSpouse) { $this->_hasSpouse = $hasSpouse; return $this; } public function isHasStatus() { return $this->_hasStatus; } public function setHasStatus($hasStatus) { $this->_hasStatus = $hasStatus; return $this; } public function isAllowStatusChange() { return $this->_allowStatusChange; } public function setAllowStatusChange($allowStatusChange) { $this->_allowStatusChange = $allowStatusChange; return $this; } public function isSubmitted() { $method = $this->getMethod(); if (0 == strcasecmp($_SERVER['REQUEST_METHOD'], $method)) { $data = \Qs_Request::get($method); $itemIdMatched = true; if (($itemId = $this->getCmsItemId())) { $itemIdMatched = (isset($data['__idItem']) && $data['__idItem'] == $itemId); } return ($itemIdMatched && (0 === strpos($data['action'], 'insert') || 0 === strpos($data['action'], 'update'))); } return false; } protected function _getRequestPrefix() { return "attendee[{$this->getIndex()}]"; } protected function _getSubData($field = null, $default = null) { $result = null; if ($this->isSubmitted()) { $request = \Qs_Array::get(\Qs_Request::get($this->getMethod()), $this->_getRequestPrefix()); if (false === $field) { $result = $request; } else { $result = \Qs_Array::get($request, $field); } } if (null === $result) { if (null === $field) { $result = $this->_defaults; } else { $result = \Qs_Array::get($this->_defaults, $field); } } return (null === $result) ? $default : $result; } protected function _initElements() { if ($this->getAllowCurrentUser() && $this->getCurrentUserId()) { $options = [ AttendeeForm::ATTEND_MYSELF => 'Myself', AttendeeForm::ATTEND_OTHER => 'Another Member', ]; $this->addElement( 'radio', 'attendType', [ 'label' => 'Attendee Type', 'separator' => '   ', 'multiOptions' => $options, 'required' => true, 'data-attend-type' => '', ] ); $this->getElement('attendType')->getDecorator('label')->setTagOption('class', 'attend-type-label'); $this->getElement('attendType')->getDecorator('HtmlTag')->setOption('class', 'attend-type-element'); } else { $this->addElement('hidden', 'attendType', ['value' => AttendeeForm::ATTEND_OTHER]); } $this->_addCurrentGroup(); $this->_addOtherGroup(); $this->_initCommonFields(); if ($this->getAllowDelete()) { $this->addElement( 'button', 'delete', [ 'label' => 'Delete', 'class' => 'btn btn-danger', 'data-action' => 'delete', 'ignore' => true, ] ); $dtDdWrapper = $this->getElement('delete')->getDecorator('DtDdWrapper'); $dtDdWrapper->setDtAttrib('class', 'attendee-delete-label'); $dtDdWrapper->setDdAttrib('class', 'attendee-delete'); } return $this; } protected function _addCurrentGroup() { if ($this->getAllowCurrentUser() && $this->getCurrentUserId()) { $this->addElement('hidden', 'currentId', ['value' => $this->getCurrentUserId()]); $this->addElement( 'static', 'currentName', [ 'label' => 'Member\'s Name', 'value' => $this->getCurrentUserName(), 'required' => !$this->isSubmitted() ] ); $this->addDisplayGroup(['currentId', 'currentName'], 'myself-group'); $this->getDisplayGroup('myself-group')->getDecorator('dtDdWrapper')->setDtAttrib('class', 'myself-group-label'); $this->getDisplayGroup('myself-group')->getDecorator('dtDdWrapper')->setDdAttrib('class', 'myself-group'); } return $this; } protected function _addOtherGroup() { $isSubmitted = $this->isSubmitted(); $allowMembers = (bool)$this->getAllowMembers(); $allowNonMembers = (bool)$this->getAllowNonMembers(); $groupFields = ['type']; if ($allowMembers && $allowNonMembers) { $type = $this->_getSubData('type'); $this->addElement( 'radio', 'type', [ 'label' => 'Attendee Type', 'separator' => '   ', 'multiOptions' => self::$_typeTitles, 'required' => true ] ); } else { $type = ($allowMembers && !$allowNonMembers) ? AttendeeForm::TYPE_MEMBER : AttendeeForm::TYPE_NONMEMBER; $this->addElement('hidden', 'type', ['value' => $type]); if ($this->getShowStaticAttendeeType()) { $this->addElement('static', 'typeTitle', ['label' => 'Attendee Type', 'value' => self::$_typeTitles[$type]]); $groupFields[] = 'typeTitle'; } } if ($this->isHasStatus()) { $this->addElement( 'select', 'status', [ 'label' => 'Attendance Status', 'required' => true, 'multiOptions' => ['' => 'Select One'] + (array)(new Qs_Db_Table('EventAttendeeStatus'))->get4Select(), 'value' => 'enrolled', ] ); if (!$this->isAllowStatusChange()) { $this->getElement('status')->setAttrib('disabled', 'disabled')->setIgnore(true)->setRequired(false); } $groupFields[] = 'status'; $this->addElement( 'numeric', 'attendedCeus', [ 'label' => 'Attended Hours', 'negative' => false, 'append' => 'hr(s)', ] ); $groupFields[] = 'attendedCeus'; } $attendType = $this->_getData('attendType'); if ($allowMembers) { $required = ($isSubmitted && (AttendeeForm::ATTEND_OTHER === $attendType) && AttendeeForm::TYPE_MEMBER == $this->_getSubData('type') ); $this->addElement( 'autocomplete', 'id', [ 'label' => 'Member\'s Name', 'dataUrl' => $this->getUserAutocompleteUrl(), 'required' => $required, ] ); if (!$this->getAdminMode()) { $this->getElement('id')->setDescription($this->getConfig('memberAutocompleteNote')); } $groupFields[] = 'id'; if (($userId = $this->_getSubData('id')) && false !== ($userName = UserObj::getAutocompleteItemTitle($userId, 'event'))) { $this->getElement('id')->setTitle($userName); } if (($msg = $this->getDeletedMemberAttendee())) { $this->getElement('id')->setRequired(false); $this->getElement('id')->setDescription($msg); } else { $this->getElement('id')->getDecorator('label')->setOption('class', 'required'); } } if ($allowNonMembers) { $required = ($isSubmitted && (AttendeeForm::ATTEND_OTHER === $attendType) && AttendeeForm::TYPE_NONMEMBER === $type); $this->addElement('text', 'firstName', ['label' => 'First Name', 'required' => $required, 'filters' => ['StringTrim']]); $this->addElement('text', 'lastName', ['label' => 'Last Name', 'required' => $required, 'filters' => ['StringTrim']]); $groupFields[] = 'firstName'; $groupFields[] = 'lastName'; if (!$this->getIsSpouse()) { $this->addElement('text', 'email', ['label' => 'Email', 'required' => $required, 'filters' => ['StringTrim']]); $this->addElement('text', 'jobTitle', ['label' => 'Job Title', 'required' => $required, 'filters' => ['StringTrim']]); $this->addElement('text', 'company', ['label' => 'Utility or Company', 'required' => $required, 'filters' => ['StringTrim']]); $this->addElement('text', 'supervisorName', ['label' => 'Name of Supervisor', 'filters' => ['StringTrim']]); $this->getElement('email')->addValidator('emailAddress'); $groupFields[] = 'email'; $groupFields[] = 'jobTitle'; $groupFields[] = 'company'; $groupFields[] = 'supervisorName'; } foreach (['id', 'firstName', 'lastName', 'email', 'jobTitle', 'company'] as $name) { if (($element = $this->getElement($name))) { $element->getDecorator('label')->setOption('class', 'required'); } } } $this->addDisplayGroup($groupFields, 'other-group'); $this->getDisplayGroup('other-group')->getDecorator('dtDdWrapper')->setDtAttrib('class', 'other-group-label'); $this->getDisplayGroup('other-group')->getDecorator('dtDdWrapper')->setDdAttrib('class', 'other-group'); return $this; } protected function _initCommonFields() { $typeRule = new TypeRule($this->getEvent()['type']); if ($typeRule->featureSpouse && !$this->hasSpouse() && !$this->getIsSpouse()) { $this->_addSpouseFields(); } if ($typeRule->featureOptions) { $this->_addOptionForm(); } if ($typeRule->featureProducts && !$this->getAdminMode() && !$this->getEditMode()) { $this->_addProductElement(); } return $this; } protected function _addProductElement() { /** @var \App\Event\Form\Element\ProductList $productList */ $productList = $this->createElement( 'productList', 'products', ['label' => 'Products', 'eventId' => $this->getEvent()['id']] ); if ($productList->getProducts()) { $this->addElement($productList); } return $this; } protected function _addOptionForm() { if ($optionList = Model::readEventListOptions($this->getEvent()['id'])) { $optionForm = new OptionListForm([ 'optionList' => $optionList, ]); $optionForm->getDecorator('dtDdWrapper')->setOption('label', 'Options'); $optionForm->getDecorator('dtDdWrapper')->setOption('labelAttribs', ['class' => 'required']); $optionForm->getDecorator('fieldset')->setOption('class', 'option-list'); $this->addSubForm($optionForm, 'optionList'); } return $this; } protected function _addSpouseFields() { $required = !$this->isSubmitted() || 'y' === $this->_getSubData('spouseEnabled'); $this->addElement('checkbox', 'spouseEnabled', ['label' => 'Register My Spouse/Partner', 'decoration' => 'simple']); $this->addElement('text', 'spouseFirstName', ['label' => 'Spouse/Partner First Name', 'required' => $required]); $this->addElement('text', 'spouseLastName', ['label' => 'Spouse/Partner Last Name', 'required' => $required]); return $this; } public function initRender() { $this->getDecorator('Fieldset')->setOption('data-attendee', $this->getIndex()); if ($this->_getFormHidden()) { $this->getDecorator('Fieldset')->setOption('class', 'hidden'); } return parent::initRender(); } protected function _getFormHidden() { $result = true; foreach ($this->getElements() as $element) { if (!($element instanceof Zend_Form_Element_Hidden)) { $result = false; break; } } return $result; } public function loadDefaultDecorators() { if (false == $this->loadDefaultDecoratorsIsDisabled() && null == $this->getDecorators()) { $this->addDecorator('FormElements') ->addDecorator('HtmlTag', ['tag' => 'dl']) ->addDecorator('Fieldset'); } return $this; } public function setCurrentUserId($currentUserId) { $this->_currentUserId = $currentUserId; return $this; } public function getCurrentUserId() { return $this->_currentUserId; } public function getCurrentUserName() { return $this->_currentUserName; } public function setCurrentUserName($currentUserName) { $this->_currentUserName = $currentUserName; return $this; } public function setAllowMembers($allowMembers) { $this->_allowMembers = $allowMembers; return $this; } public function getAllowMembers() { return $this->_allowMembers; } public function setAllowNonMembers($allowNonMembers) { $this->_allowNonMembers = $allowNonMembers; return $this; } public function getAllowNonMembers() { return $this->_allowNonMembers; } public function getAllowCurrentUser() { return $this->_allowCurrentUser; } public function setAllowCurrentUser($allowCurrentUser) { $this->_allowCurrentUser = $allowCurrentUser; return $this; } public function setUserAutocompleteUrl($userAutocompleteUrl) { $this->_userAutocompleteUrl = $userAutocompleteUrl; return $this; } public function getUserAutocompleteUrl() { if (null === $this->_userAutocompleteUrl) { throw new Qs_Exception_EmptyPropertyException($this, '_userAutocompleteUrl'); } return $this->_userAutocompleteUrl; } public function setIndex($index) { $this->_index = $index; return $this; } public function getIndex() { if (null === $this->_index) { throw new Qs_Exception_EmptyPropertyException($this, '_index'); } return $this->_index; } public function getItem($name) { // we use FixTrait that brakes element ids return null; } protected function _initDFRelations() { $this->_dfRelations = []; $idx = $this->getIndex(); $namePrefix = 'attendee[' . $idx . ']'; $idPrefix = '#attendee-' . $idx . '-'; if (!($this->getElement('attendType') instanceof Zend_Form_Element_Hidden)) { $this->_dfRelations[] = [ '_element' => 'attendType', 'node' => '[name="' . $namePrefix . '[attendType]"]:checked', 'group' => '[name="' . $namePrefix . '[attendType]"]', 'event' => 'change', 'rules' => [ [ 'value' => AttendeeForm::ATTEND_MYSELF, 'nodes' => [$idPrefix . 'myselfgroup-element'], '_elements' => ['myself-group'], ], [ 'value' => AttendeeForm::ATTEND_OTHER, 'nodes' => [$idPrefix . 'othergroup-element'], '_elements' => ['other-group'], ] ], ]; } if (!($this->getElement('type') instanceof Zend_Form_Element_Hidden)) { $this->_dfRelations[] = [ '_element' => 'type', 'node' => '[name="' . $namePrefix . '[type]"]:checked', 'group' => '[name="' . $namePrefix . '[type]"]', 'event' => 'change', 'rules' => [ [ 'value' => AttendeeForm::TYPE_MEMBER, 'nodes' => [$idPrefix . 'id-label', $idPrefix . 'id-element'], '_elements' => ['id'], ], [ 'value' => AttendeeForm::TYPE_NONMEMBER, 'nodes' => [ $idPrefix . 'firstName-label', $idPrefix . 'firstName-element', $idPrefix . 'lastName-label', $idPrefix . 'lastName-element', $idPrefix . 'email-label', $idPrefix . 'email-element', $idPrefix . 'jobTitle-label', $idPrefix . 'jobTitle-element', $idPrefix . 'company-label', $idPrefix . 'company-element', $idPrefix . 'supervisorName-label', $idPrefix . 'supervisorName-element', ], '_elements' => ['firstName', 'lastName', 'email', 'jobTitle', 'company', 'supervisorName'], ], ] ]; } if ($this->getElement('spouseEnabled')) { $namePrefix = 'attendee[' . $idx . ']'; $idPrefix = '#attendee-' . $idx . '-'; $this->_dfRelations[] = [ '_element' => 'spouseEnabled', 'node' => '[name="' . $namePrefix . '[spouseEnabled]"]', 'event' => 'change', 'rules' => [ [ '_value' => 'y', '_elements' => ['spouseFirstName', 'spouseLastName'], 'value' => new \Zend_Json_Expr('(function () { return this.is(":checked"); })'), 'nodes' => [ $idPrefix . 'spouseFirstName-label', $idPrefix . 'spouseFirstName-element', $idPrefix . 'spouseLastName-label', $idPrefix . 'spouseLastName-element', ], ], [ '_value' => 'n', '_elements' => [], 'value' => new \Zend_Json_Expr('(function () { return !this.is(":checked"); })'), 'nodes' => [], ], ] ]; } if ($this->isHasStatus()) { $this->_dfRelations[] = [ '_element' => 'status', 'node' => '[name="' . $namePrefix . '[status]"]', 'event' => 'change', 'rules' => [ [ 'value' => \App\Event\Attendee\Entity::STATUS_ATTENDED, 'nodes' => [$idPrefix . 'attendedCeus-label', $idPrefix . 'attendedCeus-element'], '_elements' => ['attendedCeus'], ], ], ]; } return $this; } protected function _addResources() { if ($this->_dfRelations) { $dynamicFormOptions = [ 'relations' => $this->dfConvertRelations() ]; /** @var $doc \Qs_Doc */ $doc = Zend_Registry::get('doc'); $doc->addScript('js/jquery.dynamicForm.js'); $doc->addInitFunction('$("#attendee-fieldset-' . $this->getIndex() . '").dynamicForm', [$dynamicFormOptions]); /** @var \Qs_Form_Element_Autocomplete $element */ if (($element = $this->getElement('id'))) { $defaultHintOptions = array( 'useWrapper' => true, 'elements' => array( array('selector' => '#' . $element->getDisplayId(), 'hint' => 'Autocomplete field', 'required' => false), ) ); $doc->addScript('js/jquery.defaultHint.js'); $doc->addInitFunction('$().defaultHint', [$defaultHintOptions]); } } return parent::_addResources(); } public function getValues($suppressArrayNotation = false) { $values = parent::getValues($suppressArrayNotation); if ($values['attendType'] === AttendeeForm::ATTEND_MYSELF) { $values['id'] = $values['currentId']; } $values['attendedCeus'] = floatval($values['attendedCeus']); if (!$values['attendedCeus']) { $values['attendedCeus'] = null; } $this->dfClearUnusedValues($values); return $values; } /** * @param string $name element name * @return string element label id (e.g. foo-label) */ protected function _dfGetElementLabelId($name) { return null; } /** * @param string $name element name * @return string element container id (e.g. foo-element) */ protected function _dfGetElementContainerId($name) { return null; } public function setAllowDelete($allowDelete) { $this->_allowDelete = $allowDelete; return $this; } public function getAllowDelete() { return $this->_allowDelete; } public function setShowStaticAttendeeType($showStaticAttendeeType) { $this->_showStaticAttendeeType = $showStaticAttendeeType; return $this; } public function getShowStaticAttendeeType() { return $this->_showStaticAttendeeType; } public function getDeletedMemberAttendee() { return $this->_deletedMemberAttendee; } public function setDeletedMemberAttendee($message) { $this->_deletedMemberAttendee = $message; return $this; } public function getEvent() { if (null == $this->_event) { throw new \Exception('Required property "' . __CLASS__ . '->_event" is missing'); } return $this->_event; } public function setEvent(array $event) { $this->_event = $event; return $this; } public function getEditMode() { return $this->_editMode; } public function getAdminMode() { return $this->_adminMode; } public function setAdminMode($adminMode) { $this->_adminMode = $adminMode; return $this; } public function setEditMode($editMode) { $this->_editMode = $editMode; return $this; } public function getIsSpouse() { return $this->_isSpouse; } public function setIsSpouse($isSpouse) { $this->_isSpouse = $isSpouse; return $this; } public function getRenderMode() { return $this->_renderMode; } public function setRenderMode($renderMode) { $this->_renderMode = $renderMode; return $this; } }