Skip to content

Commit

Permalink
bugfixes to branching and preconditions.
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Nov 10, 2015
1 parent 90c37db commit ae0b8b6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
68 changes: 37 additions & 31 deletions src/qtism/runtime/tests/AssessmentTestSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -2157,42 +2157,42 @@ protected function nextRouteItem($ignoreBranchings = false, $ignorePreConditions
$route = $this->getRoute();
$stop = false;

while ($route->valid() === true && $stop === false) {

// Branchings?
if ($ignoreBranchings === false && $this->getCurrentNavigationMode() === NavigationMode::LINEAR && count($route->current()->getBranchRules()) > 0) {

$branchRules = $route->current()->getBranchRules();
for ($i = 0; $i < count($branchRules); $i++) {
$engine = new ExpressionEngine($branchRules[$i]->getExpression(), $this);
$condition = $engine->process();
if ($condition !== null && $condition->getValue() === true) {

$target = $branchRules[$i]->getTarget();

if ($target === 'EXIT_TEST') {
$this->endTestSession();
} elseif ($target === 'EXIT_TESTPART') {
$route->next();
$this->moveNextTestPart();
} elseif ($target === 'EXIT_SECTION') {
$route->next();
$this->moveNextAssessmentSection();
} else {
$route->branch($branchRules[$i]->getTarget());
}

break;
// Branchings?
if ($ignoreBranchings === false && $this->getCurrentNavigationMode() === NavigationMode::LINEAR && count($route->current()->getBranchRules()) > 0) {

$branchRules = $route->current()->getBranchRules();
for ($i = 0; $i < count($branchRules); $i++) {
$engine = new ExpressionEngine($branchRules[$i]->getExpression(), $this);
$condition = $engine->process();
if ($condition !== null && $condition->getValue() === true) {

$target = $branchRules[$i]->getTarget();

if ($target === 'EXIT_TEST') {
$this->endTestSession();
} elseif ($target === 'EXIT_TESTPART') {
$route->next();
$this->moveNextTestPart();
} elseif ($target === 'EXIT_SECTION') {
$route->next();
$this->moveNextAssessmentSection();
} else {
$route->branch($branchRules[$i]->getTarget());
}
}

if ($i >= count($branchRules)) {
// No branch rule returned true. Simple move next.
$route->next();
break;
}
} else {
}

if ($i >= count($branchRules)) {
// No branch rule returned true. Simple move next.
$route->next();
}
} else {
$route->next();
}

while ($route->valid() === true && $stop === false) {

// Preconditions on target?
if ($ignorePreConditions === false && $route->valid() === true) {
Expand All @@ -2209,6 +2209,12 @@ protected function nextRouteItem($ignoreBranchings = false, $ignorePreConditions
break;
}
}

if ($i >= count($preConditions)) {
// No preConditions returned true, we have to move next
// and fine a new item to be presented.
$route->next();
}
} else {
$stop = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,4 @@ public function testBranchingOnPreconditon() {
$this->assertSame(null, $session['Q03.SCORE']);
$this->assertSame(1.0, $session['Q04.SCORE']->getValue());
}
}
}

0 comments on commit ae0b8b6

Please sign in to comment.