/** * Indicate that the candidate is ending its candidate session. * * In other words, the candidate makes the item session * go from the INTERACTING mode to the SUSPENDED mode, without ending the attempt. The attempt can be resumed by a * call to the beginCandidateSession() method. * * @throws AssessmentItemSessionException If a state violation occurs. */ public function endCandidateSession() { $state = $this->getState(); if ($state !== AssessmentItemSessionState::INTERACTING) { $msg = "Cannot switch from state " . strtoupper(AssessmentItemSessionState::getNameByConstant($state)) . " to state SUSPENDED."; $code = AssessmentItemSessionException::STATE_VIOLATION; throw new AssessmentItemSessionException($msg, $this, $code); } else { $this->endAttempt(null, false); $this->setState(AssessmentItemSessionState::SUSPENDED); } }
/** * Set the item session in INTERACTING state. * * @throws AssessmentItemSessionException With code STATE_VIOLATION if the state of the session is not INITIAL nor SUSPENDED nor MODAL_FEEDBACK nor INTERACTING. */ public function interact() { $state = $this->getState(); if ($state !== AssessmentItemSessionState::INTERACTING) { if ($state !== AssessmentItemSessionState::INITIAL && $state !== AssessmentItemSessionState::SUSPENDED && $state !== AssessmentItemSessionState::MODAL_FEEDBACK) { $msg = "Cannot switch from state '" . AssessmentItemSessionState::getNameByConstant($state) . "' to state 'interacting'."; $code = AssessmentItemSessionException::STATE_VIOLATION; throw new AssessmentItemSessionException($msg, $this, $code); } $this->setState(AssessmentItemSessionState::INTERACTING); // Reset the time reference. If not, the time spent in SUSPENDED mode will be taken into account! $this->setTimeReference(new DateTime('now', new DateTimeZone('UTC'))); } }