/** * Seperate the incorrect tokens from the right tokens * * @param mixed $value * @return boolean */ protected function isValidToken($value) { // Make sure the value has the right format $value = $this->tracker->filterToken($value); $library = $this->tracker->getTokenLibrary(); $format = $library->getFormat(); $reuse = $library->hasReuse() ? $library->getReuse() : -1; if (strlen($value) !== strlen($format)) { $this->_messages = sprintf($this->translate->_('Not a valid token. The format for valid tokens is: %s.'), $format); return false; } $token = $this->tracker->getToken($value); if ($token && $token->exists) { $currentDate = new \MUtil_Date(); if ($completionTime = $token->getCompletionTime()) { // Reuse means a user can use an old token to check for new surveys if ($reuse >= 0) { // Oldest date AFTER completiondate. Oldest date is today minus reuse time if ($completionTime->diffDays($currentDate) <= $reuse) { // It is completed and may still be used to look // up other valid tokens. return true; } } $this->_messages = $this->translate->_('This token is no longer valid.'); return false; } $fromDate = $token->getValidFrom(); if (null === $fromDate || $currentDate->isEarlier($fromDate)) { // Current date is BEFORE from date $this->_messages = $this->translate->_('This token cannot (yet) be used.'); return false; } if ($untilDate = $token->getValidUntil()) { if ($currentDate->isLater($untilDate)) { //Current date is AFTER until date $this->_messages = $this->translate->_('This token is no longer valid.'); return false; } } return true; } else { $this->_messages = $this->translate->_('Unknown token.'); return false; } }
public function testGetFieldCodes() { $expected = array('f__1' => 'code', 'f__2' => 'datecode'); $this->assertEquals($expected, $this->tracker->getTrackEngine(1)->getFieldCodes()); }
/** * 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->multiTracks) { return false; } $this->tracker = $this->loader->getTracker(); if (!$this->respondentTrackId) { $this->respondentTrackId = $this->request->getParam(\Gems_Model::RESPONDENT_TRACK); } if ($this->respondentTrackId) { if (!$this->respondentTrack instanceof \Gems_Tracker_RespondentTrack) { $this->respondentTrack = $this->tracker->getRespondentTrack($this->respondentTrackId); } } if ($this->respondentTrack instanceof \Gems_Tracker_RespondentTrack) { if (!$this->respondentTrackId) { $this->respondentTrackId = $this->respondentTrack->getRespondentTrackId(); } $this->trackId = $this->respondentTrack->getTrackId(); if (!$this->respondentId) { $this->respondentId = $this->respondentTrack->getRespondentId(); } if (!$this->organizationId) { $this->organizationId = $this->respondentTrack->getOrganizationId(); } $this->caption = $this->_('Other assignments of this track to this respondent.'); $this->onEmpty = $this->_('This track is assigned only once to this respondent.'); } else { if ($this->respondent instanceof \Gems_Tracker_Respondent) { if (!$this->respondentId) { $this->respondentId = $this->respondent->getId(); } if (!$this->organizationId) { $this->organizationId = $this->respondent->getOrganizationId(); } } $this->caption = $this->_('Existing assignments of this track to this respondent.'); $this->onEmpty = $this->_('This track is not assigned to this respondent.'); } if (!$this->trackId) { $this->trackId = $this->request->getParam(\Gems_Model::TRACK_ID); } if (!$this->trackId && $this->trackEngine instanceof \Gems_Tracker_Engine_TrackEngineInterface) { $this->trackId = $this->trackEngine->getTrackId(); } return $this->trackId && $this->respondentId && $this->organizationId && parent::hasHtmlOutput(); }