['asBilling' => 'y'], 'home' => ['countryId' => 'US'], 'pmEnabled' => 'y', 'pmNotificationEnabled' => '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->_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', 'workPhone', ['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', 'workPhone', 'email', 'password', 'confirmPassword'], 'personalInfo', ['legend' => 'Personal Information'] ); return $this; } protected function _initCheckoutFields($isRequired = true) { $this->_initAddressFields(Entity::ADDRESS_BILLING, $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', 'address2', ['label' => 'Address 2']); $form->addElement('text', 'address3', ['label' => 'Address 3']); $form->addElement('text', 'city', ['label' => 'City', 'class' => 'city']); $form->addElement( 'countryState', 'state', [ 'label' => 'State', 'class' => 'state', 'countryElement' => 'countryId', 'countryId' => $this->_getData($type . '[countryId]'), 'multiOptions' => ['' => 'Select One'] + (new StateModel())->getStates4Select(), ] ); $form->addElement( 'select', 'countryId', [ 'label' => 'Country', 'class' => 'country', 'multiOptions' => ['' => 'Select One'] + (new Qs_Db_Table('Country'))->get4Select(['id', 'name']), ] ); $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; } /** * "Personal" fields for "association" mode * @param bool $full * @return $this */ protected function _initIndividualFields($full = false) { $this->_showDisplayGroupLegend('personalInfo', 'Personal Information'); $this->addElement('text', 'prefix', ['label' => 'Prefix', 'maxlength' => 16]); $this->addElement('text', 'firstName', ['label' => 'First Name', 'required' => true]); $this->addElement('text', 'middleName', ['label' => 'Middle Name/Initial']); $this->addElement('text', 'lastName', ['label' => 'Last Name', 'required' => true]); $this->addElement('text', 'suffix', ['label' => 'Suffix', 'maxlength' => 16]); $this->addElement('text', 'credentials', ['label' => 'Credentials', 'required' => true]); $this->addElement('text', 'companyName', ['label' => 'Institution/Employer', 'required' => true]); $this->addElement('text', 'position', ['label' => 'Position/Title']); 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, '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('internationalTel', 'workPhone', ['label' => 'Work Phone Number', 'required' => true]); $this->addElement('internationalTel', 'cellPhone', ['label' => 'Cell Phone Number']); $this->addElement('internationalTel', 'homePhone', ['label' => 'Home Phone Number']); $this->addElement('internationalTel', 'fax', ['label' => 'Fax 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']); $this->addElement('checkbox', 'pmEnabled', [ 'label' => 'I would like to receive private messages.', 'decoration' => 'simple', ]); $this->addElement('checkbox', 'pmNotificationEnabled', [ 'label' => 'Send me email notifications when I receive a private message.', 'decoration' => 'simple', ]); $this->addScript('js/app/user/options.js')->addInitObject('app.user.Options', [[ 'id' => $this->getId(), 'nodes' => [ 'pmEnabled' => '#pmEnabled', 'pmNotificationEnabled' => '#pmNotificationEnabled', ], ]]); return $this; } /** * "Address" fields for "association" mode * @return $this */ protected function _initHomeAddressFields() { $form = new Qs_Form_SubForm(); $form->addElement('text', 'address', ['label' => 'Address 1', 'required' => true]); $form->addElement('text', 'address2', ['label' => 'Address 2']); $form->addElement('text', 'address3', ['label' => 'Address 3']); $form->addElement('text', 'city', ['label' => 'City', 'class' => 'city', 'required' => true]); $form->addElement( 'countryState', 'state', [ 'label' => 'State/Province', 'class' => 'state', 'countryElement' => 'countryId', 'required' => true, 'countryId' => $this->_getData(Entity::ADDRESS_HOME . '[countryId]'), 'multiOptions' => ['' => 'Select One'] + (new StateModel())->getStates4Select(), ] ); $form->addElement( 'select', 'countryId', [ 'label' => 'Country', 'class' => 'country', 'required' => true, 'multiOptions' => ['' => 'Select One'] + (new Qs_Db_Table('Country'))->get4Select(['id', 'name']), ] ); $form->addElement('zip', 'zip', ['label' => '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') && $this->getElement('membershipTypeId')) { $options['memberships'] = $this->_getMemberships(); foreach ($options['memberships'] as &$membership) { $membership['price'] = floatval($membership['price']); } } $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; } public function setMemberships(array $memberships) { $this->_memberships = $memberships; return $this; } protected function _getMemberships($forSelect = false) { if (null === $this->_memberships) { $this->_memberships = []; } if ($forSelect && $this->_memberships) { $options = []; foreach ($this->_memberships as $membership) { $options[$membership['id']] = $membership['title'] . ' (' . ((float) $membership['price'] > 0 ? Number::toMoney($membership['price'], 2, false, '$') . ' USD' : 'Free') . ')'; } return $options; } return $this->_memberships; } }