['asBilling' => 'y']]; protected $_emailUniqueMessage = 'This email address is already associated with an account.'; protected $_states4Select; protected $_memberships; protected $_hasSeoFields = false; /** * @return AdminObj */ protected function _getDataObj() { if (null === $this->_dataObj) { $this->_dataObj = new AdminObj(); } return $this->_dataObj; } /** * @return CartObj */ protected function _getCart() { return CartObj::getInstance(); } /** * Elements for "simple" mode * @return $this */ protected function _initSimpleElements() { $this->_initPersonalInfoFields(); $this->_initCheckoutFields(); return $this; } /** * Elements for "association" mode * @return $this */ protected function _initAssociationElements() { $this->_initMembershipTypeFields(); $this->_initCompanyFields(); $this->_initIndividualFields(); return $this; } /** * "Personal" fields for "simple" mode * @return $this */ protected function _initPersonalInfoFields() { $this->addElement('text', 'firstName', ['label' => 'First Name', 'required' => true]); $this->addElement('text', 'lastName', ['label' => 'Last Name', 'required' => true]); $this->addElement('phone', 'directPhone', ['label' => 'Phone Number', 'required' => true]); $this->addElement( 'email', 'email', ['label' => 'Email Address', 'required' => true, 'attribs' => ['autocomplete' => 'off']] ); $uniqueValidator = new Qs_Validate_Unique(new Qs_Db_Table('User'), 'email', $this->_getData('id')); $uniqueValidator->setMessage($this->_emailUniqueMessage, Qs_Validate_Unique::NOT_UNIQUE); $this->getElement('email')->addValidator($uniqueValidator); $this->addElement( 'password', 'password', ['label' => 'Password', 'attribs' => ['autocomplete' => 'off']] ); $this->getElement('password')->addValidator('Callback', true, [[$this, 'validatePassword']]); $this->addElement( 'password', 'confirmPassword', ['label' => 'Confirm Password', 'attribs' => ['autocomplete' => 'off']] ); $this->getElement('confirmPassword')->addValidator('ConfirmPassword', true, ['password']); $this->addDisplayGroup( ['firstName', 'lastName', 'directPhone', 'email', 'password', 'confirmPassword'], 'personalInfo', ['legend' => 'Personal Information'] ); return $this; } protected function _initCheckoutFields($isRequired = true) { $this->_initAddressFields(Entity::ADDRESS_BILLING, $isRequired); $this->_initAddressFields(Entity::ADDRESS_SHIPPING, $isRequired); return $this; } /** * "Address" fields for "simple" mode * @param string $type * @param bool $isRequired * @return $this */ protected function _initAddressFields($type, $isRequired = true) { $form = new Qs_Form_SubForm(['legend' => ucfirst($type) . ' Address']); if ($type != Entity::ADDRESS_BILLING) { $form->addElement( 'checkbox', 'asBilling', ['label' => 'My shipping address is the same as my billing address', 'decoration' => 'simple'] ); } $form->addElement('text', 'firstName', ['label' => 'First Name']); $form->addElement('text', 'lastName', ['label' => 'Last Name']); $form->addElement('text', 'address', ['label' => 'Address']); $form->addElement('text', 'city', ['label' => 'City', 'class' => 'city']); $form->addElement( 'select', 'state', [ 'label' => 'State', 'class' => 'state', 'multiOptions' => ['' => 'Select One'] + $this->_getStates4Select(), ] ); $form->addElement('zip', 'zip', ['label' => 'Zip', 'class' => 'zip']); if ($isRequired) { /** @var $element \Zend_Form_Element */ $element = null; if ($type == Entity::ADDRESS_BILLING) { foreach ($form as $element) { $element->setRequired(); } } else { $asBilling = $this->_getData($type . '[asBilling]'); foreach ($form as $element) { if ('asBilling' == $element->getName()) { continue; } if ($asBilling && 'n' == $asBilling) { $element->setRequired(); } else { $element->getDecorator('Label')->setOption('class', 'required'); } } } } $this->addSubForm($form, $type); return $this; } /** * "Membership type" fields for "association" mode * @return $this */ protected function _initMembershipTypeFields() { $multioptions = ['' => 'Select One'] + $this->_getMemberships(true); $this->addElement( 'select', 'membershipTypeId', ['label' => 'Membership Type', 'required' => true, 'multioptions' => $multioptions] ); return $this; } /** * "Company" fields for "association" mode * @return $this */ protected function _initCompanyFields() { $form = new Qs_Form_SubForm(['legend' => 'Company Information']); $form->addElement('text', 'name', ['label' => 'Company', 'required' => true]); $form->addElement('text', 'address', ['label' => 'Address 1', 'required' => true]); $form->addElement('text', 'address2', ['label' => 'Address 2']); $form->addElement('text', 'city', ['label' => 'City', 'required' => true]); $multioptions = ['' => 'Select One'] + $this->_getStates4Select(); $form->addElement( 'select', 'state', ['label' => 'State', 'required' => true, 'multioptions' => $multioptions] ); $form->addElement('zip', 'zip', ['label' => 'Zip', 'required' => true]); $form->addElement('phone', 'phone', ['label' => 'Phone Number']); $form->addElement('phone', 'fax', ['label' => 'Fax Number']); $this->addSubForm($form, 'company'); return $this; } /** * "Personal" fields for "association" mode * @param bool $full * @return $this */ protected function _initIndividualFields($full = false) { $this->_showDisplayGroupLegend('personalInfo', 'Personal Information'); $this->addElement('text', 'firstName', ['label' => 'First Name', 'required' => true]); $this->addElement('text', 'lastName', ['label' => 'Last Name', 'required' => true]); if ($this->_hasSeoFields) { $this->addSeoGroup('User', ['firstName', 'lastName']); } if ($full) { $photoConfig = $this->getConfig('photo'); $resize = $photoConfig->width . 'x' . $photoConfig->height . Qs_ImageFs::getResizeMethodAlias($photoConfig->resizeMethod); $this->addElement( 'extendedImage', 'photo', [ 'label' => 'Photo', 'resize' => $resize, 'required' => true, 'defaultThumbnail' => 'images/member-no-photo.png', ] ); $this->addElement('htmlEditor', 'bio', ['label' => 'Bio']); $this->addElement( 'url', 'linkedInUrl', [ 'label' => 'LinkedIn URL', 'description' => 'Example: http://www.linkedin.com/company/adapta-interactive', ] ); } $this->_initHomeAddressFields(); $this->addElement('phone', 'directPhone', ['label' => 'Direct Phone Number', 'required' => true]); $this->addElement('phone', 'cellPhone', ['label' => 'Cell Phone Number']); $this->addElement( 'email', 'email', ['label' => 'Email Address', 'required' => true, 'attribs' => ['autocomplete' => 'off']] ); // validate email registration $hasRegistration = new Qs_Validate_Unique(new Qs_Db_Table('User'), 'email', $this->_getData('id')); $hasRegistration->setWhere('`bought` = "y"'); $hasRegistration->setMessage($this->_emailUniqueMessage, Qs_Validate_Unique::NOT_UNIQUE); $this->getElement('email')->addValidator($hasRegistration, true); // validate email in cart $options = ['cartId' => $this->_getCart()->getCartId()]; $inCart = new NotInCart($options); $this->getElement('email')->addValidator($inCart, true); $this->addElement( 'password', 'password', ['label' => 'Password', 'attribs' => ['autocomplete' => 'off']] ); $this->getElement('password')->addValidator('Callback', true, [[$this, 'validatePassword']]); $this->addElement( 'password', 'confirmPassword', ['label' => 'Confirm Password', 'attribs' => ['autocomplete' => 'off']] ); $this->getElement('confirmPassword')->addValidator('ConfirmPassword', true, ['password']); return $this; } /** * "Address" fields for "association" mode * @return $this */ protected function _initHomeAddressFields() { $form = new Qs_Form_SubForm(); $form->addElement('text', 'address', ['label' => 'Home Address 1']); $form->addElement('text', 'address2', ['label' => 'Home Address 2']); $form->addElement('text', 'city', ['label' => 'Home City', 'class' => 'city']); $form->addElement( 'select', 'state', [ 'label' => 'Home State', 'class' => 'state', 'multiOptions' => ['' => 'Select One'] + $this->_getStates4Select(), ] ); $form->addElement('zip', 'zip', ['label' => 'Home Zip', 'class' => 'zip']); $this->addSubForm($form, Entity::ADDRESS_HOME); return $this; } /** * @param string $elementName * @param string $legend * @return $this */ protected function _showDisplayGroupLegend($elementName, $legend) { $this->addElement('header', $elementName, ['label' => $legend]); $this->getElement($elementName)->getDecorator('HtmlTag')->setOption('class', 'form_header form-header-lg'); return $this; } protected function _getScriptOptions() { $options['formId'] = $this->getId(); if (Module::MODE_ASSOCIATION == $this->getConfig('mode')) { $memberships = $this->_getMemberships(); array_walk_recursive( $memberships, function (&$item, $key) { if ($key != 'summary') $item = htmlspecialchars($item); } ); $options['memberships'] = $memberships; } $options['addressTypes'] = [Entity::ADDRESS_SHIPPING]; if ($this->getSubForm(Entity::ADDRESS_BILLING)) { $options['addressFields'] = array_keys($this->getSubForm(Entity::ADDRESS_BILLING)->getElements()); } $options['inheritedAddress'] = Entity::ADDRESS_BILLING; return $options; } public function render(\Zend_View_Interface $view = null) { /** @var $doc \App_Doc_Admin */ $doc = Zend_Registry::get('doc'); $doc->addScript('js/app/user/form.js'); $doc->addInitObject('app.user.form', [$this->_getScriptOptions()], 'appUserForm'); return parent::render($view); } public function validatePassword($value, $context = null) { if (!empty($value) && empty($context['confirmPassword'])) { $this->getElement('confirmPassword')->setRequired()->isValid(''); $this->getElement('confirmPassword')->setErrors(['Password confirmation does not match']); } return true; } protected function _getStates4Select() { if (null === $this->_states4Select) { $this->_states4Select = $this->_getDataObj()->getDState4Select(); } return $this->_states4Select; } protected function _getMemberships($forSelect = false) { if (null === $this->_memberships) { try { $table = new Qs_Db_Table('MembershipType'); $this->_memberships = $table->fetchAll(null, 'sorter')->toArray(); } catch (Qs_Exception $e) { $this->_memberships = []; } if ($this->_memberships) { $keys = Qs_Array::fetchCol($this->_memberships, 'id'); $this->_memberships = array_combine($keys, $this->_memberships); } } if ($forSelect && $this->_memberships) { return array_combine( Qs_Array::fetchCol($this->_memberships, 'id'), Qs_Array::fetchCol($this->_memberships, 'title') ); } return $this->_memberships; } }