/** * Make the candidate interact with the current Assessment Item to be presented. A new attempt * will begin automatically if the candidate still has available attempts. Otherwise, * nothing happends. * * @param AssessmentTestSession $session The AssessmentTestSession you want to make the candidate interact with. */ public static function beginCandidateInteraction(AssessmentTestSession $session) { $itemSession = $session->getCurrentAssessmentItemSession(); $itemSessionState = $itemSession->getState(); $initial = $itemSessionState === AssessmentItemSessionState::INITIAL; $suspended = $itemSessionState === AssessmentItemSessionState::SUSPENDED; $remainingAttempts = $itemSession->getRemainingAttempts(); $attemptable = $remainingAttempts === -1 || $remainingAttempts > 0; if ($initial === true || $suspended === true && $attemptable === true) { // Begin the very first attempt. $session->beginAttempt(); } // Otherwise, the item is not attemptable bt the candidate. }
/** * Set time reference of current assessment item session to <i>now</i> instead of time of last update. * This ensures that time when delivery execution was paused will not be taken in account. * Make sure that method invoked right after retrieving assessment test session * and before the first AssessmentTestSession::updateDuration method call * @param AssessmentTestSession $session * @param \DateTime|null $time Time to be specified. Current time by default. Make sure that $time has UTC timezone. */ public function updateTimeReference(AssessmentTestSession $session, \DateTime $time = null) { if ($time === null) { $time = new \DateTime('now', new \DateTimeZone('UTC')); } $itemSession = $session->getCurrentAssessmentItemSession(); if ($itemSession) { $itemSession->setTimeReference($time); $session->updateDuration(); } }