/**
  * Create a new SelectableRoute object.
  * 
  * @param boolean $fixed If the SelectableRoute is fixed.
  * @param boolean $required If the SelectableRoutei is required.
  * @param boolean $visible If the SelectableRoute is visible.
  * @param boolean $keepTogether If the SelectableRoute must be kept together.
  */
 public function __construct($fixed = false, $required = false, $visible = true, $keepTogether = true)
 {
     parent::__construct();
     $this->setFixed($fixed);
     $this->setRequired($required);
     $this->setVisible($visible);
     $this->setKeepTogether($keepTogether);
 }
 /**
  * Retrieve an AssessmentTestSession object from storage by $sessionId.
  *
  * @param \qtism\data\AssessmentTest $test
  * @param string $sessionId
  * @return \qtism\runtime\tests\AssessmentTestSession An AssessmentTestSession object.
  * @throws \qtism\runtime\storage\common\StorageException If the AssessmentTestSession could not be retrieved from storage.
  */
 public function retrieve(AssessmentTest $test, $sessionId)
 {
     try {
         $stream = $this->getRetrievalStream($sessionId);
         $stream->open();
         $access = $this->createBinaryStreamAccess($stream);
         // -- Deal with intrinsic values of the Test Session.
         $assessmentTestSessionState = $access->readTinyInt();
         $currentPosition = $access->readTinyInt();
         if ($access->readBoolean() === true) {
             $timeReference = $access->readDateTime();
         } else {
             $timeReference = null;
         }
         // Build the route and the item sessions.
         $route = new Route();
         $lastOccurenceUpdate = new SplObjectStorage();
         $itemSessionStore = new AssessmentItemSessionStore();
         $pendingResponseStore = new PendingResponseStore();
         $routeCount = $access->readTinyInt();
         // Create the item session factory that will be used to instantiate
         // new item sessions.
         for ($i = 0; $i < $routeCount; $i++) {
             $routeItem = $access->readRouteItem($this->getSeeker());
             $route->addRouteItemObject($routeItem);
             // An already instantiated session for this route item?
             if ($access->readBoolean() === true) {
                 $itemSession = $access->readAssessmentItemSession($this->getManager(), $this->getSeeker());
                 // last-update
                 if ($access->readBoolean() === true) {
                     $lastOccurenceUpdate[$routeItem->getAssessmentItemRef()] = $routeItem->getOccurence();
                 }
                 // pending-responses
                 if ($access->readBoolean() === true) {
                     $pendingResponseStore->addPendingResponses($access->readPendingResponses($this->getSeeker()));
                 }
                 $itemSessionStore->addAssessmentItemSession($itemSession, $routeItem->getOccurence());
             }
         }
         $route->setPosition($currentPosition);
         $manager = $this->getManager();
         $assessmentTestSession = $manager->createAssessmentTestSession($test, $route);
         $assessmentTestSession->setAssessmentItemSessionStore($itemSessionStore);
         $assessmentTestSession->setSessionId($sessionId);
         $assessmentTestSession->setState($assessmentTestSessionState);
         $assessmentTestSession->setLastOccurenceUpdate($lastOccurenceUpdate);
         $assessmentTestSession->setPendingResponseStore($pendingResponseStore);
         $assessmentTestSession->setTimeReference($timeReference);
         // Deal with test session configuration.
         // -- AutoForward (not in use anymore, consume it anyway).
         $access->readBoolean();
         // Build the test-level global scope, composed of Outcome Variables.
         foreach ($test->getOutcomeDeclarations() as $outcomeDeclaration) {
             $outcomeVariable = OutcomeVariable::createFromDataModel($outcomeDeclaration);
             $access->readVariableValue($outcomeVariable);
             $assessmentTestSession->setVariable($outcomeVariable);
         }
         // Build the duration store.
         $durationStore = new DurationStore();
         $durationCount = $access->readShort();
         for ($i = 0; $i < $durationCount; $i++) {
             $varName = $access->readString();
             $durationVariable = new OutcomeVariable($varName, Cardinality::SINGLE, BaseType::DURATION);
             $access->readVariableValue($durationVariable);
             $durationStore->setVariable($durationVariable);
         }
         $assessmentTestSession->setDurationStore($durationStore);
         $stream->close();
         return $assessmentTestSession;
     } catch (Exception $e) {
         $msg = "An error occured while retrieving AssessmentTestSession. " . $e->getMessage();
         throw new StorageException($msg, StorageException::RETRIEVAL, $e);
     }
 }
Example #3
0
 public function testOccurences()
 {
     $assessmentItemRefs = new AssessmentItemRefCollection();
     $assessmentItemRefs[] = new AssessmentItemRef('Q1', 'Q1.xml');
     $assessmentItemRefs[] = new AssessmentItemRef('Q2', 'Q2.xml');
     $assessmentItemRefs[] = new AssessmentItemRef('Q3', 'Q3.xml');
     $assessmentSections = new AssessmentSectionCollection();
     $assessmentSections[] = new AssessmentSection('S1', 'Section 1', true);
     $assessmentSections['S1']->setSectionParts($assessmentItemRefs);
     $testParts = new TestPartCollection();
     $testParts[] = new TestPart('T1', $assessmentSections);
     $assessmentTest = new AssessmentTest('test', 'A Test', $testParts);
     $route = new Route();
     $route->addRouteItem($assessmentItemRefs['Q1'], $assessmentSections['S1'], $testParts['T1'], $assessmentTest);
     $route->addRouteItem($assessmentItemRefs['Q2'], $assessmentSections['S1'], $testParts['T1'], $assessmentTest);
     $route->addRouteItem($assessmentItemRefs['Q3'], $assessmentSections['S1'], $testParts['T1'], $assessmentTest);
     $this->assertEquals(1, $route->getOccurenceCount($assessmentItemRefs['Q1']));
     $this->assertEquals(1, $route->getOccurenceCount($assessmentItemRefs['Q2']));
     $this->assertEquals(1, $route->getOccurenceCount($assessmentItemRefs['Q3']));
     $route->addRouteItem($assessmentItemRefs['Q3'], $assessmentSections['S1'], $testParts['T1'], $assessmentTest);
     $this->assertEquals(2, $route->getOccurenceCount($assessmentItemRefs['Q3']));
     // Get the second route item in the route.
     $routeItem2 = $route->getRouteItemAt(1);
     $this->assertEquals('Q2', $routeItem2->getAssessmentItemRef()->getIdentifier());
     $this->assertEquals(0, $routeItem2->getOccurence());
     $routeItem3 = $route->getRouteItemAt(2);
     $this->assertEquals('Q3', $routeItem3->getAssessmentItemRef()->getIdentifier());
     $this->assertEquals(0, $routeItem3->getOccurence());
     $routeItem4 = $route->getRouteItemAt(3);
     $this->assertEquals('Q3', $routeItem4->getAssessmentItemRef()->getIdentifier());
     $this->assertEquals(1, $routeItem4->getOccurence());
 }