Skip to content

Commit

Permalink
fix: if branching rules are from test part, allow nonlinear mode
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfs7 committed Dec 12, 2023
1 parent d8b58d1 commit 6bf92c6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/qtism/data/rules/BranchRuleCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@
*/
class BranchRuleCollection extends QtiComponentCollection
{

/** @var bool */
private $supportsNonLinearNavigationMode = false;

public function isAllowedForNonLinearNavigationMode(): bool
{
return $this->supportsNonLinearNavigationMode;
}

public function allowForNonLinearNavigationMode(): void
{
$this->supportsNonLinearNavigationMode = true;
}

/**
* Check if a given $value is an instance of BranchRule.
*
Expand Down
6 changes: 5 additions & 1 deletion src/qtism/runtime/tests/AssessmentTestSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -2412,7 +2412,11 @@ protected function nextRouteItem($ignoreBranchings = false, $ignorePreConditions
$numberOfBranchRules = $branchRules->count();

// Branchings?
if ($ignoreBranchings === false && $numberOfBranchRules > 0 && $this->mustApplyBranchRules() === true) {
if (
$ignoreBranchings === false &&
$numberOfBranchRules > 0 &&
$this->mustApplyBranchRules() || $branchRules->isAllowedForNonLinearNavigationMode()
) {
for ($i = 0; $i < $numberOfBranchRules; $i++) {
$engine = new ExpressionEngine($branchRules[$i]->getExpression(), $this);
$condition = $engine->process();
Expand Down
5 changes: 4 additions & 1 deletion src/qtism/runtime/tests/RouteItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ public function getEffectiveBranchRules(): BranchRuleCollection
} while ($parentSection = $parentSection->getParent());

// Return branching rules from the Test Part level
return $this->getTestPart()->getBranchRules();
$branchingRules = $this->getTestPart()->getBranchRules();
$branchingRules->allowForNonLinearNavigationMode();

return $branchingRules;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public function testBranchingRules(): void
$session->moveNext();

$this->assertEquals('testPart-8', $session->getCurrentTestPart()->getIdentifier());
$this->assertEquals('assessmentSection-10', $session->getCurrentAssessmentSection()->getIdentifier());
$this->assertEquals('assessmentSection-11', $session->getCurrentAssessmentSection()->getIdentifier());
$this->assertEquals('item-14', $session->getCurrentAssessmentItemRef()->getIdentifier());
}
}
3 changes: 2 additions & 1 deletion test/samples/custom/runtime/branchings/branching_rules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
</assessmentSection>
</testPart>
<testPart identifier="testPart-6" navigationMode="nonlinear" submissionMode="individual">
<branchRule target="testPart-7">
<branchRule target="testPart-8">
<baseValue baseType="boolean">true</baseValue>
</branchRule>
<assessmentSection identifier="assessmentSection-9" title="Section" visible="true">
Expand All @@ -107,6 +107,7 @@
</assessmentItemRef>
</assessmentSection>
</testPart>
<!-- Jump from testPart-7 -->
<testPart identifier="testPart-8" navigationMode="nonlinear" submissionMode="individual">
<assessmentSection identifier="assessmentSection-11" title="Section" visible="true">
<itemSessionControl maxAttempts="0" allowComment="false" validateResponses="false"/>
Expand Down

0 comments on commit 6bf92c6

Please sign in to comment.