protected function loadExport()
 {
     $this->export = $this->loader->getRespondentExport();
     if ($this->token instanceof \Gems_Tracker_Token) {
         $this->addRespondent($this->token->getPatientNumber(), $this->token->getOrganizationId());
         $this->export->addRespondentTrackFilter($this->token->getRespondentTrackId());
         $this->export->addTokenFilter($this->token->getTokenId());
     } elseif ($this->respondentTrack instanceof \Gems_Tracker_RespondentTrack) {
         $this->addRespondent($this->respondentTrack->getPatientNumber(), $this->respondentTrack->getOrganizationId());
         $this->export->addRespondentTrackFilter($this->respondentTrack->getRespondentTrackId());
     } elseif ($this->respondent instanceof \Gems_Tracker_Respondent) {
         $this->addRespondent($this->respondent->getPatientNumber(), $this->respondent->getOrganizationId());
     }
 }
 /**
  * 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();
 }
 /**
  * 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()
 {
     // Try to set $this->respondentTrackId, it can be ok when not set
     if (!$this->respondentTrackId) {
         if ($this->respondentTrack) {
             $this->respondentTrackId = $this->respondentTrack->getRespondentTrackId();
         } else {
             $this->respondentTrackId = $this->request->getParam(\Gems_Model::RESPONDENT_TRACK);
         }
     }
     // First attempt at trackId
     if (!$this->trackId && $this->trackEngine) {
         $this->trackId = $this->trackEngine->getTrackId();
     }
     // Check if a sufficient set of data is there
     if (!($this->trackId || $this->patientId || $this->organizationId)) {
         // Now we really need $this->respondentTrack
         if (!$this->respondentTrack) {
             if ($this->respondentTrackId) {
                 $this->respondentTrack = $this->loader->getTracker()->getRespondentTrack($this->respondentTrackId);
             } else {
                 // Parameters not valid
                 return false;
             }
         }
     }
     if (!$this->trackId) {
         $this->trackId = $this->respondentTrack->getTrackId();
     }
     if (!$this->patientId) {
         $this->patientId = $this->respondentTrack->getPatientNumber();
     }
     if (!$this->organizationId) {
         $this->organizationId = $this->respondentTrack->getOrganizationId();
     }
     // \MUtil_Echo::track($this->trackId, $this->patientId, $this->organizationId, $this->respondentTrackId);
     return $this->getModel()->loadFirst() && parent::hasHtmlOutput();
 }
 /**
  * Remove the unanswered tokens for inactive rounds.
  *
  * @param \Gems_Tracker_RespondentTrack $respTrack The respondent track to check
  * @param int $userId Id of the user who takes the action (for logging)
  * @return int The number of tokens changed by this code
  */
 protected function removeInactiveRounds(\Gems_Tracker_RespondentTrack $respTrack, $userId)
 {
     $qTrackId = $this->db->quote($this->_trackId);
     $qRespTrackId = $this->db->quote($respTrack->getRespondentTrackId());
     $orgId = $this->db->quote($respTrack->getOrganizationId());
     $where = "gto_start_time IS NULL AND\n            gto_id_respondent_track = {$qRespTrackId} AND\n            gto_id_round != 0 AND\n            gto_id_round IN (SELECT gro_id_round\n                    FROM gems__rounds\n                    WHERE (gro_active = 0 OR gro_organizations NOT LIKE CONCAT('%|',{$orgId},'|%')) AND\n                        gro_id_track = {$qTrackId})";
     return $this->db->delete('gems__tokens', $where);
 }