getDataObj()->hasPrimaryKey() || empty($this->_primaryKey)) { throw new Exception('Event id is not defined'); } $this->_defaults['dateSubmitted'] = date('Y-m-d'); $this->_defaults['timeSubmitted'] = date('H:i:s'); if (($userId = $this->getUserId())) { if (!isset($this->_defaults['attendee'])) { $this->_defaults['attendee'] = array(); } $this->_defaults['attendee'][] = array( 'mode' => 'choose', 'type' => AttendeeForm::TYPE_MEMBER, 'id' => $userId ); } else { $this->_defaults['attendee'][] = array( 'mode' => 'choose', ); } return parent::init(); } protected function _initElements() { $this->addElement( 'static', 'eventTitle', array( 'label' => 'Event', 'value' => $this->getDataObj()->getData('title') ) ); $this->addElement( 'date', 'dateSubmitted', array( 'label' => 'Date Submitted', 'required' => true ) ); $this->addElement( 'time', 'timeSubmitted', array( 'label' => 'Time Submitted', 'required' => true ) ); $this->addElement( 'select', 'paid', array( 'label' => 'Paid', 'multiOptions' => array( '' => 'Select One', 'y' => 'Yes', 'n' => 'No', ), 'onchange' => '$(this.form).find("dl:first").toggleClass("paid", "y" === $(this).val());', 'required' => true, ) ); $paid = $this->_getData('paid'); $this->addElement( 'select', 'paymentMethod', array( 'label' => 'Payment Method', 'multiOptions' => array( '' => 'Select One', OrderObj::PAYMENT_TYPE_CASH => OrderObj::$paymentMethodsTitles[OrderObj::PAYMENT_TYPE_CASH], OrderObj::PAYMENT_TYPE_CHECK => OrderObj::$paymentMethodsTitles[OrderObj::PAYMENT_TYPE_CHECK], ), 'required' => ('y' === $paid) ) ); $this->getElement('paymentMethod')->getDecorator('Label')->setOption('class', 'required'); return parent::_initElements(); } public function getValues($suppressArrayNotation = false) { $values = parent::getValues($suppressArrayNotation); if (empty($values['paid']) || 'y' !== $values['paid']) { unset($values['paymentMethod']); } return $values; } public function initRender() { parent::initRender(); if (($paid = $this->_getData('paid')) && 'y' === $paid) { $decorator = $this->getDecorator('HtmlTag'); $decorator->setOption('class', $decorator->getOption('class') . ' paid'); } return $this; } public function getAllowGroups() { if (null === $this->_allowGroups) { $this->_allowGroups = $this->getDataObj()->getGroupsAllowed(); } return $this->_allowGroups; } public function getAllowNonMembers() { if (null === $this->_allowNonMembers) { $this->_allowNonMembers = $this->getDataObj()->getNonMembersAllowed(); } return $this->_allowNonMembers; } public function setUserId($userId) { $this->_userId = $userId; return $this; } public function getUserId() { return $this->_userId; } }