Ejemplo n.º 1
0
 /**
  * Persist an AssessmentTestSession into binary data.
  *
  * @param \qtism\runtime\tests\AssessmentTestSession $assessmentTestSession
  * @throws \qtism\runtime\storage\common\StorageException
  */
 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 the Route of the AssessmentTestSession and the related item sessions.
         $access->writeTinyInt($route->count());
         $itemSessionStore = $assessmentTestSession->getAssessmentItemSessionStore();
         $pendingResponseStore = $assessmentTestSession->getPendingResponseStore();
         $oldRoutePosition = $route->getPosition();
         foreach ($route as $routeItem) {
             $item = $routeItem->getAssessmentItemRef();
             $occurence = $routeItem->getOccurence();
             // Deal with RouteItem
             $access->writeRouteItem($this->getSeeker(), $routeItem);
             // Deal with ItemSession related to the previously written RouteItem.
             try {
                 $itemSession = $itemSessionStore->getAssessmentItemSession($item, $occurence);
                 $access->writeBoolean(true);
                 $access->writeAssessmentItemSession($this->getSeeker(), $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($this->getSeeker(), $pendingResponses);
                 } else {
                     $access->writeBoolean(false);
                 }
             } catch (OutOfBoundsException $e) {
                 $access->writeBoolean(false);
                 // No assessmentItemSession for this route item.
                 continue;
             }
         }
         $route->setPosition($oldRoutePosition);
         // Deal with test session configuration.
         // !!! AutoForward (not in use anymore, fake it).
         $access->writeBoolean(false);
         // 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::PERSITANCE, $e);
     }
 }
 /**
  * Gets the map of the reachable items.
  * @param AssessmentTestSession $session
  * @return array The map of the test
  */
 public static function getTestMap($session)
 {
     $map = array();
     if ($session->isRunning() !== false) {
         $route = $session->getRoute();
         $routeItems = $route->getAllRouteItems();
         $offset = $route->getRouteItemPosition($routeItems[0]);
         foreach ($routeItems as $routeItem) {
             $itemRef = $routeItem->getAssessmentItemRef();
             $occurrence = $routeItem->getOccurence();
             // get the session related to this route item.
             $store = $session->getAssessmentItemSessionStore();
             $itemSession = $store->getAssessmentItemSession($itemRef, $occurrence);
             $map[] = new Jump($offset, $routeItem, $itemSession);
             $offset++;
         }
     }
     return $map;
 }
 /**
  * Persist an AssessmentTestSession into binary data.
  * 
  * The QTI Binary Storage Version that will be used to persist the AssessmentTestSession
  * will be systematically the one defined in QtiBinaryConstants::QTI_BINARY_STORAGE_VERSION. 
  * 
  * @param AssessmentTestSession $assessmentTestSession
  * @throws StorageException
  */
 public function persist(AssessmentTestSession $assessmentTestSession)
 {
     try {
         $stream = new MemoryStream();
         $stream->open();
         $access = $this->createBinaryStreamAccess($stream);
         // write the QTI Binary Storage version in use to persist the test session.
         $access->writeTinyInt(QtiBinaryConstants::QTI_BINARY_STORAGE_VERSION);
         $access->writeTinyInt($assessmentTestSession->getState());
         $route = $assessmentTestSession->getRoute();
         $access->writeTinyInt($route->getPosition());
         // Persist the Route of the AssessmentTestSession and the related item sessions.
         $access->writeTinyInt($route->count());
         $itemSessionStore = $assessmentTestSession->getAssessmentItemSessionStore();
         $pendingResponseStore = $assessmentTestSession->getPendingResponseStore();
         foreach ($route as $routeItem) {
             $item = $routeItem->getAssessmentItemRef();
             $occurence = $routeItem->getOccurence();
             // Deal with RouteItem
             $access->writeRouteItem($this->getSeeker(), $routeItem);
             // Deal with ItemSession related to the previously written RouteItem.
             $itemSession = $itemSessionStore->getAssessmentItemSession($item, $occurence);
             $access->writeAssessmentItemSession($this->getSeeker(), $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($this->getSeeker(), $pendingResponses);
             } else {
                 $access->writeBoolean(false);
             }
         }
         // Deal with test session configuration.
         // -- AutoForward (not in use anymore, fake it).
         $access->writeBoolean(false);
         // 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}'.";
         throw new StorageException($msg, StorageException::PERSITANCE, $e);
     }
 }