*/ namespace oat\taoProctoring\model\execution; use oat\generis\model\OntologyAwareTrait; use oat\taoDelivery\model\execution\ServiceProxy; use oat\taoProctoring\model\authorization\TestTakerAuthorizationService; use oat\taoQtiTest\models\SectionPauseService; use oat\taoQtiTest\models\runner\session\TestSession; use qtism\data\AssessmentItemRef; use qtism\runtime\tests\AssessmentTestSessionState; class ProctoredSectionPauseService extends SectionPauseService { use OntologyAwareTrait; /** * This category triggers the section pause */ const PAUSE_CATEGORY = 'x-tao-proctored-auto-pause'; private $isProctored = null; /** * Checked the given session could be paused at some point * (in other words : is section pause enabled) * @param $session * @return bool */ public function couldBePaused(TestSession $session = null) { return ($session->getState() === AssessmentTestSessionState::INTERACTING && $this->isProctored($session)); } /** * Checked that section can be paused * @param TestSession $session * @return bool */ public function isPausable(TestSession $session = null) { if ($this->couldBePaused($session)) { /** @var AssessmentItemRef $itemRef */ $itemRef = $session->getCurrentAssessmentItemRef(); return $this->isItemPausable($itemRef); } return false; } /** * Check if we can move backward : when leaving a pausable section, * we can't move backward. * * @param TestSession $session * @return bool */ public function canMoveBackward(TestSession $session = null) { if ($this->couldBePaused($session)) { return ! $this->isItemPausable($session->getCurrentAssessmentItemRef()); } return true; } /** * Is the given section proctored * * @param TestSession $session * @return bool false by default */ private function isProctored(TestSession $session) { //check only once if (is_null($this->isProctored)) { $this->isProctored = false; if (!is_null($session)) { $user = \common_session_SessionManager::getSession()->getUser(); $deliveryExecution = ServiceProxy::singleton()->getDeliveryExecution($session->getSessionId()); $this->isProctored = $this->getServiceManager()->get(TestTakerAuthorizationService::SERVICE_ID)->isProctored($deliveryExecution->getDelivery(), $user); } } return $this->isProctored; } /** * Is the given itemRef pauseable (ie. has the given category) * * @param AssessmentItemRef $itemRef * @return bool false by default */ private function isItemPausable(AssessmentItemRef $itemRef) { if (!is_null($itemRef)) { return $itemRef->getCategories()->contains(self::PAUSE_CATEGORY); } return false; } }