getEventObj()->hasPrimaryKey()) { throw new Exception('Event id is not defined'); } if (empty($this->_defaults['paymentDate'])) { $this->_defaults['paymentDate'] = date('Y-m-d H:i:s'); } if (empty($this->_defaults['attendee'])) { if ($this->getAttendeeObj()->hasUserId()) { $this->_defaults['attendee'][] = [ 'mode' => 'choose', 'type' => AttendeeForm::TYPE_MEMBER, 'id' => $this->getAttendeeObj()->getUserId() ]; } else { $this->_defaults['attendee'][] = [ 'mode' => 'choose', ]; } } return parent::init(); } protected function _initElements() { $this->_initTitleElement(); parent::_initElements(); $this->_initPaymentGroupElement(); return $this; } protected function _initTitleElement() { $this->addElement( 'static', 'eventTitle', [ 'label' => 'Event', 'value' => $this->getEventObj()->getData('title') ] ); return $this; } protected function _initPaymentGroupElement() { $enabled = $this->_getPaymentEnabled(); $this->addElement( 'static', 'paymentNote', [ 'value' => 'Note: Entered payment information will be applied to each attendee listed above. ' . 'If attendees have different payment information, please add and save them one at a time instead.' ] ); $this->addElement( 'select', 'paymentType', [ 'label' => 'Payment Type', 'multiOptions' => ['' => 'Choose Payment Type'] + (array) $this->getAttendeeObj()->getPaymentMethods4Select(), 'required' => $enabled, ] ); $this->addElement('date', 'paymentDate', ['label' => 'Payment Date', 'required' => $enabled]); $this->addElement( 'numeric', 'amount', [ 'label' => 'Amount', 'prepend' => '$', 'negative' => false, 'required' => $enabled ] ); $this->addDisplayGroup( ['paymentNote', 'paymentType', 'paymentDate', 'amount'], 'paymentGroup', [ 'legend' => $this->_renderPaymentLegend(), 'escape' => false ] ); foreach (['paymentType', 'paymentDate', 'amount'] as $name) { $this->getElement($name)->getDecorator('label')->setOption('class', 'required'); } return $this; } public function getAllowNonMembers() { return $this->_allowNonMembers; } protected function _addResources() { parent::_addResources(); /** @var \Qs_Doc $doc */ $doc = Zend_Registry::get('doc'); if ($this->getElement('paymentType')) { $params = [ 'nodeIds' => [ 'paymentEnabled' => 'paymentEnabled' ], ]; $params['nodeIds']['paymentType'] = $this->getElement('paymentType')->getId(); $params['nodeIds']['amount'] = $this->getElement('amount')->getId(); $doc->addScript('js/app/event/attendee/admin/form.js'); $doc->addInitObject('app.event.attendee.admin.Form', [$params]); } return $this; } protected function _getPaymentEnabled() { $enabled = 'y' === $this->_getData( 'paymentEnabled', $this->_getData('paymentType') ? 'y' : 'n' ); return $enabled; } protected function _renderPaymentLegend() { $enabled = $this->_getPaymentEnabled(); $checkbox = Qs_View::getInstance()->formCheckbox( 'paymentEnabled', $enabled ? 'y' : 'n', [], ['checkedValue' => 'y', 'uncheckedValue' => 'n'] ); $html = '