getConfig('mode'); if (Module::MODE_SIMPLE == $mode) { $this->_initStatusFields(); $this->_initSimpleElements(); } else if (Module::MODE_ASSOCIATION == $mode) { $this->_initAssociationElements(); } else { throw new Qs_Exception('Unknown module mode.'); } return $this; } protected function _initMembershipTypeFields() { parent::_initMembershipTypeFields(); $this->_initStatusFields(); return $this; } protected function _initCompanyFields() { $displayGroupElements = []; $displayGroupElements[] = 'companyId'; $this->addElement('autocomplete', 'companyId', ['label' => 'Company']); $this->companyId->setDataUrl($this->getAction() . '?action=autocompleteCompany'); if (null !== ($companyId = $this->_getData('companyId'))) { if (null !== ($companyTitle = $this->_getDataObj()->getCompanyTitleById($companyId, 'name'))) { $this->companyId->setTitle($companyTitle); } } $description = $this->_renderRegistrationCompanyDescription(); if ($description) { $displayGroupElements[] = 'registrationsCompany'; $this->addElement( 'static', 'registrationsCompany', ['label' => 'Company Entered by User', 'value' => $description, 'escape' => false] ); } $this->addDisplayGroup($displayGroupElements, 'company', ['legend' => 'Company Information']); return $this; } protected function _initIndividualFields($full = true) { parent::_initIndividualFields($full); $this->photo->setRequired(false); $this->_initAdditionalAssociationFields(); return $this; } protected function _initAdditionalAssociationFields() { $this->addElement('date', 'joinDate', ['label' => 'Join Date']); $this->addElement('textarea', 'notes', ['label' => 'Notes']); $this->addElement( 'multiCheckbox', 'lists', [ 'label' => 'Lists', 'columns' => 3, 'multioptions' => $this->_getLists(), ] ); $this->_addLeadershipFields(); $this->_addCommitteesField(); return $this; } protected function _addLeadershipFields() { $this->addElement( 'select', 'leadershipGroupId', [ 'label' => 'Leadership Group', 'multioptions' => ['' => 'Select One'] + $this->_getLeadershipGroups(), ] ); $this->addElement('text', 'leadershipPosition', ['label' => 'Leadership Position']); $this->addDisplayGroup( ['leadershipGroupId', 'leadershipPosition'], 'leadershipGroup', ['legend' => 'Leadership'] ); return $this; } protected function _addCommitteesField() { $options = ['label' => 'Committees', 'required' => false]; $committeeSubForm = new CommitteeSubForm($options); if (($committees = $this->_getData('committees'))) { foreach (array_keys($committees) as $index) { $committeeSubForm->addSubForm(new CommitteeItemSubForm(), (string) $index); } } else { $committeeSubForm->addSubForm(new CommitteeItemSubForm(), '0'); // add empty row } $this->addSubForm($committeeSubForm, 'committees'); $this->addFormRule([$this, 'validateCommitteeItems']); return $this; } public function validateCommitteeItems($data) { $errors = []; $subForm = null; foreach ($this->getSubForms() as $_subForm) { if ($_subForm instanceof CommitteeSubForm) { $subForm = $_subForm; } } if ($subForm) { $subFromName = $subForm->getName(); if ($committees = Qs_Array::get($data, $subFromName, [])) { $tmpCommittees = []; foreach ($committees as $key => $row) { if ('' != $row['committeeId'] && '' != $row['positionId']) { $tmpCommittees[$key] = $row; } } $committees = $tmpCommittees; foreach ($committees as $key => $row) { unset($committees[$key]); foreach ($committees as $key2 => $row2) { if ($row['committeeId'] == $row2['committeeId']) { $message = 'Duplicate row'; $errors[$subFromName][$key]['committeeId'] = $message; $errors[$subFromName][$key2]['committeeId'] = $message; unset($committees[$key2]); break; } } } } } return (empty($errors)) ? true : $errors; } protected function _renderRegistrationCompanyDescription() { $text = ''; if (!$this->_getData('companyId') && $pk = $this->getPrimaryKey()) { $table = new Qs_Db_Table('UserRegistrationCompany'); $company = $table->search($pk); if ($company) { $config = $this->getConfigArray('companyDescription'); foreach ($config['fields'] as $field => $title) { if ('' != $company[$field]) { $text .= Qs_String::fill( $config['rowTpl'], ['title' => $title, 'value' => htmlspecialchars($company[$field])], '%%' ); } } $newCompanyUrl = CompanyAdminView::getPage('url'); if ($newCompanyUrl) { $newCompanyUrl .= '?' . http_build_query(['action' => 'new', 'userId' => $company['userId']]); $text .= Qs_String::fill($config['linkTpl'], ['url' => htmlspecialchars($newCompanyUrl)], '%%'); } } } return $text; } protected function _initStatusFields() { $this->addElement( 'select', 'status', [ 'label' => 'Account Status', 'required' => true, 'multioptions' => ['' => 'Select One'] + $this->_getStatuses(), ] ); return $this; } protected function _get4Select($tableAlias) { $table = new Qs_Db_Table($tableAlias); return $table->get4Select(); } protected function _getStatuses() { return $this->_get4Select('UserStatus'); } protected function _getLists() { return $this->_get4Select('List'); } protected function _getLeadershipGroups() { return $this->_get4Select('LeadershipGroup'); } public function render(Zend_View_Interface $view = null) { $html = Qs_Form::render($view); /** @var $doc \App_Doc_Admin */ $doc = Zend_Registry::get('doc'); $options = $this->_getScriptOptions(); if (Module::MODE_ASSOCIATION == $this->getConfig('mode')) { $options['hintOptions'] = [ 'elements' => [ ['selector' => '#_companyId', 'hint' => 'Autocomplete field'], ], 'useWrapper' => true, ]; } $doc->addScript('js/jquery.defaultHint.js', [], 'defaultHint'); $doc->addScript('js/app/user/admin/form.js'); $doc->addInitObject('app.user.admin.form', [$options]); return $html; } }