Returns a token with a success reception code for this round or null

@param type $roundId Gems round id
@param \Gems_Tracker_Token $token Optional token to add as a round (for speed optimization)
@return \Gems_Tracker_Token
540120
public function getActiveRoundToken($roundId, \Gems_Tracker_Token $token = null)
    {
        if ((null !== $token) && $token->hasSuccesCode()) {
            // Cache the token
            //
            // WARNING: This may cause bugs for tracks where two tokens exists
            // with this roundId and a success reception code, but this does speed
            // this function with track engines where that should not occur.
            $this->_activeTokens[$token->getRoundId()] = $token;
        }

        // Nothing to find
        if (! $roundId) {
            return null;
        }

        // Use array_key_exists since there may not be a valid round
        if (! array_key_exists($roundId, $this->_activeTokens)) {
            $tokenSelect = $this->tracker->getTokenSelect();
            $tokenSelect->andReceptionCodes()
                    ->forRespondentTrack($this->_respTrackId)
                    ->forRound($roundId)
                    ->onlySucces();

            // \MUtil_Echo::track($tokenSelect->__toString());

            if ($tokenData = $tokenSelect->fetchRow()) {
                $this->_activeTokens[$roundId] = $this->tracker->getToken($tokenData);
            } else {
                $this->_activeTokens[$roundId] = null;
            }
        }

        return $this->_activeTokens[$roundId];
    }
54301
public function updateConsent(\Gems_Tracker_Token $token, $consentCode = null)
    {
        $source = $this->getSource();
        return $source->updateConsent($token, $this->_surveyId, $this->_gemsSurvey['gsu_surveyor_id'], $consentCode);
    }
806489
public function getTokenInfo(\Gems_Tracker_Token $token, $surveyId, $sourceSurveyId, array $fields = null)
    {
        if (! $token->cacheHas(self::CACHE_TOKEN_INFO)) {
            if (null === $sourceSurveyId) {
                $sourceSurveyId = $this->_getSid($surveyId);
            }

            $lsTokens = $this->_getTokenTableName($sourceSurveyId);
            $tokenId  = $this->_getToken($token->getTokenId());

            $sql = 'SELECT *
                FROM ' . $lsTokens . '
                WHERE token = ? LIMIT 1';

            try {
                $result = $this->getSourceDatabase()->fetchRow($sql, $tokenId);
            } catch (\Zend_Db_Statement_Exception $exception) {
                $this->logger->logError($exception, $this->request);
                $result = false;
            }

            $token->cacheSet(self::CACHE_TOKEN_INFO, $result);
        } else {
            $result = $token->cacheGet(self::CACHE_TOKEN_INFO);
        }

        if ($fields !== null) $result = array_intersect_key((array) $result, array_flip($fields));

        return $result;
    }
895634
public function findNextTokenPosition($tokenId, $apos = null) {
		if ($apos === null) {
			$pos = $this->getCurrentPosition();
		} else {
			$pos = $apos;
		}
		$pos += 1; // Start from the token following the current position

		$nbTokens = count($this->tokens);
		while ($pos < $nbTokens) {
			$token = $this->tokens[$pos];

			if ($tokenId === $token->id) {
				return $pos;
			}

			$pos ++;
		}

		return null;
	}
85770
public function getTokenResult($token, callable $set = null)
    {
        return Pool::getInstance()->get(ClusterCoroutine::class)->init($token, $this->receive_call, $set);
    }
1275710
public function execute($trackId = null, $roundId = null)
    {
        $batch = $this->getBatch();
        $select = $this->db->select();

        $select->from('gems__rounds', array(
            'gro_id_order', 'gro_id_relationfield', 'gro_round_description', 'gro_icon_file',
            'gro_changed_event', 'gro_display_event',
            'gro_valid_after_source', 'gro_valid_after_field', 'gro_valid_after_unit', 'gro_valid_after_length',
            'gro_valid_for_source', 'gro_valid_for_field', 'gro_valid_for_unit', 'gro_valid_for_length',
            'gro_organizations', 'gro_code', 'gro_condition'
            ))  ->joinInner('gems__surveys', 'gems__rounds.gro_id_survey = gsu_id_survey', array(
                'survey_export_code' => 'gsu_export_code',
                )) // gro_id_survey
                ->joinLeft('gems__rounds AS va', 'gems__rounds.gro_valid_after_id = va.gro_id_round', array(
                    'valid_after' => 'va.gro_id_order',
                    )) // gro_valid_after_id
                ->joinLeft('gems__rounds AS vf', 'gems__rounds.gro_valid_for_id = vf.gro_id_round', array(
                     'valid_for' => 'vf.gro_id_order',
                    )) // gro_valid_for_id
                ->where('gems__rounds.gro_id_round = ?', $roundId);
        // \MUtil_Echo::track($select->__toString(), $roundId);

        $data = $this->db->fetchRow($select);
        // \MUtil_Echo::track($data);

        if ($data) {
            $fields = $this->loader->getTracker()->getTrackEngine($trackId)->getFieldsDefinition();
            $tests  = array(
                \Gems_Tracker_Engine_StepEngineAbstract::APPOINTMENT_TABLE,
                \Gems_Tracker_Engine_StepEngineAbstract::RESPONDENT_TRACK_TABLE,
                );
            if (isset($data['gro_id_relationfield']) && $data['gro_id_relationfield']) {
                // -1 means the respondent itself, also gro_id_relationfield stores a "bare"
                // field id, not one with a table prefix
                if ($data['gro_id_relationfield'] >= 0) {
                    $data['gro_id_relationfield'] = $this->translateFieldCode(
                            $fields,
                            FieldsDefinition::makeKey(FieldMaintenanceModel::FIELDS_NAME, $data['gro_id_relationfield'])
                            );
                }
            }

            if (isset($data['gro_valid_after_source'], $data['gro_valid_after_field']) &&
                    in_array($data['gro_valid_after_source'], $tests)) {
                // Translate field to {order}
                $data['gro_valid_after_field'] = $this->translateFieldCode($fields, $data['gro_valid_after_field']);
            }
            if (isset($data['gro_valid_for_source'], $data['gro_valid_for_field']) &&
                    in_array($data['gro_valid_for_source'], $tests)) {
                // Translate field to {order}
                $data['gro_valid_for_field'] = $this->translateFieldCode($fields, $data['gro_valid_for_field']);
            }

            $count = $batch->addToCounter('rounds_exported');

            if ($count == 1) {
                $this->exportTypeHeader('rounds');
                $this->exportFieldHeaders($data);
            }
            $this->exportFieldData($data);
            $this->exportFlush();

            $batch->setMessage('rounds_export', sprintf(
                    $this->plural('%d round exported', '%d rounds exported', $count),
                    $count
                    ));
        }
    }
1306348
public function requestLookupToken($token, $requestId = '0')
    {

        $endPoint = str_replace('{token}', $token, self::ENDPOINT_LOOKUP_TOKEN);

        // Add request_id on end point url
        $endPoint .= '?request_id=' . $requestId;

        $response = $this->getClientProvider()
                         ->request(self::METHOD_LOOKUP_TOKEN, $endPoint, array(), true);

        $pctMapper = new PaymentCardTokenMapper($response->toArray());

        return $pctMapper->getModelObjectMapped();
    }
402171
public function verify($token, $messageId = null)
    {
        $messageId = ($messageId !== null) ? $messageId : $this->messageId;

        // Throw error for empty token or empty message id, because the server will not handle this
        if (empty($token)) {
            throw new Verification\EmptyTokenException();
        }
        if (empty($messageId)) {
            throw new Verification\EmptyMessageIdException();
        }

        try {
            $this->sendApiCall(self::ACTION_RETRIEVE, sprintf('%s/%s?token=%s', $this->getCreateUrl(), urlencode($messageId), $token));
        } catch (Exception $e) {
            if (Verification\Exception::isVerificationException($e)) {
                throw new Verification\Exception($e);
            } else {
                throw $e;
            }
        }
    }
241845
protected function _token($token = null)
    {
        if ($token) {
            return $token;
        }

        $token = $this->_request()->data('token');
        if ($token) {
            return $token;
        }

        $token = $this->_request()->param('token');
        if ($token) {
            return $token;
        }

        return $this->_request()->query('token');
    }
803823
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 (! $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();
        }
    }
310693
public function getNextRoundId($roundId)
    {
       $this->_ensureRounds();

       if ($this->_rounds && $roundId) {
           $next = false;
           foreach ($this->_rounds as $currentRoundId => $round) {
               if ($next) {
                   return $currentRoundId;
               }
               if ($currentRoundId == $roundId) {
                   $next = true;
               }
           }

           return null;

       } elseif ($this->_rounds) {
           end($this->_rounds);
           return key($this->_rounds);
       }
    }
1057495
public function mintFedoraUrl(
        $uuid,
        $token = null
    ) {
        $headers = ['Content-Type' => 'text/plain'];

        if (!empty($token)) {
            $headers['Authorization'] = $token;
        }

        $response = $this->client->post('', [
            'body' => $uuid,
            'headers' => $headers,
        ]);

        $this->log->debug("Gemini POST response", [
            'uuid' => $uuid,
            'response' => $response,
        ]);

        return (string)$response->getBody();
    }
209470
public function getToken()
    {
        static $token;

        if ($token instanceof \Gems_Tracker_Token) {
            return $token;
        }

        $token   = null;
        $tokenId = $this->getTokenId();

        if ($tokenId) {
            $token = $this->loader->getTracker()->getToken($tokenId);
        }
        if ($token && $token->exists) {
            // Set variables for the menu
            $token->applyToMenuSource($this->menu->getParameterSource());

            return $token;
        }

        throw new \Gems_Exception($this->_('No existing token specified!'));
    }
516868
public function getStartTime(\Gems_Tracker_Token $token)
    {
        $source = $this->getSource();
        return $source->getStartTime($token, $this->_surveyId, $this->_gemsSurvey['gsu_surveyor_id']);
    }
973660
public function getRoundCode($roundId)
    {
        $this->_ensureRounds();
        $roundCode = null;

        if (array_key_exists($roundId, $this->_rounds) && array_key_exists('gro_code', $this->_rounds[$roundId])) {
            $roundCode = $this->_rounds[$roundId]['gro_code'];
        }

        return $roundCode;
    }
583086
public function verifyToken(Token $token)
    {
        $alg = $token->getHeader('alg');

        if (empty($this->supportedAlgs[$alg])) {
            throw new InvalidParamException('Algorithm not supported');
        }

        $signer = Yii::createObject($this->supportedAlgs[$alg]);
        return $token->verify($signer, $this->key);
    }
385589
public function getAnswerDisplaySnippets(\Gems_Tracker_Token $token)
    {
        $snippets = parent::getAnswerDisplaySnippets($token);
        if (!is_array($snippets)) {
        	$snippets = array($snippets);
        }
        // Add the ScoreChartsSnippet
        $snippets[] = 'Survey_Display_ScoreChartsSnippet';
        return $snippets;
    }