array('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', array('label' => 'First Name', 'required' => true)); $this->addElement('text', 'lastName', array('label' => 'Last Name', 'required' => true)); $this->addElement('phone', 'directPhone', array('label' => 'Phone Number', 'required' => true)); $this->addElement( 'email', 'email', array('label' => 'Email Address', 'required' => true, 'attribs' => array('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', array('label' => 'Password', 'attribs' => array('autocomplete' => 'off')) ); $this->getElement('password')->addValidator('Callback', true, array(array($this, 'validatePassword'))); $this->addElement( 'password', 'confirmPassword', array('label' => 'Confirm Password', 'attribs' => array('autocomplete' => 'off')) ); $this->getElement('confirmPassword')->addValidator('ConfirmPassword', true, array('password')); $this->addDisplayGroup( array('firstName', 'lastName', 'directPhone', 'email', 'password', 'confirmPassword'), 'personalInfo', array('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(array('legend' => ucfirst($type) . ' Address')); if ($type != Entity::ADDRESS_BILLING) { $form->addElement( 'checkbox', 'asBilling', array('label' => 'My shipping address is the same as my billing address', 'decoration' => 'simple') ); } $form->addElement('text', 'firstName', array('label' => 'First Name')); $form->addElement('text', 'lastName', array('label' => 'Last Name')); $form->addElement('text', 'address', array('label' => 'Address')); $form->addElement('text', 'city', array('label' => 'City', 'class' => 'city')); $form->addElement( 'select', 'state', array( 'label' => 'State', 'class' => 'state', 'multiOptions' => array('' => 'Select One') + $this->_getStates4Select() ) ); $form->addElement('zip', 'zip', array('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 = array('' => 'Select One') + $this->_getMemberships(true); $this->addElement( 'select', 'membershipTypeId', array('label' => 'Membership Type', 'required' => true, 'multioptions' => $multioptions) ); return $this; } /** * "Company" fields for "association" mode * @return $this */ protected function _initCompanyFields() { $form = new Qs_Form_SubForm(array('legend' => 'Company Information')); $form->addElement('text', 'name', array('label' => 'Company', 'required' => true)); $form->addElement('text', 'address', array('label' => 'Address 1', 'required' => true)); $form->addElement('text', 'address2', array('label' => 'Address 2')); $form->addElement('text', 'city', array('label' => 'City', 'required' => true)); $multioptions = array('' => 'Select One') + $this->_getStates4Select(); $form->addElement( 'select', 'state', array('label' => 'State', 'required' => true, 'multioptions' => $multioptions) ); $form->addElement('zip', 'zip', array('label' => 'Zip', 'required' => true)); $form->addElement('phone', 'phone', array('label' => 'Phone Number')); $form->addElement('phone', 'fax', array('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', array('label' => 'First Name', 'required' => true)); $this->addElement('text', 'lastName', array('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', array( 'label' => 'Photo', 'resize' => $resize, 'required' => true, 'defaultThumbnail' => 'images/member-no-photo.png', ) ); $this->addElement('htmlEditor', 'bio', array('label' => 'Bio')); $this->addElement( 'url', 'linkedInUrl', array( 'label' => 'LinkedIn URL', 'description' => 'Example: http://www.linkedin.com/company/adapta-interactive' ) ); } $this->_initHomeAddressFields(); $this->addElement('phone', 'directPhone', array('label' => 'Direct Phone Number', 'required' => true)); $this->addElement('phone', 'cellPhone', array('label' => 'Cell Phone Number')); $this->addElement( 'email', 'email', array('label' => 'Email Address', 'required' => true, 'attribs' => array('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 = array('cartId' => $this->_getCart()->getCartId()); $inCart = new NotInCart($options); $this->getElement('email')->addValidator($inCart, true); $this->addElement( 'password', 'password', array('label' => 'Password', 'attribs' => array('autocomplete' => 'off')) ); $this->getElement('password')->addValidator('Callback', true, array(array($this, 'validatePassword'))); $this->addElement( 'password', 'confirmPassword', array('label' => 'Confirm Password', 'attribs' => array('autocomplete' => 'off')) ); $this->getElement('confirmPassword')->addValidator('ConfirmPassword', true, array('password')); return $this; } /** * "Address" fields for "association" mode * @return $this */ protected function _initHomeAddressFields() { $form = new Qs_Form_SubForm(); $form->addElement('text', 'address', array('label' => 'Home Address 1')); $form->addElement('text', 'address2', array('label' => 'Home Address 2')); $form->addElement('text', 'city', array('label' => 'Home City', 'class' => 'city')); $form->addElement( 'select', 'state', array( 'label' => 'Home State', 'class' => 'state', 'multiOptions' => array('' => 'Select One') + $this->_getStates4Select() ) ); $form->addElement('zip', 'zip', array('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(array('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 = array(); } 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; } }