/** * Read a route item from the current binary stream. * * @param AssessmentTestSeeker $seeker An AssessmentTestSeeker object where components will be pulled out by position. * @throws QtiBinaryStreamAccessException * @return RouteItem */ public function readRouteItem(AssessmentTestSeeker $seeker) { try { $occurence = $this->readTinyInt(); $itemRef = $seeker->seekComponent('assessmentItemRef', $this->readShort()); if (QtiBinaryConstants::QTI_BINARY_STORAGE_VERSION <= 2) { // Prior to version 3, only a singe assessmentSection might be bound // to the RouteItem. $sections = $seeker->seekComponent('assessmentSection', $this->readShort()); } $testPart = $seeker->seekComponent('testPart', $this->readShort()); if (QtiBinaryConstants::QTI_BINARY_STORAGE_VERSION >= 3) { // From version 3, multiple assessmentSections might be bound // to the RouteItem. $sectionsCount = $this->readTinyInt(); $sections = new AssessmentSectionCollection(); for ($i = 0; $i < $sectionsCount; $i++) { $sections[] = $seeker->seekComponent('assessmentSection', $this->readShort()); } } $branchRulesCount = $this->readTinyInt(); $branchRules = new BranchRuleCollection(); for ($i = 0; $i < $branchRulesCount; $i++) { $branchRules[] = $seeker->seekComponent('branchRule', $this->readShort()); } $preConditionsCount = $this->readTinyInt(); $preConditions = new PreConditionCollection(); for ($i = 0; $i < $preConditionsCount; $i++) { $preConditions[] = $seeker->seekComponent('preCondition', $this->readShort()); } $routeItem = new RouteItem($itemRef, $sections, $testPart, $seeker->getAssessmentTest()); $routeItem->setOccurence($occurence); $routeItem->setBranchRules($branchRules); $routeItem->setPreConditions($preConditions); return $routeItem; } catch (BinaryStreamAccessException $e) { $msg = "An error occured while reading a route item."; throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ROUTE_ITEM, $e); } catch (OutOfBoundsException $e) { $msg = "A QTI Component was not found in the assessmentTest tree structure."; throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ROUTE_ITEM, $e); } }
/** * Read a route item from the current binary stream. * * @param \qtism\runtime\storage\common\AssessmentTestSeeker $seeker An AssessmentTestSeeker object where components will be pulled out by position. * @throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException * @return \qtism\runtime\tests\RouteItem */ public function readRouteItem(AssessmentTestSeeker $seeker) { try { $occurence = $this->readTinyInt(); $itemRef = $seeker->seekComponent('assessmentItemRef', $this->readShort()); $testPart = $seeker->seekComponent('testPart', $this->readShort()); $sectionsCount = $this->readTinyInt(); $sections = new AssessmentSectionCollection(); for ($i = 0; $i < $sectionsCount; $i++) { $sections[] = $seeker->seekComponent('assessmentSection', $this->readShort()); } $branchRulesCount = $this->readTinyInt(); $branchRules = new BranchRuleCollection(); for ($i = 0; $i < $branchRulesCount; $i++) { $branchRules[] = $seeker->seekComponent('branchRule', $this->readShort()); } $preConditionsCount = $this->readTinyInt(); $preConditions = new PreConditionCollection(); for ($i = 0; $i < $preConditionsCount; $i++) { $preConditions[] = $seeker->seekComponent('preCondition', $this->readShort()); } $routeItem = new RouteItem($itemRef, $sections, $testPart, $seeker->getAssessmentTest()); $routeItem->setOccurence($occurence); $routeItem->setBranchRules($branchRules); $routeItem->setPreConditions($preConditions); return $routeItem; } catch (BinaryStreamAccessException $e) { $msg = "An error occured while reading a route item."; throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ROUTE_ITEM, $e); } catch (OutOfBoundsException $e) { $msg = "A QTI Component was not found in the assessmentTest tree structure."; throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ROUTE_ITEM, $e); } }