Beispiel #1
0
 /**
  * Create sharers subform
  *
  * @return void
  */
 public function init()
 {
     // Invoke the sharers manager
     $sharersManager = new Manager_Insurance_TenantsContentsPlus_Sharers();
     // Create array of possible sharer occupations
     $sharerOccupations = array('' => '--- please select ---');
     $sharerOccupationsObj = $sharersManager->getOccupations();
     foreach ($sharerOccupationsObj as $sharerOccupationObj) {
         $sharerOccupations[$sharerOccupationObj->getType()] = $sharerOccupationObj->getType();
     }
     // Add number of sharers element
     $multiOptions = array('' => '--- please select ---');
     for ($i = 0; $i <= $this->maxSharers; $i++) {
         $multiOptions["{$i}"] = "{$i}";
     }
     $this->addElement('select', 'policy_sharers', array('label' => 'How many sharers would you like to include in this policy?', 'required' => false, 'multiOptions' => $multiOptions, 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select a number of sharers', 'notEmptyInvalid' => 'Please select a number of sharers')))), 'attribs' => array('class' => 'form-control')));
     // Add sharer 1 upward's occupation - this is only required for validation if the above element value says is equal to or above $i
     if ($this->maxSharers > 0) {
         for ($i = 1; $i <= $this->maxSharers; $i++) {
             $this->addElement('select', "policy_sharer{$i}_occupation", array('label' => "Sharer {$i} occupation", 'required' => false, 'multiOptions' => $sharerOccupations, 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => "Please select an occupation for sharer {$i}", 'notEmptyInvalid' => "Please select an occupation for sharer {$i}")))), 'attribs' => array('class' => 'form-control')));
         }
     }
     // Set custom subform decorator
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'subforms/sharers.phtml'))));
     // Strip all tags to prevent XSS errors
     $this->setElementFilters(array('StripTags'));
     $this->setElementDecorators(array(array('ViewHelper', array('escape' => false)), array('Label', array('escape' => false))));
     $view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view');
     $view->headScript()->appendFile('/assets/tenants-insurance-quote/js/sharers.js', 'text/javascript');
 }