/**
  * Adds elements from the model to the bridge that creates the form.
  *
  * Overrule this function to add different elements to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_FormBridgeInterface $bridge
  * @param \MUtil_Model_ModelAbstract $model
  */
 protected function addFormElements(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model)
 {
     if (!$this->createData) {
         $bridge->addHidden('gtr_id_track');
     }
     $bridge->addText('gtr_track_name');
     // gtr_track_class
     if ($this->trackEngine) {
         $options = $model->get('gtr_track_class', 'multiOptions');
         $alternatives = $this->trackEngine->getConversionTargets($options);
         if (count($alternatives) > 1) {
             $options = $alternatives;
             $bridge->addHidden($this->_oldClassName);
             if (!isset($this->formData[$this->_oldClassName])) {
                 $this->formData[$this->_oldClassName] = $this->formData['gtr_track_class'];
             }
             $classEdit = true;
         } else {
             $classEdit = false;
         }
     } else {
         $tracker = $this->loader->getTracker();
         $options = $tracker->getTrackEngineList(true, true);
         $classEdit = true;
     }
     $model->set('gtr_track_class', 'multiOptions', $options, 'escape', false);
     if ($classEdit) {
         $bridge->addRadio('gtr_track_class');
     } else {
         $bridge->addExhibitor('gtr_track_class');
     }
     $bridge->addDate('gtr_date_start');
     $bridge->addDate('gtr_date_until');
     if (!$this->createData) {
         $bridge->addCheckbox('gtr_active');
     }
     if ($model->has('gtr_code')) {
         $bridge->addText('gtr_code');
     }
     if ($model->has('gtr_calculation_event', 'label')) {
         $bridge->add('gtr_calculation_event');
     }
     if ($model->has('gtr_completed_event', 'label')) {
         $bridge->add('gtr_completed_event');
     }
     if ($model->has('gtr_beforefieldupdate_event', 'label')) {
         $bridge->add('gtr_beforefieldupdate_event');
     }
     if ($model->has('gtr_fieldupdate_event', 'label')) {
         $bridge->add('gtr_fieldupdate_event');
     }
     $bridge->add('gtr_organizations');
     if (\MUtil_Bootstrap::enabled()) {
         $element = new \MUtil_Bootstrap_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=gtr_organizations]'));
     } else {
         $element = new \Gems_JQuery_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=gtr_organizations]'));
     }
     $element->setLabel($this->_('Toggle'));
     $bridge->addElement($element);
 }
 /**
  * Adds elements from the model to the bridge that creates the form.
  *
  * Overrule this function to add different elements to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_FormBridgeInterface $bridge
  * @param \MUtil_Model_ModelAbstract $model
  */
 protected function addFormElements(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model)
 {
     $bridge->addHidden('grl_id_role');
     $bridge->addText('grl_name');
     $bridge->addText('grl_description');
     $roles = $this->acl->getRoles();
     if ($roles) {
         $possibleParents = array_combine($roles, $roles);
     } else {
         $possibleParents = array();
     }
     if (isset($this->formData['grl_parents']) && $this->formData['grl_parents']) {
         $this->formData['grl_parents'] = array_combine($this->formData['grl_parents'], $this->formData['grl_parents']);
     } else {
         $this->formData['grl_parents'] = array();
     }
     // Don't allow master, nologin or itself as parents
     unset($possibleParents['master']);
     unset($possibleParents['nologin']);
     $disabled = array();
     if (isset($this->formData['grl_name'])) {
         foreach ($possibleParents as $parent) {
             if ($this->acl->hasRole($this->formData['grl_name']) && $this->acl->inheritsRole($parent, $this->formData['grl_name'])) {
                 $disabled[] = $parent;
                 $possibleParents[$parent] .= ' ' . \MUtil_Html::create('small', $this->_('child of current role'), $this->view);
                 unset($this->formData['grl_parents'][$parent]);
             } else {
                 foreach ($this->formData['grl_parents'] as $p2) {
                     if ($this->acl->hasRole($p2) && $this->acl->inheritsRole($p2, $parent)) {
                         $disabled[] = $parent;
                         $possibleParents[$parent] .= ' ' . \MUtil_Html::create('small', \MUtil_Html::raw(sprintf($this->_('inherited from %s'), \MUtil_Html::create('em', $p2, $this->view))), $this->view);
                         $this->formData['grl_parents'][$parent] = $parent;
                     }
                 }
             }
         }
         $disabled[] = $this->formData['grl_name'];
         if (isset($possibleParents[$this->formData['grl_name']])) {
             $possibleParents[$this->formData['grl_name']] .= ' ' . \MUtil_Html::create('small', $this->_('this role'), $this->view);
         }
     }
     // Add this for validator to allow empty list
     $possibleParents[''] = '';
     $bridge->addMultiCheckbox('grl_parents', 'multiOptions', $possibleParents, 'disable', $disabled, 'escape', false, 'required', false, 'onchange', 'this.form.submit();');
     $allPrivileges = $this->usedPrivileges;
     $rolePrivileges = $this->acl->getRolePrivileges();
     if (isset($this->formData['grl_parents']) && $this->formData['grl_parents']) {
         $inherited = $this->getInheritedPrivileges($this->formData['grl_parents']);
         $privileges = array_diff_key($allPrivileges, $inherited);
         $inheritedPrivileges = array_intersect_key($allPrivileges, $inherited);
     } else {
         $privileges = $allPrivileges;
         $inheritedPrivileges = false;
     }
     $checkbox = $bridge->addMultiCheckbox('grl_privileges', 'multiOptions', $privileges, 'required', false);
     $checkbox->setAttrib('escape', false);
     //Don't use escaping, so the line breaks work
     if ($inheritedPrivileges) {
         $checkbox = $bridge->addMultiCheckbox('inherited', 'label', $this->_('Inherited'), 'multiOptions', $inheritedPrivileges, 'required', false, 'disabled', 'disabled');
         $checkbox->setAttrib('escape', false);
         //Don't use escaping, so the line breaks work
         $checkbox->setValue(array_keys($inheritedPrivileges));
         //To check the boxes
     }
 }
 /**
  * Adds elements from the model to the bridge that creates the form.
  *
  * Overrule this function to add different elements to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_FormBridgeInterface $bridge
  * @param \MUtil_Model_ModelAbstract $model
  * @param array $data The data that will later be loaded into the form
  * @param optional boolean $new Form should be for a new element
  * @return void|array When an array of new values is return, these are used to update the $data array in the calling function
  */
 protected function addFormElements(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model, array $data, $new = false)
 {
     $returnValues = array();
     if (APPLICATION_ENV !== 'production') {
         $bsn = new \MUtil_Validate_Dutch_Burgerservicenummer();
         $num = mt_rand(100000000, 999999999);
         while (!$bsn->isValid($num)) {
             $num++;
         }
         $model->set('grs_ssn', 'description', sprintf($this->_('Random Example BSN: %s'), $num));
     } else {
         $model->set('grs_ssn', 'description', $this->_('Enter a 9-digit SSN number.'));
     }
     if ($model->hashSsn === \Gems_Model_RespondentModel::SSN_HASH) {
         if (strlen($data['grs_ssn']) > 9) {
             // When longer the grs_ssn contains a hash, not a bsn number
             $returnValues['grs_ssn'] = '';
         }
     }
     $ucfirst = new \Zend_Filter_Callback('ucfirst');
     // \MUtil_Echo::track($data);
     $bridge->addTab('caption1')->h4($this->_('Identification'));
     //Add the hidden fields after the tab, so validation will work. They need to be in the
     //same tab where they are needed
     $bridge->addHidden('grs_id_user');
     $bridge->addHidden('gr2o_id_organization');
     $bridge->addHidden($model->getKeyCopyName('gr2o_patient_nr'));
     $bridge->addHidden($model->getKeyCopyName('gr2o_id_organization'));
     if (isset($data['gul_id_user'])) {
         $bridge->addHidden('gul_id_user');
     }
     $bridge->addText('grs_ssn', 'label', $this->_('SSN'), 'size', 10, 'maxlength', 12)->addValidator(new \MUtil_Validate_Dutch_Burgerservicenummer())->addValidator($model->createUniqueValidator('grs_ssn'))->addFilter('Digits');
     $bridge->addText('gr2o_patient_nr', 'label', $this->_('Patient number'), 'size', 15, 'minlength', 4)->addValidator($model->createUniqueValidator(array('gr2o_patient_nr', 'gr2o_id_organization'), array('gr2o_id_user' => 'grs_id_user', 'gr2o_id_organization')));
     $bridge->addText('grs_first_name')->addFilter($ucfirst);
     $bridge->addText('grs_surname_prefix', 'description', 'de, van der, \'t, etc...');
     $bridge->addText('grs_last_name', 'required', true)->addFilter($ucfirst);
     $bridge->addTab('caption2')->h4($this->_('Medical data'));
     $bridge->addRadio('grs_gender', 'separator', '', 'multiOptions', $this->util->getTranslated()->getGenders());
     $year = intval(date('Y'));
     // Als jQuery 1.4 gebruikt wordt: yearRange = c-130:c0
     $bridge->addDate('grs_birthday', 'jQueryParams', array('defaultDate' => '-30y', 'maxDate' => 0, 'yearRange' => $year - 130 . ':' . $year))->addValidator(new \MUtil_Validate_Date_DateBefore());
     //$bridge->addSelect(  'gr2o_id_physician');
     $bridge->addText('gr2o_treatment', 'size', 30, 'description', $this->_('DBC\'s, etc...'));
     $bridge->addTextarea('gr2o_comments', 'rows', 4, 'cols', 60);
     $bridge->addTab('caption3')->h4($this->_('Contact information'));
     // Setting e-mail to required is niet mogelijk, grijpt te diep in
     // misschien later proberen met ->addGroup('required', 'true'); ???
     $bridge->addText('grs_email', 'size', 30)->addValidator('SimpleEmail');
     $bridge->addCheckBox('calc_email', 'label', $this->_('Respondent has no e-mail'));
     $bridge->addRadio('gr2o_mailable');
     $bridge->addText('grs_address_1', 'size', 40, 'description', $this->_('With housenumber'))->addFilter($ucfirst);
     if ($model->has('grs_address_2')) {
         $bridge->addText('grs_address_2', 'size', 40);
     }
     $bridge->addText('grs_zipcode', 'size', 7, 'description', '0000 AA');
     $bridge->addFilter('grs_zipcode', new \Gems_Filter_DutchZipcode());
     $bridge->addText('grs_city')->addFilter($ucfirst);
     $bridge->addSelect('grs_iso_country', 'label', $this->_('Country'), 'multiOptions', $this->util->getLocalized()->getCountries());
     $bridge->addText('grs_phone_1', 'size', 15)->addValidator('Phone');
     $bridge->addTab('caption4')->h4($this->_('Settings'));
     $bridge->addSelect('grs_iso_lang', 'label', $this->_('Language'), 'multiOptions', $this->util->getLocalized()->getLanguages());
     $bridge->addRadio('gr2o_consent', 'separator', '', 'description', $this->_('Has the respondent signed the informed consent letter?'), 'required', true);
     return $returnValues;
 }
 /**
  * Adds elements from the model to the bridge that creates the form.
  *
  * Overrule this function to add different elements to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_FormBridgeInterface $bridge
  * @param \MUtil_Model_ModelAbstract $model
  * @param int $step The current step
  */
 protected function addFormElementsFor(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model, $step)
 {
     //Get all elements in the model if not already done
     $this->initItems();
     // Store the current step
     $bridge->addHidden($this->stepFieldName);
     $this->addStepElementsFor($bridge, $model, $step);
     //And any remaining item
     $this->addItemsHidden($bridge, $this->_items);
 }
 /**
  * Add items to the bridge, and remove them from the items array
  *
  * @param \MUtil_Model_Bridge_FormBridgeInterface $bridge
  * @param string $element1
  *
  * @return void
  */
 protected function addItems(\MUtil_Model_Bridge_FormBridgeInterface $bridge, $element1)
 {
     $args = func_get_args();
     if (count($args) < 2) {
         throw new \Gems_Exception_Coding('Use at least 2 arguments, first the bridge and then one or more individual items');
     }
     array_shift($args);
     // Remove bridge
     $elements = \MUtil_Ra::flatten($args);
     $model = $this->getModel();
     //Remove the elements from the _items variable
     $this->_items = array_diff($this->_items, $elements);
     //And add them to the bridge
     foreach ($elements as $name) {
         if ($model->has($name, 'label') || $model->has($name, 'elementClass')) {
             $bridge->add($name);
         } else {
             $bridge->addHidden($name);
         }
     }
 }
 /**
  * Adds elements from the model to the bridge that creates the form.
  *
  * Overrule this function to add different elements to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_FormBridgeInterface $bridge
  * @param \MUtil_Model_ModelAbstract $model
  */
 protected function addFormElements(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model)
 {
     $bridge->addHtml('to', 'label', $this->_('To'));
     $bridge->addHtml('prefered_language', 'label', $this->_('Prefered Language'));
     $bridge->addElement($this->mailElements->createTemplateSelectElement('select_template', $this->_('Template'), $this->mailTarget, $this->templateOnly, true));
     if ($this->templateOnly) {
         $bridge->addHidden('subject');
     } else {
         $bridge->addText('subject', 'label', $this->_('Subject'), 'size', 50);
     }
     $mailBody = $bridge->addElement($this->mailElements->createBodyElement('mailBody', $this->_('Message'), $model->get('gctt_body', 'required'), $this->templateOnly));
     if ($mailBody instanceof \Gems_Form_Element_CKEditor) {
         $mailBody->config['availablefields'] = $this->mailer->getMailFields();
         $mailBody->config['availablefieldsLabel'] = $this->_('Fields');
         $mailBody->config['extraPlugins'] .= ',availablefields';
         $mailBody->config['toolbar'][] = array('availablefields');
     }
     if (!$this->templateOnly) {
         $bridge->addFakeSubmit('preview', array('label' => $this->_('Preview')));
     }
     $bridge->addElement($this->createFromSelect('from', $this->_('From')));
     $bridge->addElement($this->mailElements->createSubmitButton('send', $this->_('Send')));
     $bridge->addElement($this->mailElements->createPreviewHtmlElement('Preview HTML'));
     $bridge->addElement($this->mailElements->createPreviewTextElement('Preview Text'));
     if (!$this->templateOnly) {
         $bridge->addHtml('available_fields', array('label' => $this->_('Available fields')));
     }
 }
示例#7
0
 /**
  * Adds elements from the model to the bridge that creates the form.
  *
  * Overrule this function to add different elements to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_FormBridgeInterface $bridge
  * @param \MUtil_Model_ModelAbstract $model
  * @param array $data The data that will later be loaded into the form
  * @param optional boolean $new Form should be for a new element
  * @return void|array When an array of new values is return, these are used to update the $data array in the calling function
  */
 protected function addFormElements(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model, array $data, $new = false)
 {
     foreach ($model->getItemsOrdered() as $name) {
         if ($model->has($name, 'label') || $model->has($name, 'elementClass')) {
             $bridge->add($name);
         } else {
             $bridge->addHidden($name);
         }
     }
 }