/**
  * Process the data and do what must be done
  *
  * Storing the changed $values is handled by the calling function.
  *
  * @param \Gems_Tracker_RespondentTrack $respTrack Gems respondent track object
  * @param int   $userId The current userId
  * @return void
  */
 public function processFieldUpdate(\Gems_Tracker_RespondentTrack $respTrack, $userId)
 {
     $agenda = $this->loader->getAgenda();
     $change = false;
     $token = $respTrack->getFirstToken();
     if (!$token) {
         return;
     }
     do {
         if ($token->isCompleted()) {
             continue;
         }
         $appId = $respTrack->getRoundAfterAppointmentId($token->getRoundId());
         // Not a round without appointment id
         if ($appId !== false) {
             if ($appId) {
                 $appointment = $agenda->getAppointment($appId);
             } else {
                 $appointment = null;
             }
             if ($appointment && $appointment->isActive()) {
                 $newCode = \GemsEscort::RECEPTION_OK;
                 $newText = null;
             } else {
                 $newCode = 'skip';
                 $newText = $this->_('Skipped until appointment is set');
             }
             $oldCode = \GemsEscort::RECEPTION_OK === $newCode ? 'skip' : \GemsEscort::RECEPTION_OK;
             $curCode = $token->getReceptionCode()->getCode();
             // \MUtil_Echo::track($token->getTokenId(), $curCode, $oldCode, $newCode);
             if ($oldCode === $curCode && $curCode !== $newCode) {
                 $change = true;
                 $token->setReceptionCode($newCode, $newText, $userId);
             }
         }
     } while ($token = $token->getNextToken());
     if ($change) {
         $respTrack->refresh();
     }
 }
 /**
  * Check the valid from and until dates in the track
  *
  * @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
  */
 public function checkTokensFromStart(\Gems_Tracker_RespondentTrack $respTrack, $userId)
 {
     $token = $respTrack->getFirstToken();
     if ($token instanceof \Gems_Tracker_Token) {
         return $this->checkTokensFrom($respTrack, $respTrack->getFirstToken(), $userId);
     } else {
         return 0;
     }
 }
 /**
  * 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();
     }
 }