/** * Common handler utility to initialize tokens from parameters * * @return boolean True if there is a real token specified in the request */ protected function _initToken() { if ($this->tracker) { return $this->token && $this->token->exists; } $this->tracker = $this->loader->getTracker(); $this->tokenId = $this->tracker->filterToken($this->_getParam(\MUtil_Model::REQUEST_ID)); if (!$this->tokenId) { return false; } $this->token = $this->tracker->getToken($this->tokenId); if (!$this->token->exists) { return false; } if (!($this->currentUser->isActive() || $this->token->getSurvey()->isTakenByStaff())) { $tokenLang = strtolower($this->token->getRespondentLanguage()); // \MUtil_Echo::track($tokenLang, $this->locale->getLanguage()); if ($tokenLang != $this->locale->getLanguage()) { $this->locale->setLocale($tokenLang); $this->translateAdapter->setLocale($this->locale); $this->currentUser->setLocale($tokenLang); \Gems_Cookies::setLocale($tokenLang, $this->basepath->getBasePath()); } $currentOrg = $this->loader->getOrganization(); $tokenOrgId = $this->token->getOrganizationId(); if ($tokenOrgId != $currentOrg->getId()) { $this->loader->getOrganization($tokenOrgId)->setAsCurrentOrganization(); } } return true; }
/** * Returns the previous token in this track * * @return \Gems_Tracker_Token */ public function getPreviousToken() { if (null === $this->_previousToken) { $tokenSelect = $this->tracker->getTokenSelect(); $tokenSelect->andReceptionCodes()->forNextTokenId($this->_tokenId); if ($tokenData = $tokenSelect->fetchRow()) { $this->_previousToken = $this->tracker->getToken($tokenData); $this->_previousToken->_nextToken = $this; } else { $this->_previousToken = false; } } return $this->_previousToken; }
/** * * @param mixed $token * @param int $userId The current user * @return int The number of tokens changed by this event */ public function handleRoundCompletion($token, $userId) { if (!$token instanceof \Gems_Tracker_Token) { $token = $this->tracker->getToken($token); } // \MUtil_Echo::track($token->getRawAnswers()); // Store the current token as startpoint if it is the first changed token if ($this->_checkStart) { if ($this->_checkStart->getRoundId() > $token->getRoundId()) { // Replace current token $this->_checkStart = $token; } } else { $this->_checkStart = $token; } // Process any events if ($event = $this->getTrackEngine()->getRoundChangedEvent($token->getRoundId())) { return $event->processChangedRound($token, $this, $userId); } return 0; }
/** * This tests if the public property exists is set correctly * * @dataProvider providerTokenData */ public function testTokenExists($tokenData, $exists) { $token = $this->tracker->getToken($tokenData); $this->assertEquals($exists, $token->exists); }