_dataObj) { $this->_dataObj = new \App\TradeShow\Attendee\Admin\Obj(); } return $this->_dataObj; } public function init() { if (!$this->getTradeshowObj()->hasPrimaryKey()) { throw new Exception('TradeShow id is not defined'); } if (empty($this->_defaults['paymentDate'])) { $this->_defaults['paymentDate'] = date('Y-m-d H:i:s'); } return parent::init(); } protected function _initElements() { $this->addElement( 'autocomplete', 'attendeeId', [ 'label' => 'Attendee Name', 'dataUrl' => $this->getUserAutocompleteUrl(), 'required' => false ] ); $this->getElement('attendeeId')->getDecorator('Label')->setOption('class', 'required'); $this->_initPaymentGroupElement(); $this->addFormRule([$this, 'validateData']); return $this; } public function validateData($data) { $errors = []; $emptyValidator = new Qs_Validate_NotEmpty(); if (true !== $emptyValidator->isValid($data['_attendeeId'])) { $errors['attendeeId'] = $emptyValidator->getMessages(); } if (!$data['attendeeId']) { $nameValidatorOptions = ['elementId' => 'attendeeId']; $nameValidator = new IndividualName($nameValidatorOptions); if (true !== $nameValidator->isValid(null, $data)) { $errors['attendeeId'] = $nameValidator->getMessages(); } } $validatorOptions = [ 'tradeShowId' => $this->getTradeShowObj()->getData('id'), 'registrationId' => ($registrationId = $this->_getData('id')) ? $registrationId : null, 'elementId' => 'attendeeId' ]; $validatorObj = new AttendeeNotRegisteredValidator($validatorOptions); if (true !== $validatorObj->isValid(null, $data)) { $errors['attendeeId'] = $validatorObj->getMessages(); } return ($errors) ? $errors : true; } protected function _initPaymentGroupElement() { $this->addElement( 'select', 'paymentType', [ 'label' => 'Payment Type', 'multiOptions' => ['' => 'Choose Payment Type'] + (array) $this->_getDataObj()->getPaymentMethods4Select(), 'required' => true, ] ); $this->addElement('date', 'paymentDate', ['label' => 'Payment Date', 'required' => true]); $this->addElement( 'numeric', 'amount', [ 'label' => 'Amount', 'prepend' => '$', 'negative' => false, 'required' => true ] ); $this->addDisplayGroup(['paymentType', 'paymentDate', 'amount'], 'paymentGroup', ['legend' => 'Payment Information']); return $this; } protected function _addResources() { parent::_addResources(); /** @var \Qs_Doc $doc */ $doc = Zend_Registry::get('doc'); if ($this->getElement('paymentType')) { $params = [ 'nodeIds' => [ 'paymentType' => $this->getElement('paymentType')->getId(), 'amount' => $this->getElement('amount')->getId() ] ]; $doc->addScript('js/app/tradeShow/attendee/admin/form.js'); $doc->addInitObject('app.tradeShow.attendee.admin.Form', [$params]); } $doc->addScript('js/jquery.defaultHint.js'); $hintOptions = [ 'elements' => [['selector' => '#_attendeeId', 'hint' => 'Autocomplete field']], 'useWrapper' => true ]; $doc->addInitFunction('$("#' . $this->getId() . '").defaultHint', [$hintOptions]); return $this; } }