_dataObj) { $this->_dataObj = new App_User_Admin_Obj(); } return $this->_dataObj; } /** * @return App_ECommerce_Cart_Obj */ protected function _getCart() { if (null === $this->_cart) { $this->_cart = new App_ECommerce_Cart_Obj(); $this->_cart->setPrimaryKey($this->_cart->getCartId()); } return $this->_cart; } protected function _initElements() { $this->_initAssociationFields(); $this->_initPersonalInfoFields(); $this->_initEmployerInfoFields(); $this->_initLeadershipFields(); return $this; } protected function _initAssociationFields($isNewForm = false) { $memberActive = ($isNewForm && !$this->isSubmitted()) ? $isNewForm : ('y' == $this->_getData('active')); $this->addElement( 'text', 'memberId', array( 'label' => 'Member ID', 'required' => $memberActive ) ); $uniqueValidator = new Qs_Validate_Unique(new Qs_Db_Table('User'), 'memberId', $this->_getData('id')); $uniqueValidator->setMessage('Member ID must be unique', Qs_Validate_Unique::NOT_UNIQUE); $this->getElement('memberId')->addValidator($uniqueValidator); $this->addElement('date', 'joinDate', array('label' => 'Joined', 'value' => date('Y-m-d'))); $this->addElement( 'checkbox', 'active', array( 'label' => 'Active', 'decoration' => 'simple', 'onchange' => 'if ($(this).attr("checked") == "checked") { $("#memberId").removeAttr("disabled"); $("#memberId").removeClass("disabled"); $("#memberId-label label").addClass("required"); } else { $("#memberId").attr("disabled", "disabled"); $("#memberId-label label").removeClass("required"); }' ) ); if ($memberActive) { $this->setDefault('active', 'y'); } else { $this->getElement('memberId')->setOptions(array('disabled' => 'disabled')); } $this->addDisplayGroup( array('memberId', 'joinDate', 'active'), 'AssociationInfo', array('legend' => 'Association Information') ); } protected function _initPersonalInfoFields() { $this->addElement('text', 'firstName', array('label' => 'First Name', 'required' => true)); $this->addElement('text', 'middleInitial', array('label' => 'Middle Initial')); $this->addElement('text', 'lastName', array('label' => 'Last Name', 'required' => true)); $this->addElement('text', 'suffix', array('label' => 'Suffix')); $uniqueValidator = new Qs_Validate_Unique(new Qs_Db_Table('User'), 'email', $this->_getData('id')); $uniqueValidator->setMessage('Email must be unique', Qs_Validate_Unique::NOT_UNIQUE); $this->addElement( 'text', 'email', array('label' => 'Email', 'required' => true, 'attribs' => array('autocomplete' => 'off')) ); $this->getElement('email')->addValidator('EmailAddress'); $this->getElement('email')->addValidator($uniqueValidator); $this->addElement('phone', 'phone', array('label' => 'Work Phone')); $this->_initMyInfo(); $this->addDisplayGroup( array( 'firstName', 'middleInitial', 'lastName', 'suffix', 'password', 'confirmPassword', 'email', 'phone', 'linkedIn', 'photo' ), 'personalInfo', array('legend' => 'Personal Information') ); return $this; } protected function _initMyInfo() { $config = Qs_Application::getConfig('user'); $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->addElement( 'text', 'linkedIn', array( 'label' => 'LinkedIn Profile URL', 'class' => 'text', 'filters' => array('StringTrim'), 'validators' => array('Url'), 'description' => 'Example: http://www.linkedin.com/in/johnsmith' ) ); $this->addElement( 'extendedImage', 'photo', array( 'label' => 'Photo', 'resize' => $config->image->width . 'x' . $config->image->height . $config->image->resizeMethodAlias ) ); return $this; } protected function _initLeadershipFields() { $this->addElement( 'select', 'groupId', array( 'label' => 'Group', 'multiOptions' => array('' => 'Select One') + $this->_getDataObj()->getUserGroup4Select(), 'onchange' => 'if ($(this).val() == "") {$("#leadershipTitle-label label").removeClass("required");} else {$("#leadershipTitle-label label").addClass("required");}' ) ); $this->addElement( 'text', 'leadershipTitle', array('label' => 'Position', 'required' => $this->_getData('groupId')) ); $this->addDisplayGroup( array('groupId', 'leadershipTitle'), 'Leadership', array('legend' => 'Leadership Group') ); } protected function _initEmployerInfoFields() { $this->addElement('text', 'title', array('label' => 'Position')); $this->addElement('text', 'company', array('label' => 'Company')); $this->addElement('text', 'address', array('label' => 'Address')); $this->addElement('text', 'address2', array('label' => 'Address 2')); $this->addElement('text', 'city', array('label' => 'City', 'class' => 'city')); $this->addElement( 'select', 'state', array( 'label' => 'State', 'class' => 'state', 'multiOptions' => array('' => 'Select One') + $this->_getDataObj()->getDState4Select() ) ); $zipValidator = new Zend_Validate_PostCode(new \Zend_Locale('en_US')); $zipValidator->setMessage('Zip Code is in wrong format', Zend_Validate_PostCode::NO_MATCH); $this->addElement( 'text', 'zip', array( 'label' => 'Zip', 'class' => 'zip', 'validators' => array($zipValidator), 'description' => 'Allowed characters: 0-9, \'-\'', ) ); $this->addDisplayGroup( array('title', 'company', 'address', 'address2', 'city', 'state', 'zip'), 'EmployerInfo', array('legend' => 'Employer Information') ); return $this; } 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'); $options = array(); $options['formId'] = $this->getId(); $options['addressTypes'] = $this->_getDataObj()->getAddressTypes(); if ($this->getSubForm(App_User_Abstract_Obj::ADDRESS_BILLING)) { $options['addressFields'] = array_keys($this->getSubForm(App_User_Abstract_Obj::ADDRESS_BILLING) ->getElements()); } $options['inheritedAddress'] = array_shift($options['addressTypes']); $doc->addInitObject('App_User_Form', array($options), '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; } }