addElement( 'hidden', 'step', array('value' => $this->_step) ); if ($this->_step > 1) { $this->addElement( 'hidden', 'applicantIndex', array('value' => $this->_applicantIndex) ); } return $this; } protected function _initButtons() { if (!$this->_hasButtons) { return $this; } /** @var Qs_Doc $doc */ $doc = Zend_Registry::get('doc'); $doc->getSmarty()->assign('step', $this->_step); $doc->getSmarty()->assign('stepTitle', $this->translate('Step')); $this->addElement( 'html', 'progressBar', array( 'value' => $doc->getSmarty()->fetch('Wizard/progress-bar.tpl') ) ); $wizardLastStep = $this->getConfig('wizardLastStep'); $applicants = ($this->_step >= 2) ? (array) $_SESSION['App_Wizard_View']['wizardData']['applicants'] : []; $isDebugFinishButton = $this->_isDebug() && $this->_step == $wizardLastStep + 1 && $this->_applicantIndex == 0; $continueLabel = ($applicants && ($this->_step == $wizardLastStep && $this->_applicantIndex == max(array_keys($applicants))) || $isDebugFinishButton) ? (($isDebugFinishButton) ? 'Show Results' : 'Finish') : 'Continue'; $this->addElement( 'submit', 'btnSubmit', array( 'label' => $continueLabel, 'attribs' => array('class' => 'btn btn-primary'), ) ); $this->addElement( 'submit', 'btnCancel', array( 'label' => 'Back', 'attribs' => array('class' => 'btn') ) ); if ($this->_step == 1) { $this->getElement('btnCancel')->setAttrib('style', 'display: none;'); } $this->addDisplayGroup(array('progressBar', 'btnSubmit', 'btnCancel'), 'submitGroup'); return $this; } /** * Form Step Setter * @param $value * @return $this */ public function setStep($value) { $this->_step = $value; return $this; } public function setApplicantsCount($value) { $this->_applicantsCount = $value; return $this; } /** * Applicant Name Setter * @param $value * @return $this */ public function setApplicantName($value) { $this->_applicantName = $value; return $this; } /** * Applicant Index Setter * @param $value * @return $this */ public function setApplicantIndex($value) { $this->_applicantIndex = $value; return $this; } protected function _getApplicants() { return (array)$_SESSION['App_Wizard_View']['wizardData']['applicants']; } protected function _getAdditionalPersons() { $sessionData = $_SESSION['App_Wizard_View']['wizardData']; return (isset($sessionData['additionalPersons'])) ? (array)$sessionData['additionalPersons'] : array(); } public function render(\Zend_View_Interface $view = null) { /** @var $doc \App_Doc_Site */ $doc = \Zend_Registry::get('doc'); $doc->addScript('js/jquery.bootstrap-touchspin.js'); $doc->addStylesheet('css/thirdpart/jquery.bootstrap-touchspin.css'); $doc->addScript('js/app/wizard-form.js'); $doc->addScript('js/app/wizard-form-tip.js', array(), 'wizard-form'); $doc->addInitFunction('Form_Wizard_Tip.init', array()); $doc->addScript('js/app/wizard-language.js'); $doc->addInitFunction('Form_Wizard_Language.init', array()); $options = array( 'step' => $this->_step, 'defaultData' => ($this->_step >= 2) ? $this->getConfig('defaults')->toArray()[$this->_step] : [], ); if ($this->_step == 2 || $this->_step == 4) { $options['minIncomeAge'] = App_Settings_Obj::get('minIncomeAge'); $options['minAge'] = App_Settings_Obj::get('minAge'); } if ($this->_step == 3) { $options['pregnancyStatus'] = $this->_getStorageData(2, $this->_applicantIndex)['pregnancyStatus']; } if ($this->_step == 3 || $this->_step == 4) { $options['applicantAge'] = App_Wizard_View::getApplicantAge( $this->_getStorageData(2, $this->_applicantIndex)['birth']); } if ($this->_step == 4) { $options['maxAgeMA'] = App_Settings_Obj::get('maxAgeMA'); } $doc->addInitObject('app.Wizard', array($options)); return parent::render($view); } /** * Is Applicant Age >= config maxAgeMA * @param $applicantIndex * @return bool */ protected function _isApplicantAge($applicantIndex) { $birth = $this->_getStorageData(2, $applicantIndex)['birth']; return App_Wizard_View::checkApplicantAge($birth, App_Settings_Obj::get('maxAgeMA')); } protected function _getStorageData($step, $applicantIndex = null) { $configDefaults = $this->getConfig('defaults')->toArray()[$step]; $sessionData = $_SESSION['App_Wizard_View']['wizardData']; $storageData = (isset($sessionData[$step]) && $sessionData[$step]) ? (array)$sessionData[$step] : []; if ($step == 1) { $defaults = array_merge($configDefaults, $storageData); } else { $defaults = array_merge( $configDefaults, (isset($storageData[$applicantIndex])) ? (array)$storageData[$applicantIndex] : [] ); } return $defaults; } protected function _isDebug() { return (App_Wizard_View::DEBUG_ON == $_SESSION['App_Wizard_View']['wizardDebug']); } public function addElement($element, $name = null, $options = null) { $form = $this; switch ($element) { case 'radio': $fieldsetOptions = [ 'escape' => false, 'legendWrapperTag' => false, 'legend' => Qs_Array::get($options, 'label'), 'legendAttribs' => [ 'id' => function () use ($form, $name) { return $form->getElement($name)->getId() . '-label'; } ], 'class' => 'fieldset-radio', 'stripAttribs' => ['label_class'] ]; if (Qs_Array::get($options, 'required')) { $fieldsetOptions['legendAttribs']['class'] = 'required'; } $options = null === $options ? [] : $options; $options['decorators'] = [ 'ViewHelper', 'Errors', 'Description', ['Fieldset', $fieldsetOptions], 'DtDdWrapper', ]; break; default: break; } return parent::addElement($element, $name, $options); } }