_dataObj) { $this->_dataObj = new App_ECommerce_GiftCard_Admin_Obj(); if (!empty($this->_primaryKey)) { $this->_dataObj->setPrimaryKey($this->_primaryKey); } } return $this->_dataObj; } protected function _initElements() { $this->addElement('hidden', 'send'); $this->addElement('text', 'cardCode', array('label' => 'Gift Card Code', 'required' => true)); $uniqueValidator = new Qs_Validate_Unique(new Qs_Db_Table('GiftCard'), 'cardCode', $this->_getData('id')); $this->getElement('cardCode')->addValidator($uniqueValidator); $newButton = $this->getView()->formButton('newCardCode', 'Generate a Code', array('class' => 'btn')); $this->getElement('cardCode')->getDecorator('ViewHelper')->setAdditionalHtmlAfterElement($newButton); $this->addElement('numeric', 'cardValue', array('label' => 'Card Value', 'required' => true)); $this->getElement('cardValue')->addValidator('Callback', false, array( 'callback' => array($this, 'validatePrice'), 'messages' => 'Value should be greater than 0' ) ); $currency = ''; $this->getElement('cardValue')->getDecorator('Numeric')->setAdditionalHtmlBeforeElement($currency); $this->addElement('date', 'expirationDate', array('label' => 'Exp. Date', 'required' => true)); $this->getElement('expirationDate')->addValidator('Callback', false, array( 'callback' => array($this, 'validateDate'), 'messages' => 'The expiration date must be greater than the current date' ) ); $this->addElement( 'autocomplete', 'userId', array( 'label' => 'Customer', 'dataUrl' => BASE_URL_LANGUAGE . '/' . CURRENT_PAGE . '?action=userAutocomplete', 'validators' => array(array('Int', false)), 'required' => true ) ); if ($this->_getData('userId')) { $userObj = new App\User\Admin\Obj(); $userObj->setPrimaryKey($this->_getData('userId')); $userData = $userObj->getData(); $title = $userData['firstName'] . ' ' . $userData['lastName'] . ', ' . $userData['email']; $this->getElement('userId')->setTitle($title); } return $this; } protected function _initButtons() { if (!$this->_hasButtons) { return $this; } $this->addElement( 'submit', 'btnSubmit', array( 'label' => 'Save', 'attribs' => array('class' => 'btn btn-primary'), ) ); $this->addElement( 'submit', 'btnSend', array( 'label' => 'Send', 'attribs' => array('class' => 'btn btn-info'), ) ); $this->addElement( 'submit', 'btnCancel', array( 'label' => 'Cancel', 'attribs' => array( 'class' => 'btn', 'onclick' => "window.location.href = '" . htmlspecialchars($this->getCancelUrl()) . "';", 'helper' => 'formInputButton', ), ) ); $this->addDisplayGroup(array('btnSubmit', 'btnSend', 'btnCancel'), 'submitGroup'); return $this; } public function render(Zend_View_Interface $view = null) { /** @var $doc Qs_Doc */ $doc = Zend_Registry::get('doc'); $doc->addScript('js/app/ECommerce/giftCard/form.js'); $doc->addInitFunction('App_GiftCard_Form.init', array($this->getId())); return parent::render($view); } public function validateDate($data) { return (bool) (strtotime($data) >= strtotime(date('Y-m-d'))); } public function validatePrice($data) { return (bool) ((float) $data > 0); } }