/**
  * Overrule to implement snippet specific filtering and sorting.
  *
  * @param \MUtil_Model_ModelAbstract $model
  */
 protected function processFilterAndSort(\MUtil_Model_ModelAbstract $model)
 {
     $filter['gto_id_respondent'] = $this->respondent->getId();
     if (is_array($this->forOtherOrgs)) {
         $filter['gto_id_organization'] = $this->forOtherOrgs;
     } elseif (true !== $this->forOtherOrgs) {
         $filter['gto_id_organization'] = $this->respondent->getOrganizationId();
     }
     // Filter for valid track reception codes
     $filter[] = 'gr2t_reception_code IN (SELECT grc_id_reception_code FROM gems__reception_codes WHERE grc_success = 1)';
     $filter['grc_success'] = 1;
     // Active round
     // or
     // no round
     // or
     // token is success and completed
     $filter[] = 'gro_active = 1 OR gro_active IS NULL OR (grc_success=1 AND gto_completion_time IS NOT NULL)';
     $filter['gsu_active'] = 1;
     // NOTE! $this->model does not need to be the token model, but $model is a token model
     $tabFilter = $this->model->getMeta('tab_filter');
     if ($tabFilter) {
         $model->addFilter($tabFilter);
     }
     $model->addFilter($filter);
     // \MUtil_Echo::track($model->getFilter());
     $this->processSortOnly($model);
 }
 /**
  * Function used to fill the tab bar
  *
  * @return array tabId => label
  */
 protected function getTabs()
 {
     $user = $this->loader->getCurrentUser();
     $sql = "SELECT gr2o_id_organization, gr2o_patient_nr FROM gems__respondent2org WHERE gr2o_id_user = ?";
     $this->defaultTab = $user->getCurrentOrganizationId();
     $this->currentTab = $this->request->getParam(\MUtil_Model::REQUEST_ID2);
     $allowedOrgs = $user->getRespondentOrganizations();
     $existingOrgs = $this->db->fetchPairs($sql, $this->respondent->getId());
     $tabs = array();
     foreach ($allowedOrgs as $orgId => $name) {
         if (isset($existingOrgs[$orgId])) {
             $tabs[$orgId] = $name;
             $this->hrefs[$orgId] = array(\MUtil_Model::REQUEST_ID1 => $existingOrgs[$orgId], \MUtil_Model::REQUEST_ID2 => $orgId, 'RouteReset' => true);
         }
     }
     return $tabs;
 }
 /**
  * Process the respondent and return true when data has changed.
  *
  * The event has to handle the actual storage of the changes.
  *
  * @param \Gems_Tracker_Respondent $respondent
  * @param int $userId The current user
  * @return boolean True when something changed
  */
 public function processChangedRespondent(\Gems_Tracker_Respondent $respondent)
 {
     $changes = 0;
     $tracker = $this->loader->getTracker();
     $respTracks = $tracker->getRespondentTracks($respondent->getId(), $respondent->getOrganizationId());
     $userId = $this->currentUser->getUserId();
     foreach ($respTracks as $respondentTrack) {
         if ($respondentTrack instanceof \Gems_Tracker_RespondentTrack) {
             $changes += $respondentTrack->checkTrackTokens($userId);
         }
     }
     // \MUtil_Echo::track('Hi there! ' . $changes);
     return (bool) $changes;
 }
 /**
  * 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->multiTracks) {
         return false;
     }
     $this->tracker = $this->loader->getTracker();
     if (!$this->respondentTrackId) {
         $this->respondentTrackId = $this->request->getParam(\Gems_Model::RESPONDENT_TRACK);
     }
     if ($this->respondentTrackId) {
         if (!$this->respondentTrack instanceof \Gems_Tracker_RespondentTrack) {
             $this->respondentTrack = $this->tracker->getRespondentTrack($this->respondentTrackId);
         }
     }
     if ($this->respondentTrack instanceof \Gems_Tracker_RespondentTrack) {
         if (!$this->respondentTrackId) {
             $this->respondentTrackId = $this->respondentTrack->getRespondentTrackId();
         }
         $this->trackId = $this->respondentTrack->getTrackId();
         if (!$this->respondentId) {
             $this->respondentId = $this->respondentTrack->getRespondentId();
         }
         if (!$this->organizationId) {
             $this->organizationId = $this->respondentTrack->getOrganizationId();
         }
         $this->caption = $this->_('Other assignments of this track to this respondent.');
         $this->onEmpty = $this->_('This track is assigned only once to this respondent.');
     } else {
         if ($this->respondent instanceof \Gems_Tracker_Respondent) {
             if (!$this->respondentId) {
                 $this->respondentId = $this->respondent->getId();
             }
             if (!$this->organizationId) {
                 $this->organizationId = $this->respondent->getOrganizationId();
             }
         }
         $this->caption = $this->_('Existing assignments of this track to this respondent.');
         $this->onEmpty = $this->_('This track is not assigned to this respondent.');
     }
     if (!$this->trackId) {
         $this->trackId = $this->request->getParam(\Gems_Model::TRACK_ID);
     }
     if (!$this->trackId && $this->trackEngine instanceof \Gems_Tracker_Engine_TrackEngineInterface) {
         $this->trackId = $this->trackEngine->getTrackId();
     }
     return $this->trackId && $this->respondentId && $this->organizationId && parent::hasHtmlOutput();
 }
 /**
  * Should be called after answering the request to allow the Target
  * to check if all required registry values have been set correctly.
  *
  * @return boolean False if required are missing.
  */
 public function checkRegistryRequestsAnswers()
 {
     if (!$this->organizationId) {
         if ($this->respondent) {
             $this->organizationId = $this->respondent->getOrganizationId();
         }
         if (!$this->organizationId) {
             $this->organizationId = $this->request->getParam(\MUtil_Model::REQUEST_ID2);
         }
     }
     if ($this->organizationId && !$this->respondentId) {
         if ($this->respondent) {
             $this->respondentId = $this->respondent->getId();
         }
         if (!$this->respondentId) {
             $this->respondentId = $this->util->getDbLookup()->getRespondentId($this->request->getParam(\MUtil_Model::REQUEST_ID1), $this->organizationId);
         }
     }
     return $this->organizationId && $this->respondentId && $this->db && $this->model;
 }
 /**
  * Creates the model
  *
  * @return \MUtil_Model_ModelAbstract
  */
 protected function createModel()
 {
     if ($this->model instanceof \Gems_Model_AppointmentModel) {
         $model = $this->model;
     } else {
         $model = $this->loader->getModels()->createAppointmentModel();
         $model->applyBrowseSettings();
     }
     $model->addColumn(new \Zend_Db_Expr("CONVERT(gap_admission_time, DATE)"), 'date_only');
     $model->set('date_only', 'formatFunction', array($this, 'formatDate'));
     // 'dateFormat', \Zend_Date::DAY_SHORT . ' ' . \Zend_Date::MONTH_NAME . ' ' . \Zend_Date::YEAR);
     $model->set('gap_admission_time', 'label', $this->_('Time'), 'formatFunction', array($this, 'formatTime'));
     // 'dateFormat', 'HH:mm ' . \Zend_Date::WEEKDAY);
     $this->_dateStorageFormat = $model->get('gap_admission_time', 'storageFormat');
     // $this->_timeImg           = \MUtil_Html::create('img', array('src' => 'stopwatch.png', 'alt' => ''));
     $model->set('gr2o_patient_nr', 'label', $this->_('Respondent nr'));
     if ($this->respondent instanceof \Gems_Tracker_Respondent) {
         $model->addFilter(array('gap_id_user' => $this->respondent->getId(), 'gap_id_organization' => $this->respondent->getOrganizationId()));
     }
     return $model;
 }