/**
  * Hook that allows actions when data was saved
  *
  * When not rerouted, the form will be populated afterwards
  *
  * @param int $changed The number of changed rows (0 or 1 usually, but can be more)
  */
 protected function afterSave($changed)
 {
     parent::afterSave($changed);
     $model = $this->getModel();
     if ($model instanceof \Gems_Model_AppointmentModel) {
         $count = $model->getChangedTokenCount();
         if ($count) {
             $this->addMessage(sprintf($this->plural('%d token changed', '%d tokens changed', $count), $count));
         }
     }
 }
 /**
  * Hook containing the actual save code.
  *
  * Call's afterSave() for user interaction.
  *
  * @see afterSave()
  */
 protected function saveData()
 {
     // feature request #200
     if (isset($this->formData['gtr_organizations']) && is_array($this->formData['gtr_organizations'])) {
         $this->formData['gtr_organizations'] = '|' . implode('|', $this->formData['gtr_organizations']) . '|';
     }
     if ($this->trackEngine) {
         $this->formData['gtr_survey_rounds'] = $this->trackEngine->calculateRoundCount();
     } else {
         $this->formData['gtr_survey_rounds'] = 0;
     }
     parent::saveData();
     // Check for creation
     if ($this->createData) {
         if (isset($this->formData['gtr_id_track'])) {
             $this->trackId = $this->formData['gtr_id_track'];
         }
     } elseif ($this->trackEngine && isset($this->formData[$this->_oldClassName], $this->formData['gtr_track_class']) && $this->formData[$this->_oldClassName] != $this->formData['gtr_track_class']) {
         // Track conversion
         $this->trackEngine->convertTo($this->formData['gtr_track_class']);
     }
 }
 /**
  * Perform some actions on the form, right before it is displayed but already populated
  *
  * Here we add the table display to the form.
  *
  * @return \Zend_Form
  */
 public function beforeDisplay()
 {
     parent::beforeDisplay();
     $element = $this->_form->getElement('grl_parents');
     if ($element instanceof \Zend_Form_Element_MultiCheckbox) {
         $options = $element->getMultiOptions();
         // Remove this as validator with allowed empty list has occured
         unset($options['']);
         $element->setMultiOptions($options);
     }
 }
 /**
  * Hook that loads the form data from $_POST or the model
  *
  * Or from whatever other source you specify here.
  */
 protected function loadFormData()
 {
     if ($this->createData && !$this->request->isPost()) {
         $now = new \MUtil_Date();
         $organizationId = $this->request->getParam(\MUtil_Model::REQUEST_ID2);
         $patientId = $this->request->getParam(\MUtil_Model::REQUEST_ID1);
         $respondentData = $this->util->getDbLookup()->getRespondentIdAndName($patientId, $organizationId);
         $this->formData = array('gr2o_patient_nr' => $patientId, 'gto_id_organization' => $organizationId, 'gto_id_respondent' => $respondentData['id'], 'respondent_name' => $respondentData['name'], 'gto_id_survey' => $this->request->getParam(\Gems_Model::SURVEY_ID), 'gto_id_track' => $this->request->getParam(\Gems_Model::TRACK_ID), 'gto_valid_from_manual' => 1, 'gto_valid_from' => $now, 'gto_valid_until_manual' => 0, 'gto_valid_until' => null);
         $this->getModel()->processAfterLoad(array($this->formData), $this->createData, false);
     } else {
         parent::loadFormData();
     }
     $this->loadSurvey();
     $this->loadTrackSettings();
     $this->loadRoundSettings();
     // \MUtil_Echo::track($this->formData);
 }
 /**
  * If the current user is the system user, present a message and don't allow to edit
  *
  * @return boolean
  */
 public function hasHtmlOutput()
 {
     if ($this->currentUser->getUserId() == \Gems_User_UserLoader::SYSTEM_USER_ID) {
         $this->addMessage($this->getNotAllowedMessage());
         return false;
     }
     return parent::hasHtmlOutput();
 }
 /**
  * The place to check if the data set in the snippet is valid
  * to generate the snippet.
  *
  * When invalid data should result in an error, you can throw it
  * here but you can also perform the check in the
  * checkRegistryRequestsAnswers() function from the
  * {@see \MUtil_Registry_TargetInterface}.
  *
  * @return boolean
  */
 public function hasHtmlOutput()
 {
     if (!$this->tokenId) {
         if ($this->token) {
             $this->tokenId = $this->token->getTokenId();
         } elseif ($this->request) {
             $this->tokenId = $this->request->getParam(\MUtil_Model::REQUEST_ID);
         }
     }
     if ($this->tokenId && !$this->token) {
         $this->token = $this->loader->getTracker()->getToken($this->tokenId);
     }
     // Output always true, returns an error message as html when anything is wrong
     return parent::hasHtmlOutput();
 }
 /**
  * Makes sure there is a form.
  */
 protected function loadForm()
 {
     $model = $this->getModel();
     $this->unDelete = $this->isUndeleting();
     $receptionCodes = $this->getReceptionCodes();
     // \MUtil_Echo::track($this->unDelete, $receptionCodes);
     if (!$receptionCodes) {
         throw new \Gems_Exception($this->_('No reception codes exist.'));
     }
     if ($this->unDelete) {
         $label = $this->_('Restore code');
     } else {
         if ($this->unDeleteRight && !$this->loader->getCurrentUser()->hasPrivilege($this->unDeleteRight)) {
             $this->addMessage($this->_('Watch out! You yourself cannot undo this change!'));
         }
         $label = $this->_('Rejection code');
     }
     $model->set($this->receptionCodeItem, 'label', $label);
     if ($this->fixedReceptionCode) {
         if (!isset($receptionCodes[$this->fixedReceptionCode])) {
             if ($this->fixedReceptionCode = $this->formData[$this->receptionCodeItem]) {
                 throw new \Gems_Exception($this->_('Already set to this reception code.'));
             } else {
                 throw new \Gems_Exception(sprintf($this->_('Reception code %s does not exist.'), $this->fixedReceptionCode));
             }
         }
     } elseif (count($receptionCodes) == 1) {
         reset($receptionCodes);
         $this->fixedReceptionCode = key($receptionCodes);
     }
     if ($this->fixedReceptionCode) {
         $model->set($this->receptionCodeItem, 'elementClass', 'Exhibitor', 'multiOptions', $receptionCodes);
         $this->formData[$this->receptionCodeItem] = $this->fixedReceptionCode;
     } else {
         $model->set($this->receptionCodeItem, 'elementClass', 'Select', 'multiOptions', array('' => '') + $receptionCodes, 'required', true, 'size', min(7, max(3, count($receptionCodes) + 2)));
         if (!isset($this->formData[$this->receptionCodeItem], $receptionCodes[$this->formData[$this->receptionCodeItem]])) {
             $this->formData[$this->receptionCodeItem] = '';
         }
     }
     $this->saveLabel = $this->getTitle();
     parent::loadForm();
 }
 /**
  * Hook containing the actual save code.
  *
  * Call's afterSave() for user interaction.
  *
  * @see afterSave()
  */
 protected function saveData()
 {
     parent::saveData();
     if ($this->createData && !$this->roundId) {
         $this->roundId = $this->formData['gro_id_round'];
     }
     if ($this->formData['gro_valid_for_source'] == 'tok' && $this->formData['gro_valid_for_field'] == 'gto_valid_from' && empty($this->formData['gro_valid_for_id'])) {
         // Special case we should insert the current roundID here
         $this->formData['gro_valid_for_id'] = $this->roundId;
         // Now save, don't call saveData again to keep changed message as is
         $model = $this->getModel();
         $this->formData = $model->save($this->formData);
     }
     $this->trackEngine->updateRoundCount($this->loader->getCurrentUser()->getUserId());
 }
 /**
  * After validation we clean the form data to remove all
  * entries that do not have elements in the form (and
  * this filters the data as well).
  */
 public function cleanFormData()
 {
     parent::cleanFormData();
     // You can only save data for the current user
     $this->formData['gsf_id_user'] = $this->loader->getCurrentUser()->getUserId();
 }
 /**
  * If menu item does not exist or is not allowed, redirect to index
  *
  * @return \Gems_Snippets_ModelFormSnippetAbstract
  */
 protected function setAfterSaveRoute()
 {
     parent::setAfterSaveRoute();
     if (is_array($this->afterSaveRouteUrl)) {
         if (isset($this->afterSaveRouteUrl['action'], $this->formData['gr2t_id_respondent_track']) && 'index' !== $this->afterSaveRouteUrl['action']) {
             $this->afterSaveRouteUrl[\Gems_Model::RESPONDENT_TRACK] = $this->formData['gr2t_id_respondent_track'];
         }
     }
 }