Skip to content

Commit

Permalink
feat: allow to branch to the same test part, do not ignore test part …
Browse files Browse the repository at this point in the history
…branch rules
  • Loading branch information
shpran committed Oct 11, 2023
1 parent 97cfaf2 commit da61af4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 14 additions & 0 deletions src/qtism/runtime/tests/AssessmentTestSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use qtism\data\IAssessmentItem;
use qtism\data\NavigationMode;
use qtism\data\processing\ResponseProcessing;
use qtism\data\rules\BranchRule;
use qtism\data\rules\PreConditionCollection;
use qtism\data\ShowHide;
use qtism\data\state\Weight;
Expand Down Expand Up @@ -2514,8 +2515,21 @@ public function moveNextTestPart(): void

$route = $this->getRoute();
$from = $route->current();
$branchRules = $from->getTestPart()->getBranchRules();

while ($route->valid() === true && $route->current()->getTestPart() === $from->getTestPart()) {
/** @var BranchRule $branchRule */
foreach ($branchRules as $branchRule) {
$engine = new ExpressionEngine($branchRule->getExpression(), $this);
$condition = $engine->process();

if ($condition !== null && $condition->getValue() === true) {
$route->branch($branchRule->getTarget());

break 2;
}
}

$route->next();
}

Expand Down
8 changes: 0 additions & 8 deletions src/qtism/runtime/tests/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -1150,14 +1150,6 @@ public function branch($identifier): void
// Check for a testPart.
$testPartIdentifierMap = $this->getTestPartIdentifierMap();
if (isset($testPartIdentifierMap[$id])) {
// We branch to the first RouteItem belonging to the testPart.
if ($testPartIdentifierMap[$id][0]->getTestPart() === $this->current()->getTestPart()) {
// From IMS QTI:
// For testParts, the target must refer to another testPart.
$msg = 'Cannot branch to the same testPart.';
throw new OutOfBoundsException($msg);
}

// We branch to the first RouteItem belonging to the testPart.
$this->setPosition($this->getRouteItemPosition($testPartIdentifierMap[$id][0]));

Expand Down

0 comments on commit da61af4

Please sign in to comment.