Checks whether the token is in the source.

@param \Gems_Tracker_Token $token Gems token object
@param int $surveyId Gems Survey Id
@param string $sourceSurveyId Optional Survey Id used by source
@return boolean
516174
public function inSource(\Gems_Tracker_Token $token, $surveyId, $sourceSurveyId = null)
    {
        $tokenInfo = $this->getTokenInfo($token, $surveyId, $sourceSurveyId);
        return (boolean) $tokenInfo;
    }
640347
public function verifyToken($messageId, $token)
    {
        try {
            $verification = $this->getTokenResult($messageId, $token);

            return ($verification->getStatusCode() === Verification::STATUS_SUCCESS);
        } catch (Exception $e) {
            return false;
        }
    }
776779
public function getSurveyName($surveyId) {
        $tracker = $this->loader->getTracker();
        $survey  = $tracker->getSurvey($surveyId);

        return $survey->getName();
    }
1106844
protected function _checkReturnURI($sourceSurveyId, \Gems_Tracker_Survey $survey, array &$messages)
    {
        $lsSurvLang = $this->_getSurveyLanguagesTableName();
        $sql = 'SELECT surveyls_language FROM ' . $lsSurvLang . ' WHERE surveyls_survey_id = ?';

        $lsDb = $this->getSourceDatabase();

        $languages = $lsDb->fetchAll($sql, array($sourceSurveyId));
        $langChanges = 0;
        foreach ($languages as $language)
        {
            $langChanges = $langChanges + $lsDb->update(
                $lsSurvLang,
                array(
                    'surveyls_urldescription' => $this->_getReturnURIDescription($language['surveyls_language'])
                    ),
                array(
                    'surveyls_survey_id = ?' => $sourceSurveyId,
                    'surveyls_language = ?'  => $language
                    )
                );
        }

        if ($langChanges > 0) {
            $messages[] = sprintf($this->_('The description of the exit url description was changed for %s languages in survey \'%s\'.'), $langChanges, $survey->getName());
        }
    }
108163
public function getAnswerDateTime($fieldName, \Gems_Tracker_Token $token)
    {
        $source = $this->getSource();
        return $source->getAnswerDateTime($fieldName, $token, $this->_surveyId, $this->_gemsSurvey['gsu_surveyor_id']);
    }
476757
function getSurveys (defOptions, credentials, token, surveyId, callback) {
  var options;
  
  surveyId = surveyId || '';
  
  if (typeof surveyId === 'function') {
    callback = surveyId;
    surveyId = '';
  }
  
  options = {
    method : 'GET',
    uri : `v1/Surveys/${surveyId}`,
  };
  
  return requestWithTokenCheck(defOptions, credentials, token, options, callback);
}
507808
public function checkRegistryRequestsAnswers()
    {
        if ($this->db && (! $this->_gemsSurvey)) {
            $result = $this->db->fetchRow("SELECT * FROM gems__surveys WHERE gsu_id_survey = ?", $this->_surveyId);
            if ($result) {
                $this->_gemsSurvey = $result;
                $this->exists = true;
            } else {
                //Row not present, try with empty array? or should we throw an error?
                $this->_gemsSurvey = array(
                    'gsu_code'             => null,
                    'gsu_valid_for_length' => 6,
                    'gsu_valid_for_unit'   => 'M',
                    );
                $this->exists = false;
            }
        }

        return (boolean) $this->_gemsSurvey;
    }
937185
protected function _isTokenInFilter(\Gems_Tracker_Token $token)
    {
        $result = false;

        // Only if token has a success code
        if ($token->getReceptionCode()->isSuccess()) {
            $result = true;
        }

        if ($result) {
            $tokenInfo = array(
                'code'     => $token->getSurvey()->getCode(),
                'surveyid' => $token->getSurveyId(),
                'tokenid'  => $token->getTokenId()
            );

            // Now check if the tokenfilter is true
            if (empty($this->tokenFilter)) {
                $result = true;
            } else {
                $result = false;
                // Now read the filter and split by track code or track id
                foreach ($this->tokenFilter as $filter)
                {
                    $remaining = array_diff_assoc($filter, $tokenInfo);
                    if (empty($remaining)) {
                        $result = true;
                        break;
                    }
                }
            }
        }

        return $result;
    }
418779
public function getAnswerDisplaySnippets(\Gems_Tracker_Token $token)
    {
        $this->token = $token;

        $snippets = (array) $token->getTrackEngine()->getAnswerSnippetNames();

        $snippets['answerFilter'] = $this;

        return $snippets;
    }
296090
public function verifyToken($token, $userId)
	{
		$user = $this->repository->get($userId);
		$now = new DateTime();

		if ($user) {
			$dateDiff = $now->diff($user->reset_password_requested_at);

			$totalHours = ($dateDiff->d * 24) + $dateDiff->h;

			// remove token older than 2h
			if ($totalHours > 2) {
				$update = [
					'reset_password_requested_at' => NULL,
					'reset_password_token' => NULL,
				];
				$this->repository->update($userId, $update);

				return FALSE;
			}

			if (Passwords::verify($token, $user->reset_password_token)) {
				$update = [
					'reset_password_requested_at' => NULL,
					'reset_password_token' => NULL,
				];
				$this->repository->update($userId, $update);

				return TRUE;
			}
		}

		return FALSE;
	}
939684
public function execute($tokenData = null, $userId = null)
    {
        $batch   = $this->getBatch();
        $tracker = $this->loader->getTracker();

        $batch->addToCounter('checkedTokens');
        $token = $tracker->getToken($tokenData);

        $wasAnswered = $token->isCompleted();

        if ($result = $token->checkTokenCompletion($userId)) {
            if ($result & \Gems_Tracker_Token::COMPLETION_DATACHANGE) {
                $i = $batch->addToCounter('resultDataChanges');
                $batch->setMessage('resultDataChanges', sprintf(
                        $this->_('Results and timing changed for %d tokens.'),
                        $i
                        ));

                if ($wasAnswered) {
                    $action  = 'token.data-changed';
                    $message = sprintf($this->_("Token '%s' data has changed."), $token->getTokenId());
                } else {
                    $action  = 'token.answered';
                    $message = sprintf($this->_("Token '%s' was answered."), $token->getTokenId());
                }
                if (! $this->request instanceof \Zend_Controller_Request_Abstract) {
                    $this->request = \Zend_Controller_Front::getInstance()->getRequest();
                }
                $this->accesslog->logEntry(
                        $this->request,
                        $action,
                        true,
                        $message,
                        $token->getArrayCopy(),
                        $token->getRespondentId()
                        );

            }
            if ($result & \Gems_Tracker_Token::COMPLETION_EVENTCHANGE) {
                $i = $batch->addToCounter('surveyCompletionChanges');
                $batch->setMessage('surveyCompletionChanges', sprintf(
                        $this->_('Answers changed by survey completion event for %d tokens.'),
                        $i
                        ));
            }
        }

        if ($token->isCompleted()) {
            $batch->setTask('Tracker_ProcessTokenCompletion', 'tokproc-' . $token->getTokenId(), $tokenData, $userId);
        }

        $batch->setMessage('checkedTokens', sprintf(
                $this->_('Checked %d tokens.'),
                $batch->getCounter('checkedTokens')
                ));

        // Free memory
        $tracker->removeToken($token);
    }
710852
public function checkSourceActive($userId)
    {
        // The only method to check if it is active is by getting all the tables,
        // since the surveys table may be empty so we just check for existence.
        $sourceDb  = $this->getSourceDatabase();
        $tables    = array_map('strtolower', $sourceDb->listTables());
        $tableName = $this->addDatabasePrefix(self::SURVEYS_TABLE, false); // Get name without database prefix.

        $active = strtolower(in_array($tableName, $tables));

        $values['gso_active'] = $active ? 1 : 0;
        $values['gso_status'] = $active ? 'Active' : 'Inactive';

        $this->_updateSource($values, $userId);

        return $active;
    }
1319914
public function processTokenInsertion(\Gems_Tracker_Token $token)
    {
        if ($token->hasSuccesCode() && (! $token->isCompleted())) {
            // Preparation for a more general object class
            $code = $token->getSurvey()->getCode();

            $prev = $token;
            while ($prev = $prev->getPreviousToken()) {

                if ($prev->hasSuccesCode() && $prev->isCompleted()) {
                    // Check first on survey id and when that does not work by name.
                    if ($prev->getSurvey()->getCode() == $code) {
                        return $prev->getRawAnswers();
                    }
                }
            }
        }
    }
437419
public function getRawTokenAnswerRowsSelect(array $filter, $surveyId, $sourceSurveyId = null)
    {
        $survey = $this->getSurvey($surveyId, $sourceSurveyId);
        $model  = $survey->getModel();

        $select = $model->getSelect();
        $this->filterLimitOffset($filter, $select);

        return $select;
    }
416339
public function getQuestionList($language, $surveyId, $sourceSurveyId = null)
    {
        $survey = $this->getSurvey($surveyId, $sourceSurveyId);
        $model  = $survey->getModel();
        $result = [];

        foreach($model->getItemsOrdered() as $name) {
            if ($label = $model->get($name, 'label')) {
                $result[$name] = $label;
            }
        }

        if ($model->getMeta('nested', false)) {
            foreach ($model->getMeta('nestedNames') as $name) {
                // We have a nested model, add the nested questions
                $nestedModel = $model->get($name, 'model');
                foreach($nestedModel->getItemsOrdered() as $name) {
                    if ($label = $nestedModel->get($name, 'label')) {
                        $result[$name] = $label;
                    }
                }
            }
        }

        return $result;
    }
1205680
public function execute($sourceId = null, $sourceSurveyId = null, $surveyId = null)
    {
        $batch = $this->getBatch();

        if ($surveyId) {
            $survey = $this->loader->getTracker()->getSurvey($surveyId);
        } else {
            $survey = $this->loader->getTracker()->getSurveyBySourceId($sourceSurveyId, $sourceId);
        }

        if (! $survey->isActive()) {
            return;
        }

        // Now save the questions
        $answerModel = $survey->getAnswerModel('en');
        
        $hash = $survey->calculateHash();
        
        if ($survey->getHash() === $hash) {
            return;
        }
        
        $survey->setHash($hash, $this->loader->getCurrentUser()->getUserId());

        foreach ($answerModel->getItemsOrdered() as $order => $name) {
            if (true === $answerModel->get($name, 'survey_question')) {
                $batch->addTask('Tracker_RefreshQuestion', $surveyId, $name, $order);
            }
        }

        // If we have a response database, create a view on the answers
        if ($this->project->hasResponseDatabase()) {
            $this->replaceCreateView($survey, $answerModel);
        }
    }
887718
public function getSurveyData($surveyId) {
        $tracker = $this->loader->getTracker();

        $survey = $tracker->getSurvey($surveyId);

        $surveyInfo = $survey->getQuestionInformation($this->locale);

        $filteredSurveyInfo = $surveyInfo;
        foreach ($surveyInfo as $questionCode => $questionInfo) {
            if ($questionInfo['class'] == 'question_sub') {
                $parentCode                                           = $questionInfo['title'];
                $parent                                               = $surveyInfo[$parentCode];
                $filteredSurveyInfo[$questionCode]['question'] = $parent['question'] . ' | ' . $questionInfo['question'];
                if (isset($filteredSurveyInfo[$parentCode])) {
                    unset($filteredSurveyInfo[$parentCode]);
                }
            }
        }

        return $filteredSurveyInfo;
    }