/**
  * Appends the needed fields for this config to the $bridge
  *
  * @param \MUtil_Model_ModelAbstract $orgModel
  */
 public function addConfigFields(\MUtil_Model_ModelAbstract $orgModel)
 {
     $configModel = $this->getConfigModel(true);
     $order = $orgModel->getOrder('gor_user_class') + 1;
     foreach ($configModel->getItemNames() as $name) {
         $orgModel->set($name, 'order', $order++, 'tab', 'access');
         $orgModel->set($name, $configModel->get($name));
     }
 }
 /**
 * Adds rows from the model to the bridge that creates the browse table.
 *
 * Overrule this function to add different columns to the browse table, without
 * having to recode the core table building code.
 *
 * @param \MUtil_Model_Bridge_VerticalTableBridge $bridge
 * @param \MUtil_Model_ModelAbstract $model
 * @return void
 * /
     protected function addShowTableRows(\MUtil_Model_Bridge_VerticalTableBridge $bridge, \MUtil_Model_ModelAbstract $model)
     {
    parent::addShowTableRows($bridge, $model);
     }
 
     /**
 * Creates the model
 *
 * @return \MUtil_Model_ModelAbstract
 */
 protected function createModel()
 {
     if (!$this->model instanceof \Gems_Model_AppointmentModel) {
         $this->model = $this->loader->getModels()->createAppointmentModel();
         $this->model->applyDetailSettings();
     }
     $this->model->set('gap_admission_time', 'formatFunction', array($this, 'displayDate'));
     $this->model->set('gap_discharge_time', 'formatFunction', array($this, 'displayDate'));
     return $this->model;
 }
 /**
  * Adds columns from the model to the bridge that creates the browse table.
  *
  * Adds a button column to the model, if such a button exists in the model.
  *
  * @param \MUtil_Model_Bridge_TableBridge $bridge
  * @param \MUtil_Model_ModelAbstract $model
  * @return void
  */
 protected function addBrowseTableColumns(\MUtil_Model_Bridge_TableBridge $bridge, \MUtil_Model_ModelAbstract $model)
 {
     $bridge->gr2t_id_respondent_track;
     // Data needed for edit button
     $bridge->gr2o_id_organization;
     // Data needed for edit button
     $HTML = \MUtil_Html::create();
     // Get the buttons
     if ($menuItem = $this->menu->find(array('controller' => 'respondent', 'action' => 'show', 'allowed' => true))) {
         $respondentButton = $menuItem->toActionLink($this->getRequest(), $bridge, $this->_('Show respondent'));
         $respondentButton->appendAttrib('class', 'rightFloat');
     } else {
         $respondentButton = null;
     }
     if ($menuItem = $this->menu->find(array('controller' => 'track', 'action' => 'show-track', 'allowed' => true))) {
         $trackButton = $menuItem->toActionLink($this->getRequest(), $bridge, $this->_('Show track'));
         $trackButton->appendAttrib('class', 'rightFloat');
     } else {
         $trackButton = null;
     }
     // Row with dates and patient data
     $bridge->tr(array('onlyWhenChanged' => true, 'class' => 'even'));
     $bridge->addSortable('gr2o_patient_nr');
     $bridge->addSortable('respondent_name')->colspan = 2;
     if ($this->escort instanceof \Gems_Project_Tracks_SingleTrackInterface) {
         $bridge->addSortable('grs_birthday');
         $bridge->addMultiSort('progress', array($respondentButton));
     } else {
         $bridge->addSortable('grs_birthday');
         $bridge->addMultiSort('grs_city', array($respondentButton));
         $model->set('gr2t_track_info', 'tableDisplay', 'smallData');
         // Row with track info
         $bridge->tr(array('onlyWhenChanged' => true, 'class' => 'even'));
         $td = $bridge->addMultiSort('gtr_track_name', 'gr2t_track_info');
         $td->class = 'indentLeft';
         $td->colspan = 4;
         $td->renderWithoutContent = false;
         // Do not display this cell and thus this row if there is not content
         $td = $bridge->addMultiSort('progress', array($trackButton));
         $td->renderWithoutContent = false;
         // Do not display this cell and thus this row if there is not content
     }
     $bridge->tr(array('class' => array('odd', $bridge->row_class), 'title' => $bridge->gto_comment));
     $bridge->addColumn($this->getTokenLinks($bridge))->class = 'rightAlign';
     $bridge->addSortable('gto_valid_from');
     $bridge->addSortable('gto_valid_until');
     $model->set('gto_round_description', 'tableDisplay', 'smallData');
     $bridge->addMultiSort('gsu_survey_name', 'gto_round_description')->colspan = 2;
     $bridge->tr(array('class' => array('odd', $bridge->row_class), 'title' => $bridge->gto_comment));
     $bridge->addColumn();
     $bridge->addSortable('gto_mail_sent_date');
     $bridge->addSortable('gto_completion_time');
     $bridge->addSortable('gto_id_token');
     $bridge->addMultiSort('ggp_name', array($this->getActionLinks($bridge)));
 }
 /**
  * Creates the model
  *
  * @return \MUtil_Model_ModelAbstract
  */
 protected function createModel()
 {
     // Replace two checkboxes with on radio button control
     $this->model->set('ggp_staff_members', 'elementClass', 'Hidden');
     $this->model->setOnSave('ggp_staff_members', array($this, 'saveIsStaff'));
     $this->model->set('ggp_respondent_members', 'elementClass', 'Hidden');
     $this->model->setOnSave('ggp_respondent_members', array($this, 'saveIsRespondent'));
     $options = array('1' => $this->model->get('ggp_staff_members', 'label'), '2' => $this->model->get('ggp_respondent_members', 'label'));
     $this->model->set('staff_respondent', 'label', $this->_('Can be assigned to'), 'elementClass', 'Radio', 'multiOptions', $options, 'order', $this->model->getOrder('ggp_staff_members') + 1);
     $this->model->setOnLoad('staff_respondent', array($this, 'loadStaffRespondent'));
     return $this->model;
 }
 /**
  * Adds columns from the model to the bridge that creates the browse table.
  *
  * Overrule this function to add different columns to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_TableBridge $bridge
  * @param \MUtil_Model_ModelAbstract $model
  * @return void
  */
 public function addBrowseTableColumns(\MUtil_Model_Bridge_TableBridge $bridge, \MUtil_Model_ModelAbstract $model)
 {
     $model->set('gr2o_patient_nr', 'label', $this->_('Respondent'));
     $model->set('gto_round_description', 'label', $this->_('Round / Details'));
     $model->set('gto_valid_from', 'label', $this->_('Valid from'));
     $model->set('gto_valid_until', 'label', $this->_('Valid until'));
     $model->set('gto_mail_sent_date', 'label', $this->_('Contact date'));
     $model->set('respondent_name', 'label', $this->_('Name'));
     $HTML = \MUtil_Html::create();
     $bridge->setDefaultRowClass(\MUtil_Html_TableElement::createAlternateRowClass('even', 'even', 'odd', 'odd'));
     $bridge->addColumn($this->getTokenLinks($bridge), ' ')->rowspan = 2;
     // Space needed because TableElement does not look at rowspans
     $bridge->addSortable('gto_valid_from');
     $bridge->addSortable('gto_valid_until');
     $bridge->addMultiSort('gr2o_patient_nr', $HTML->raw('; '), 'respondent_name');
     $bridge->addMultiSort('ggp_name', array($this->getActionLinks($bridge)));
     $bridge->tr();
     $bridge->addSortable('gto_mail_sent_date');
     $bridge->addSortable('gto_completion_time');
     if ($this->escort instanceof \Gems_Project_Tracks_SingleTrackInterface) {
         $bridge->addMultiSort('gto_round_description', $HTML->raw('; '), 'gsu_survey_name');
     } else {
         $model->set('gr2t_track_info', 'tableDisplay', 'smallData');
         $model->set('gto_round_description', 'tableDisplay', 'smallData');
         $bridge->addMultiSort('gtr_track_name', 'gr2t_track_info', $bridge->gtr_track_name->if($HTML->raw(' » ')), 'gsu_survey_name', 'gto_round_description');
     }
     $bridge->addSortable('assigned_by');
 }
Beispiel #6
0
 /**
  *
  * @param string $trackingField The field that stores the tracking value
  * @param string $trackedField   The field whose changing is tracked
  * @param string $oldValueField Optional, the field to store a copy of the original value in
  */
 public function apply($trackingField, $trackedField, $oldValueField = null)
 {
     if (null === $oldValueField) {
         // Defautl name
         $oldValueField = self::OLD_FIELD_PREFIX . $trackedField;
         // Check if a fields already existed
         if (method_exists($this->_model, 'getKeyCopyName')) {
             $copyName = $this->_model->getKeyCopyName($trackedField);
             if ($this->_model->has($copyName)) {
                 $oldValueField = $copyName;
             }
         }
     }
     if (!$this->_model->has($oldValueField)) {
         $this->_model->set($oldValueField, 'elementClass', 'Hidden', __CLASS__, $trackedField);
         $this->_model->setOnLoad($oldValueField, array($this, 'loadOldValue'));
     }
     if (!$this->_model->has($trackingField)) {
         // Only load the original value and ste the original result when it was not already in the model
         $this->_model->setAutoSave($trackingField);
         // $this->_model->setOnLoad($trackingField, $this->_unchangedValue);
     }
     $this->_model->set($trackingField, __CLASS__, array($trackedField, $oldValueField));
     $this->_model->setOnSave($trackingField, array($this, 'saveValue'));
     // Store the extra hidden fields needed
     $hiddenFields = $this->_model->getMeta(self::HIDDEN_FIELDS, array());
     $hiddenFields[] = $oldValueField;
     $this->_model->setMeta(self::HIDDEN_FIELDS, $hiddenFields);
     // Make sure the fields are in the result set
     $this->_model->get($trackedField);
     $this->_model->get($trackingField);
     $this->_model->get($oldValueField);
 }
 /**
  * Adds columns from the model to the bridge that creates the browse table.
  *
  * Overrule this function to add different columns to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_TableBridge $bridge
  * @param \MUtil_Model_ModelAbstract $model
  * @return void
  */
 protected function addBrowseTableColumns(\MUtil_Model_Bridge_TableBridge $bridge, \MUtil_Model_ModelAbstract $model)
 {
     $model->set('gto_id_token', 'formatFunction', 'strtoupper');
     $bridge->setDefaultRowClass(\MUtil_Html_TableElement::createAlternateRowClass('even', 'even', 'odd', 'odd'));
     $tr1 = $bridge->tr();
     $tr1->appendAttrib('class', $bridge->row_class);
     $tr1->appendAttrib('title', $bridge->gto_comment);
     $bridge->addColumn($this->createShowTokenButton($bridge), ' ')->rowspan = 2;
     // Space needed because TableElement does not look at rowspans
     $bridge->addSortable('gto_valid_from');
     $bridge->addSortable('gto_valid_until');
     $bridge->addSortable('gto_id_token');
     // $bridge->addSortable('gto_mail_sent_num', $this->_('Contact moments'))->rowspan = 2;
     $this->addRespondentCell($bridge, $model);
     $bridge->addMultiSort('ggp_name', array($this->createActionButtons($bridge)));
     $tr2 = $bridge->tr();
     $tr2->appendAttrib('class', $bridge->row_class);
     $tr2->appendAttrib('title', $bridge->gto_comment);
     $bridge->addSortable('gto_mail_sent_date');
     $bridge->addSortable('gto_completion_time');
     $bridge->addSortable('gto_mail_sent_num', $this->_('Contact moments'));
     if ($this->multiTracks) {
         $model->set('gr2t_track_info', 'tableDisplay', 'smallData');
         $model->set('gto_round_description', 'tableDisplay', 'smallData');
         $bridge->addMultiSort('gtr_track_name', 'gr2t_track_info', array($bridge->gtr_track_name->if(\MUtil_Html::raw(' » ')), ' '), 'gsu_survey_name', 'gto_round_description');
     } else {
         $bridge->addMultiSort('gto_round_description', \MUtil_Html::raw('; '), 'gsu_survey_name');
     }
     $bridge->addSortable('assigned_by');
 }
 /**
  * Adds columns from the model to the bridge that creates the browse table.
  *
  * Overrule this function to add different columns to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_TableBridge $bridge
  * @param \MUtil_Model_ModelAbstract $model
  * @return void
  */
 protected function addBrowseTableColumns(\MUtil_Model_Bridge_TableBridge $bridge, \MUtil_Model_ModelAbstract $model)
 {
     // Add link to patient to overview
     $menuItems = $this->findMenuItems('respondent', 'show');
     if ($menuItems) {
         $menuItem = reset($menuItems);
         if ($menuItem instanceof \Gems_Menu_SubMenuItem) {
             $href = $menuItem->toHRefAttribute($bridge);
             if ($href) {
                 $aElem = new \MUtil_Html_AElement($href);
                 $aElem->setOnEmpty('');
                 // Make sure org is known
                 $model->get('gr2o_id_organization');
                 $model->set('gr2o_patient_nr', 'itemDisplay', $aElem);
                 $model->set('respondent_name', 'itemDisplay', $aElem);
             }
         }
     }
     $model->set('gto_id_token', 'formatFunction', 'strtoupper');
     $bridge->setDefaultRowClass(\MUtil_Html_TableElement::createAlternateRowClass('even', 'even', 'odd', 'odd'));
     $tr1 = $bridge->tr();
     $tr1->appendAttrib('class', $bridge->row_class);
     $tr1->appendAttrib('title', $bridge->gto_comment);
     $bridge->addColumn($this->createShowTokenButton($bridge), ' ')->rowspan = 2;
     // Space needed because TableElement does not look at rowspans
     $bridge->addSortable('gto_valid_from');
     $bridge->addSortable('gto_valid_until');
     $bridge->addSortable('gto_id_token');
     // $bridge->addSortable('gto_mail_sent_num', $this->_('Contact moments'))->rowspan = 2;
     $this->addRespondentCell($bridge, $model);
     $bridge->addMultiSort('ggp_name', array($this->createActionButtons($bridge)));
     $tr2 = $bridge->tr();
     $tr2->appendAttrib('class', $bridge->row_class);
     $tr2->appendAttrib('title', $bridge->gto_comment);
     $bridge->addSortable('gto_mail_sent_date');
     $bridge->addSortable('gto_completion_time');
     $bridge->addSortable('gto_mail_sent_num', $this->_('Contact moments'));
     if ($this->multiTracks) {
         $model->set('gr2t_track_info', 'tableDisplay', 'smallData');
         $model->set('gto_round_description', 'tableDisplay', 'smallData');
         $bridge->addMultiSort('gtr_track_name', 'gr2t_track_info', array($bridge->gtr_track_name->if(\MUtil_Html::raw(' » ')), ' '), 'gsu_survey_name', 'gto_round_description');
     } else {
         $bridge->addMultiSort('gto_round_description', \MUtil_Html::raw('; '), 'gsu_survey_name');
     }
     $bridge->addSortable('assigned_by');
 }
 /**
  * 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)
 {
     $onOffFields = array('gr2t_track_info', 'gto_round_description', 'grc_description');
     foreach ($onOffFields as $field) {
         if (!(isset($this->formData[$field]) && $this->formData[$field])) {
             $model->set($field, 'elementClass', 'None');
         }
     }
     parent::addFormElements($bridge, $model);
 }
 /**
  * Set the surveys to be listed as valid for choices for this item and the way they are displayed (if at all)
  *
  * @param \MUtil_Model_ModelAbstract $model The round model
  * @param array $itemData    The current items data
  * @param boolean True if the update changed values (usually by changed selection lists).
  */
 protected function applySurveyListValidFor(\MUtil_Model_ModelAbstract $model, array &$itemData)
 {
     if (!(isset($itemData['gro_id_round']) && $itemData['gro_id_round'])) {
         $itemData['gro_id_round'] = '';
     }
     // Fixed value
     $itemData['gro_valid_for_id'] = $itemData['gro_id_round'];
     // The options array
     $rounds[$itemData['gro_id_round']] = $this->_('This round');
     $model->set('gro_valid_for_id', 'multiOptions', $rounds, 'elementClass', 'Exhibitor');
     return false;
 }
 /**
  * Creates the model
  *
  * @return \MUtil_Model_ModelAbstract
  */
 protected function createModel()
 {
     if (!$this->model instanceof \Gems_Tracker_Model_TrackModel) {
         $tracker = $this->loader->getTracker();
         $this->model = $tracker->getRespondentTrackModel();
         if (!$this->trackEngine instanceof \Gems_Tracker_Engine_TrackEngineInterface) {
             $this->trackEngine = $this->respondentTrack->getTrackEngine();
         }
         $this->model->applyEditSettings($this->trackEngine);
     }
     $this->model->set('restore_tokens', 'label', $this->_('Restore tokens'), 'description', $this->_('Restores tokens with the same code as the track.'), 'elementClass', 'Checkbox');
     return $this->model;
 }
 /**
  * Use this function for a default application of this type to the model
  *
  * @param \MUtil_Model_ModelAbstract $model
  * @param string $valueField The field containing the value to be encrypted
  * #param string $methodField the field storing the method of encryption
  * @return \Gems_Model_Type_EncryptedField (continuation pattern)
  */
 public function apply(\MUtil_Model_ModelAbstract $model, $valueField, $methodField)
 {
     $this->findValue[$methodField] = $valueField;
     $model->setSaveWhenNotNull($valueField);
     $model->setOnLoad($valueField, array($this, 'loadValue'));
     $model->setOnSave($valueField, array($this, 'saveValue'));
     // Only hidden to make sure onSave's are triggered
     $model->set($methodField, 'elementClass', 'hidden');
     $model->setOnLoad($methodField, 'default');
     // Yes you can set this to a constant
     $model->setSaveWhen($methodField, array($this, 'whenEncryption'));
     $model->setOnSave($methodField, array($this, 'saveEncryption'));
     if ($model instanceof \MUtil_Model_DatabaseModelAbstract) {
         $model->setOnTextFilter($valueField, false);
         $model->setOnTextFilter($methodField, false);
     }
     return $this;
 }
 /**
  * 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;
 }
Beispiel #14
0
 /**
  * Use this function for a default application of this type to the model
  *
  * @param \MUtil_Model_ModelAbstract $model
  * @param string $name The field to set the seperator character
  * @return \MUtil_Model_Type_ConcatenatedRow (continuation pattern)
  */
 public function apply(\MUtil_Model_ModelAbstract $model, $name)
 {
     $model->set($name, 'formatFunction', array($this, 'format'));
     $model->setOnLoad($name, array($this, 'loadValue'));
     $model->setOnSave($name, array($this, 'saveValue'));
     if ($model instanceof \MUtil_Model_DatabaseModelAbstract) {
         $model->setOnTextFilter($name, array($this, 'textFilter'));
     }
     $this->options = $model->get($name, 'multiOptions');
     return $this;
 }
 /**
  * Set the field values for a dutch zipcode
  *
  * @param \MUtil_Model_ModelAbstract $model
  * @param \Zend_Translate_Adapter $translator
  * @param string $fieldName
  */
 public static function setDutchZipcode(\MUtil_Model_ModelAbstract $model, \Zend_Translate_Adapter $translator, $fieldName = 'grs_zipcode')
 {
     $model->set($fieldName, 'size', 7, 'description', $translator->_('E.g.: 0000 AA'), 'filter', new \Gems_Filter_DutchZipcode());
 }
 /**
  * Add first columns (group) from the model to the bridge that creates the browse table.
  *
  * You can actually add more than one column in this function, but just call all four functions
  * with the default columns in each
  *
  * Overrule this function to add different columns to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_TableBridge $bridge
  * @param \MUtil_Model_ModelAbstract $model
  * @return void
  */
 protected function addBrowseColumn3(\MUtil_Model_Bridge_TableBridge $bridge, \MUtil_Model_ModelAbstract $model)
 {
     $br = \MUtil_Html::create('br');
     if ($model->hasAlias('gems__respondent2track')) {
         $model->set('gtr_track_name', 'label', $this->_('Track'));
         $model->set('gr2t_track_info', 'label', $this->_('Track description'));
         $items = $this->findMenuItems('track', 'show-track');
         $track = 'gtr_track_name';
         if ($items) {
             $menuItem = reset($items);
             if ($menuItem instanceof \Gems_Menu_MenuAbstract) {
                 $href = $menuItem->toHRefAttribute($this->request, $bridge, array('gr2t_id_respondent_track' => $bridge->gr2t_id_respondent_track));
                 $track = array();
                 $track[0] = \MUtil_Lazy::iif($bridge->gr2t_id_respondent_track, \MUtil_Html::create()->a($href, $bridge->gtr_track_name, array('onclick' => "event.cancelBubble = true;")));
                 $track[1] = $bridge->createSortLink('gtr_track_name');
             }
         }
         $bridge->addMultiSort($track, $br, 'gr2t_track_info');
     } else {
         $citysep = \MUtil_Html::raw('  ');
         // $bridge->itemIf($bridge->grs_zipcode, \MUtil_Html::raw('  '));
         $bridge->addMultiSort('grs_address_1', $br, 'grs_zipcode', $citysep, 'grs_city');
     }
 }
Beispiel #17
0
 /**
  * Use this function for a default application of this type to the model
  *
  * @param \MUtil_Model_ModelAbstract $model
  * @param string $name The field to set the seperator character
  * @param boolean $detailed When true show detailed information
  * @return \MUtil\Model\Type\JsonData (continuation pattern)
  */
 public function apply(\MUtil_Model_ModelAbstract $model, $name, $detailed)
 {
     if ($detailed) {
         $formatFunction = 'formatDetailed';
     } else {
         $formatFunction = 'formatTable';
     }
     $model->set($name, 'formatFunction', array($this, $formatFunction));
     $model->setOnLoad($name, array($this, 'loadValue'));
     $model->setOnSave($name, array($this, 'saveValue'));
 }
Beispiel #18
0
 /**
  * Recursively apply the changes from a dependency
  *
  * @param \MUtil_Model_ModelAbstract $model
  * @param array $changes
  * @param array $data Referenced data
  */
 protected function _applyDependencyChanges(\MUtil_Model_ModelAbstract $model, array $changes, array &$data)
 {
     // \MUtil_Echo::track($model->getName(), $changes, $data);
     // Here we could allow only those changes this dependency claims to change
     // or even check all of them are set.
     foreach ($changes as $name => $settings) {
         if (isset($settings['model'])) {
             $submodel = $model->get($name, 'model');
             // \MUtil_Echo::track($name, $settings['model'], $data[$name]);
             if ($submodel instanceof \MUtil_Model_ModelAbstract) {
                 if (!isset($data[$name])) {
                     $data[$name] = array();
                 }
                 foreach ($data[$name] as &$row) {
                     $submodel->_applyDependencyChanges($submodel, $settings['model'], $row);
                 }
             }
             unset($settings['model']);
         }
         $model->set($name, $settings);
         // Change the actual value
         if (isset($settings['value'])) {
             // \MUtil_Echo::track($name, $settings['value']);
             $data[$name] = $settings['value'];
         }
     }
 }
 /**
  * Use this function for a default application of this dependency to the model
  *
  * @param \MUtil_Model_ModelAbstract $model Try not to store the model as variabe in the dependency (keep it simple)
  */
 public function applyToModel(\MUtil_Model_ModelAbstract $model)
 {
     if ($this->applyOnChange) {
         foreach ($this->getDependsOn() as $name) {
             if ($model->is($name, 'elementClass', 'Checkbox')) {
                 if (!$model->has($name, 'onclick')) {
                     $model->set($name, 'onclick', $this->onChangeJs);
                 }
             } else {
                 if (!$model->has($name, 'onchange')) {
                     $model->set($name, 'onchange', $this->onChangeJs);
                 }
             }
         }
     }
 }
 /**
  * Add the elements from the model to the bridge for the current step
  *
  * @param \MUtil_Model_Bridge_FormBridgeInterface $bridge
  * @param \MUtil_Model_ModelAbstract $model
  */
 protected function addStepExportCodes(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model)
 {
     $this->displayHeader($bridge, $this->_('Set the survey export codes'), 'h3');
     $rounds = $this->formData['rounds'];
     $surveyCodes = array();
     foreach ($rounds as $roundId) {
         $round = $this->trackEngine->getRound($roundId);
         $sid = $round->getSurveyId();
         $name = 'survey__' . $sid;
         $surveyCodes[$name] = $name;
         $model->set($name, 'validator', array('ValidateSurveyExportCode', true, array($sid, $this->db)));
     }
     $this->addItems($bridge, $surveyCodes);
 }
 /**
  * Add the settings from the transformed import data to the formData and the model
  *
  * @param \ArrayObject $import
  * @param \MUtil_Model_ModelAbstract $model
  */
 public function addExistingRoundsToModel(\ArrayObject $import, \MUtil_Model_ModelAbstract $model)
 {
     $currentRounds = $this->trackEngine->getRounds();
     if (!$currentRounds) {
         return;
     }
     $importRounds = array();
     $newImportRounds = array();
     $tracker = $this->loader->getTracker();
     foreach ($import['rounds'] as $lineNr => $roundData) {
         if (isset($roundData['survey_export_code'], $import['surveyCodes'][$roundData['survey_export_code']])) {
             $roundData['gro_id_survey'] = $import['surveyCodes'][$roundData['survey_export_code']];
             $round = $tracker->createTrackClass('Round', $roundData);
             $importRounds[$round->getRoundOrder()] = $round->getFullDescription();
             $newImportRounds[$round->getRoundOrder()] = sprintf($this->_('Set round to round %s'), $round->getFullDescription());
             $import['roundOrderToLine'][$round->getRoundOrder()] = $lineNr;
         }
     }
     // Filter for rounds not in current track
     foreach ($currentRounds as $roundId => $round) {
         if ($round instanceof Round) {
             $order = $round->getRoundOrder();
             if (isset($newImportRounds[$order])) {
                 unset($newImportRounds[$order]);
             }
         }
     }
     $except = array(self::ROUND_LEAVE, self::ROUND_DEACTIVATE);
     $notEqualTo = array();
     // Make sure no round is imported twice
     foreach ($currentRounds as $roundId => $round) {
         if ($round instanceof Round) {
             $name = "round_{$roundId}";
             $order = $round->getRoundOrder();
             $model->set($name, 'existingRound', true, 'required', true, 'roundId', $roundId);
             if (isset($importRounds[$order])) {
                 if ($round->getFullDescription() == $importRounds[$order]) {
                     $options = array(self::ROUND_LEAVE => $this->_('Leave current round'), $order => $this->_('Replace with import round'));
                 } else {
                     $options = array(self::ROUND_LEAVE => $this->_('Leave current round'), $order => sprintf($this->_('Replace with import round %s'), $importRounds[$order]));
                 }
                 $model->set($name, 'label', sprintf($this->_('Matching round %s'), $round->getFullDescription()), 'elementClass', 'Radio', 'multiOptions', $options);
                 $value = $order;
             } else {
                 $model->set($name, 'label', sprintf($this->_('Round not in import: %s'), $round->getFullDescription()), 'elementClass', 'Select', 'multiOptions', array(self::ROUND_LEAVE => sprintf($this->_('Leave current round %d unchanged'), $order), self::ROUND_DEACTIVATE => sprintf($this->_('Deactivate current round %d'), $order)) + $newImportRounds, 'size', 3 + count($newImportRounds));
                 $value = null;
                 if ($notEqualTo) {
                     $notEqualVal = new NotEqualExcept($notEqualTo, $except);
                     $model->set($name, 'validators[notequal]', $notEqualVal);
                 }
                 $notEqualTo[] = $name;
             }
             if (!array_key_exists($name, $this->formData)) {
                 $this->formData[$name] = $value;
             }
         }
     }
 }
 /**
  * Applies the fieldmap data to the model
  *
  * @param \MUtil_Model_ModelAbstract $model
  */
 public function applyToModel(\MUtil_Model_ModelAbstract $model)
 {
     $map = $this->_getMap();
     $oldfld = null;
     $parent = null;
     foreach ($map as $name => $field) {
         $tmpres = array();
         $tmpres['thClass'] = \Gems_Tracker_SurveyModel::CLASS_MAIN_QUESTION;
         $tmpres['group'] = $field['gid'];
         $tmpres['type'] = $this->_getType($field);
         $tmpres['survey_question'] = true;
         if ($tmpres['type'] === \MUtil_Model::TYPE_DATE) {
             $tmpres['storageFormat'] = 'yyyy-MM-dd';
             $tmpres['dateFormat'] = 'dd MMMM yyyy';
             // $tmpres['formatFunction']
         }
         if ($tmpres['type'] === \MUtil_Model::TYPE_DATETIME) {
             $tmpres['storageFormat'] = 'yyyy-MM-dd HH:mm:ss';
             $tmpres['dateFormat'] = 'dd MMMM yyyy HH:mm';
             // $tmpres['formatFunction']
         }
         if ($tmpres['type'] === \MUtil_Model::TYPE_TIME) {
             $tmpres['storageFormat'] = 'yyyy-MM-dd HH:mm:ss';
             $tmpres['dateFormat'] = 'HH:mm:ss';
             // $tmpres['formatFunction']
         }
         // \MUtil_Echo::track($field);
         $oldQuestion = isset($oldfld['question']) ? $oldfld['question'] : null;
         if (isset($field['question']) && (!isset($oldfld) || $oldQuestion !== $field['question'])) {
             $tmpres['label'] = \MUtil_Html::raw($this->removeMarkup($field['question']));
         }
         if (isset($field['help']) && $field['help']) {
             $tmpres['description'] = \MUtil_Html::raw($this->removeMarkup($field['help']));
         }
         // Juggle the labels for sub-questions etc..
         if (isset($field['sq_question'])) {
             if (isset($tmpres['label'])) {
                 // Add non answered question for grouping and make it the current parent
                 //$parent = '_' . $name . '_';
                 $parent = $field['title'];
                 $model->set($parent, $tmpres);
                 $model->set($parent, 'type', \MUtil_Model::TYPE_NOVALUE);
             }
             if (isset($field['sq_question1'])) {
                 $tmpres['label'] = \MUtil_Html::raw(sprintf($this->translate->_('%s: %s'), $this->removeMarkup($field['sq_question']), $this->removeMarkup($field['sq_question1'])));
             } else {
                 $tmpres['label'] = \MUtil_Html::raw($this->removeMarkup($field['sq_question']));
             }
             $tmpres['thClass'] = \Gems_Tracker_SurveyModel::CLASS_SUB_QUESTION;
         }
         if ($options = $this->_getMultiOptions($field)) {
             $tmpres['multiOptions'] = $options;
         }
         // Code does not have to be unique. So if a title is used
         // twice we only use it for the first result.
         if (isset($field['code']) && !$model->has($field['code'])) {
             $name = $field['code'];
         }
         // Parent storage
         if (\Gems_Tracker_SurveyModel::CLASS_MAIN_QUESTION === $tmpres['thClass']) {
             $parent = $name;
         } elseif ($parent) {
             // Add the name of the parent item
             $tmpres['parent_question'] = $parent;
         }
         $model->set($name, $tmpres);
         $oldfld = $field;
     }
 }
 /**
  * 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);
 }
 /**
  * The logic to set the display of the valid_X_field date list field.
  *
  * @param \MUtil_Model_ModelAbstract $model The round model
  * @param string $fieldName The valid_X_field to set
  * @param string $source The date list source as defined by this object
  * @param int $roundId Optional a round id
  * @param string $language   (ISO) language string
  * @param boolean $validAfter True if it concerns _valid_after_ dates
  */
 protected function setDateListFor(\MUtil_Model_ModelAbstract $model, $fieldName, $source, $roundId, $language, $validAfter)
 {
     $dateOptions = $this->getDateOptionsFor($source, $roundId, $language, $validAfter);
     switch (count($dateOptions)) {
         case 0:
             $model->del($fieldName, 'label');
             break;
         case 1:
             $model->set($fieldName, 'elementClass', 'exhibitor');
             // Intentional fall through
         // Intentional fall through
         default:
             $model->set($fieldName, 'multiOptions', $dateOptions);
             break;
     }
 }