Persist an AssessmentTestSession into persistent binary data.

@param \qtism\runtime\tests\AssessmentTestSession $assessmentTestSession
@throws \qtism\runtime\storage\common\StorageException
544241
public function persist(AssessmentTestSession $assessmentTestSession)
    {
        try {

            $stream = new MemoryStream();
            $stream->open();
            $access = $this->createBinaryStreamAccess($stream);

            // -- Deal with intrinsic values of the Test Session.
            $access->writeTinyInt($assessmentTestSession->getState());

            // Write the current position in the route.
            $route = $assessmentTestSession->getRoute();
            $access->writeTinyInt($route->getPosition());

            // persist time reference.
            $timeReference = $assessmentTestSession->getTimeReference();
            if (is_null($timeReference) === true) {
                $access->writeBoolean(false);
            } else {
                $access->writeBoolean(true);
                $access->writeDateTime($timeReference);
            }
            
            // persist visited testPart identifiers.
            $visitedTestPartIdentifiers = $assessmentTestSession->getVisitedTestPartIdentifiers();
            $access->writeTinyInt(count($visitedTestPartIdentifiers));
            foreach ($visitedTestPartIdentifiers as $visitedTestPartIdentifier) {
                $access->writeString($visitedTestPartIdentifier);
            }
            
            // persist path.
            $access->writePath($assessmentTestSession->getPath());
            
            // -- Persist configuration
            $access->writeShort($assessmentTestSession->getConfig());

            // -- Persist the Route of the AssessmentTestSession and the related item sessions.
            $access->writeTinyInt($route->count());
            $itemSessionStore = $assessmentTestSession->getAssessmentItemSessionStore();
            $pendingResponseStore = $assessmentTestSession->getPendingResponseStore();
            $oldRoutePosition = $route->getPosition();

            $seeker = $this->getSeeker();

            foreach ($route as $routeItem) {
                $item = $routeItem->getAssessmentItemRef();
                $occurence = $routeItem->getOccurence();

                // Deal with RouteItem
                $access->writeRouteItem($seeker, $routeItem);

                // Deal with ItemSession related to the previously written RouteItem.
                try {
                    $itemSession = $itemSessionStore->getAssessmentItemSession($item, $occurence);
                    $access->writeBoolean(true);
                    $access->writeAssessmentItemSession($seeker, $itemSession);
                    
                    // Deal with last occurence update.
                    $access->writeBoolean($assessmentTestSession->isLastOccurenceUpdate($item, $occurence));
                    
                    // Deal with PendingResponses
                    if (($pendingResponses = $pendingResponseStore->getPendingResponses($item, $occurence)) !== false) {
                        $access->writeBoolean(true);
                        $access->writePendingResponses($seeker, $pendingResponses);
                    } else {
                        $access->writeBoolean(false);
                    }
                }
                catch (OutOfBoundsException $e) {
                    $access->writeBoolean(false);
                    // No assessmentItemSession for this route item.
                    continue;
                }
            }
            
            $route->setPosition($oldRoutePosition);

            // Persist the test-level global scope.
            foreach ($assessmentTestSession->getKeys() as $outcomeIdentifier) {
                $outcomeVariable = $assessmentTestSession->getVariable($outcomeIdentifier);
                $access->writeVariableValue($outcomeVariable);
            }

            $durationStore = $assessmentTestSession->getDurationStore();
            $access->writeShort(count($durationStore));
            foreach ($durationStore->getKeys() as $k) {
                $access->writeString($k);
                $access->writeVariableValue($durationStore->getVariable($k));
            }

            $this->persistStream($assessmentTestSession, $stream);

            $stream->close();
        } catch (Exception $e) {
            $sessionId = $assessmentTestSession->getSessionId();
            $msg = "An error occured while persisting AssessmentTestSession with ID '${sessionId}': " . $e->getMessage();
            throw new StorageException($msg, StorageException::PERSISTENCE, $e);
        }
    }
310432
public function addFailure(Test $test, AssertionFailedError $error, float $time): void
    {
        $this->writeCase(
            self::STATUS_FAIL,
            $time,
            $this->getStackTrace($error),
            TestFailure::exceptionToString($error),
            $test
        );

        $this->currentTestPass = false;
    }
790028
public function assessmentActivity()
    {
        $service = $this->getServiceLocator()->get(ActivityMonitoringService::SERVICE_ID);

        // Reason categories
        $this->setData('reason_categories', DeliveryHelper::getAllReasonsCategories());

        // Config
        $config = [ActivityMonitoringService::OPTION_USER_ACTIVITY_WIDGETS =>
            $service->getOption(ActivityMonitoringService::OPTION_USER_ACTIVITY_WIDGETS),
            ActivityMonitoringService::OPTION_ASSESSMENT_ACTIVITY_AUTO_REFRESH =>
                $service->getOption(ActivityMonitoringService::OPTION_ASSESSMENT_ACTIVITY_AUTO_REFRESH),
            ActivityMonitoringService::OPTION_COMPLETED_ASSESSMENTS_AUTO_REFRESH =>
                $service->getOption(ActivityMonitoringService::OPTION_COMPLETED_ASSESSMENTS_AUTO_REFRESH),
        ];
        $this->setData('config', $config);

        $this->setView('Tools/assessment_activity.tpl');
    }
1129972
public void setAssessmentTargets(java.util.Collection<AssessmentTarget> assessmentTargets) {
        if (assessmentTargets == null) {
            this.assessmentTargets = null;
            return;
        }

        this.assessmentTargets = new java.util.ArrayList<AssessmentTarget>(assessmentTargets);
    }
338312
public function saveAuthAssignment($assignment)
	{
		$this->db->createCommand()
			->update($this->assignmentTable, array(
				'bizrule'=>$assignment->getBizRule(),
				'data'=>serialize($assignment->getData()),
			), 'itemname=:itemname AND userid=:userid', array(
				'itemname'=>$assignment->getItemName(),
				'userid'=>$assignment->getUserId()
			));
	}
88079
public function getTimeLimits($testSession)
    {
        $seconds = null;

        if ($item = $testSession->getCurrentAssessmentItemRef()) {
            $seconds = $this->getPartTimeLimits($item);
        }

        if (!$seconds && $section = $testSession->getCurrentAssessmentSection()) {
            $seconds = $this->getPartTimeLimits($section);
        }

        if (!$seconds && $testPart = $testSession->getCurrentTestPart()) {
            $seconds = $this->getPartTimeLimits($testPart);
        }

        if (!$seconds && $assessmentTest = $testSession->getAssessmentTest()) {
            $seconds = $this->getPartTimeLimits($assessmentTest);
        }

        return $seconds;
    }
1136883
public static function get_assessment($assessmentid) {
        global $DB, $PAGE;

        $params = self::validate_parameters(self::get_assessment_parameters(), array('assessmentid' => $assessmentid));
        $warnings = array();

        // Get and validate the assessment, submission and workshop.
        $assessment = $DB->get_record('workshop_assessments', array('id' => $params['assessmentid']), '*', MUST_EXIST);
        $submission = $DB->get_record('workshop_submissions', array('id' => $assessment->submissionid), '*', MUST_EXIST);
        list($workshop, $course, $cm, $context) = self::validate_workshop($submission->workshopid);

        // Check that we can get the assessment.
        $workshop->check_view_assessment($assessment, $submission);

        $assessment = $workshop->get_assessment_by_id($assessment->id);
        $assessment = self::prepare_assessment_for_external($assessment, $workshop);
        if (empty($assessment)) {
            throw new moodle_exception('nopermissions', 'error', '', 'view assessment');
        }
        $related = array('context' => $context);
        $exporter = new assessment_exporter($assessment, $related);

        return array(
            'assessment' => $exporter->export($PAGE->get_renderer('core')),
            'warnings' => $warnings
        );
    }
336891
protected function prepare_data_from_recordset($assessments) {
        $data = array();    // to be returned
        foreach ($assessments as $a) {
            $id = $a->assessmentid; // just an abbreviation
            if (!isset($data[$id])) {
                $data[$id] = new stdclass();
                $data[$id]->assessmentid = $a->assessmentid;
                $data[$id]->weight       = $a->assessmentweight;
                $data[$id]->reviewerid   = $a->reviewerid;
                $data[$id]->gradinggrade = $a->gradinggrade;
                $data[$id]->submissionid = $a->submissionid;
                $data[$id]->dimgrades    = array();
            }
            $data[$id]->dimgrades[$a->dimensionid] = $a->grade;
        }
        return $data;
    }
691584
public function _after(\Codeception\TestInterface $test)
    {
        foreach ($this->permanentServices as $serviceName => $service) {
            $this->permanentServices[$serviceName] = $this->grabService($serviceName);
        }
        parent::_after($test);
    }
528135
public function check(RunnerServiceContext $context)
    {
        parent::check($context);

        $state = $context->getTestSession()->getState();

        if ($state == AssessmentTestSessionState::SUSPENDED) {
            throw new QtiRunnerPausedException();
        }

        return true;
    }
806795
public function initResultServer($compiledDelivery, $executionIdentifier, $userUri)
    {
        $storage = $this->getResultStorage($compiledDelivery);
        //$storage->spawnResult($executionIdentifier);

        //link test taker identifier with results
        $storage->storeRelatedTestTaker($executionIdentifier, $userUri);

        //link delivery identifier with results
        $storage->storeRelatedDelivery($executionIdentifier, $compiledDelivery->getUri());
    }
38536
public function canMoveBackward(TestSession $session = null)
    {
        if ($this->couldBePaused($session)) {
            return ! $this->isItemPausable($session->getCurrentAssessmentItemRef());
        }
        return true;
    }
909797
public function getSessionStrategy(BrowserConfiguration $browser)
	{
		/*
		 * This logic creates separate strategy for:
		 * - each browser configuration in BrowserTestCase::$browsers (for isolated strategy)
		 * - each browser configuration in BrowserTestCase::$browsers for each test case class (for shared strategy)
		 */
		$strategy_type = $browser->getSessionStrategy();
		$strategy_hash = $browser->getSessionStrategyHash();

		if ( $strategy_hash !== $this->lastUsedSessionStrategyHash ) {
			$this->sessionStrategiesInUse[$strategy_hash] = $this->_sessionStrategyFactory->createStrategy(
				$strategy_type
			);
		}

		$this->lastUsedSessionStrategyHash = $strategy_hash;

		return $this->sessionStrategiesInUse[$strategy_hash];
	}
1018968
public function onCreateSession(CreateCourseSessionEvent $event)
    {
        $session = $event->getCourseSession();
        $options = new MatiereOptions();
        $options->setCourseSession($session);
        $this->om->persist($options);
        $this->om->flush();
    }
597955
protected function doExecute(AssertionContext $context)
    {
        if ($context->getAssertion()) {
            $this->sessionProcessor->processAssertions(
                array($context->getAssertion()),
                $context->getProfileContext()->getOwnEntityDescriptor()->getEntityID(),
                $context->getProfileContext()->getPartyEntityDescriptor()->getEntityID()
            );
        }
    }
207170
private function gcPersistent()
    {
        return (bool) $this->app['database']->getDefault()
            ->delete('PersistentSessions')
            ->where('created_at', U::unixToDb(time() - PersistentSession::$sessionLength), '<')
            ->execute();
    }
904215
public void save(HttpSession httpSession) {
		String sessionSerialized = serializeSession();
		// Finally store the maestrano session
		httpSession.setAttribute(MAESTRANO_SESSION_ID, sessionSerialized);
	}