/**
  * 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->respondent instanceof \Gems_Tracker_Respondent) {
         if (!$this->patientId) {
             $this->patientId = $this->respondent->getPatientNumber();
         }
         if (!$this->organizationId) {
             $this->organizationId = $this->respondent->getOrganizationId();
         }
     }
     // Try to get $this->respondentTrackId filled
     if (!$this->respondentTrackId) {
         if ($this->respondentTrack) {
             $this->respondentTrackId = $this->respondentTrack->getRespondentTrackId();
         } else {
             $this->respondentTrackId = $this->request->getParam(\Gems_Model::RESPONDENT_TRACK);
         }
     }
     // Try to get $this->respondentTrack filled
     if ($this->respondentTrackId && !$this->respondentTrack) {
         $this->respondentTrack = $this->loader->getTracker()->getRespondentTrack($this->respondentTrackId);
     }
     // Set the user id
     if (!$this->userId) {
         $this->userId = $this->loader->getCurrentUser()->getUserId();
     }
     if ($this->respondentTrack) {
         // We are updating
         $this->createData = false;
         // Try to get $this->trackEngine filled
         if (!$this->trackEngine) {
             // Set the engine used
             $this->trackEngine = $this->respondentTrack->getTrackEngine();
         }
     } else {
         // We are inserting
         $this->createData = true;
         $this->saveLabel = $this->_($this->_('Add track'));
         // Try to get $this->trackId filled
         if (!$this->trackId) {
             if ($this->trackEngine) {
                 $this->trackId = $this->trackEngine->getTrackId();
             } else {
                 $this->trackId = $this->request->getParam(\Gems_Model::TRACK_ID);
             }
         }
         // Try to get $this->trackEngine filled
         if ($this->trackId && !$this->trackEngine) {
             $this->trackEngine = $this->loader->getTracker()->getTrackEngine($this->trackId);
         }
         if (!($this->trackEngine && $this->patientId && $this->organizationId && $this->userId)) {
             throw new \Gems_Exception_Coding('Missing parameter for ' . __CLASS__ . ': could not find data for editing a respondent track nor the track engine, patientId and organizationId needed for creating one.');
         }
     }
     return parent::hasHtmlOutput();
 }
 /**
  * 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;
 }
 /**
  * Exports all the tokens of a single track, grouped by round
  *
  * @param \Gems_Tracker_RespondentTrack $track
  */
 protected function _exportTrackTokens(\Gems_Tracker_RespondentTrack $track)
 {
     $groupSurveys = $this->_group;
     $token = $track->getFirstToken();
     $engine = $track->getTrackEngine();
     $surveys = array();
     $table = $this->html->table(array('class' => 'browser table'));
     $table->th($this->_('Survey'))->th($this->_('Round'))->th($this->_('Token'))->th($this->_('Status'));
     $this->html->br();
     while ($token) {
         //Should this token be in the list?
         if (!$this->_isTokenInFilter($token)) {
             $token = $token->getNextToken();
             continue;
         }
         $table->tr()->td($token->getSurveyName())->td($engine->getTrackType() == 'T' ? $token->getRoundDescription() : $this->_('Single Survey'))->td(strtoupper($token->getTokenId()))->td($token->getStatus());
         //Should we display the answers?
         if (!$this->_displayToken($token)) {
             $token = $token->getNextToken();
             continue;
         }
         $showToken = false;
         if ($engine->getTrackType() == 'S' || !$groupSurveys) {
             // For single survey tracks or when $groupSurvey === false we show all tokens
             $showToken = true;
         } else {
             // For multi survey tracks and $groupSurveys === true, we show only the first token
             // as the snippet takes care of showing the other tokens
             if (!isset($surveys[$token->getSurveyId()])) {
                 $showToken = true;
                 $surveys[$token->getSurveyId()] = 1;
             }
         }
         if ($showToken) {
             $params = array('token' => $token, 'tokenId' => $token->getTokenId(), 'showHeaders' => false, 'showButtons' => false, 'showSelected' => false, 'showTakeButton' => false, 'grouped' => $groupSurveys);
             $snippets = $token->getAnswerSnippetNames();
             if (!is_array($snippets)) {
                 $snippets = array($snippets);
             }
             list($snippets, $snippetParams) = \MUtil_Ra::keySplit($snippets);
             $params = $params + $snippetParams;
             $this->html->snippet('Export_SurveyHeaderSnippet', 'token', $token);
             foreach ($snippets as $snippet) {
                 $this->html->snippet($snippet, $params);
             }
             $this->html->br();
         }
         $token = $token->getNextToken();
     }
 }