public function testPendingResponseStore()
 {
     $itemRef1 = new AssessmentItemRef('Q01', './Q01.xml');
     $itemRef2 = new AssessmentItemRef('Q02', './Q02.xml');
     $itemRef3 = new AssessmentItemRef('Q03', './Q02.xml');
     $state1 = new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::BOOLEAN, new Boolean(true))));
     $state2 = new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::BOOLEAN, new Boolean(false))));
     $state3 = new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::INTEGER, new Integer(1337))));
     $store = new PendingResponseStore();
     $store->addPendingResponses(new PendingResponses($state1, $itemRef1));
     $store->addPendingResponses(new PendingResponses($state2, $itemRef1, 1));
     $this->assertEquals(2, count($store->getAllPendingResponses()));
     $this->assertTrue($store->hasPendingResponses($itemRef1));
     $this->assertFalse($store->hasPendingResponses($itemRef3));
     $this->assertFalse($store->hasPendingResponses($itemRef1, 4));
     $this->assertTrue($itemRef1 === $store->getPendingResponses($itemRef1)->getAssessmentItemRef());
     $this->assertTrue($state2 === $store->getPendingResponses($itemRef1, 1)->getState());
 }
예제 #2
0
 /**
  * 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);
     }
 }