Skip to content

Commit

Permalink
New feature enabling some specific outcome variables to remain
Browse files Browse the repository at this point in the history
preserved at outcome processing time.
  • Loading branch information
bugalot committed Jul 29, 2015
1 parent 20a9dbd commit 6973113
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "qtism/qtism",
"description": "OAT QTI Software Module Library",
"type": "library",
"version": "0.9.8",
"version": "0.9.9",
"authors": [
{
"name": "Open Assessment Technologies S.A.",
Expand Down
5 changes: 3 additions & 2 deletions qtism/runtime/common/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,17 @@ public function offsetGet($offset) {
* Reset all test-level outcome variables to their defaults.
*
* @param boolean $preserveBuiltIn Whether the built-in outcome variable 'completionStatus'.
* @param array $preserve An array of identifiers reflecting variables that must not be reset but preserved.
*/
public function resetOutcomeVariables($preserveBuiltIn = true) {
public function resetOutcomeVariables($preserveBuiltIn = true, array $preserve = array()) {
$data = &$this->getDataPlaceHolder();

foreach (array_keys($data) as $k) {
if ($data[$k] instanceof OutcomeVariable) {
if ($preserveBuiltIn === true && $k === 'completionStatus') {
continue;
}
else {
else if (in_array($k, $preserve) === false) {
$data[$k]->applyDefaultValue();
}
}
Expand Down
28 changes: 27 additions & 1 deletion qtism/runtime/tests/AssessmentTestSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ class AssessmentTestSession extends State {
*/
private $sessionManager;

/**
* An array of identifiers representing outcome variable that must not be applied their default value at outcome processing time.
*
* @var array
*/
private $preservedOutcomeVariables;

/**
* Create a new AssessmentTestSession object.
*
Expand All @@ -167,6 +174,7 @@ public function __construct(AssessmentTest $assessmentTest, AbstractSessionManag
$this->setPendingResponseStore(new PendingResponseStore());
$durationStore = new DurationStore();
$this->setDurationStore($durationStore);
$this->setPreservedOutcomeVariables(array());

// Take the outcomeDeclaration objects of the global scope.
// Instantiate them with their defaults.
Expand Down Expand Up @@ -414,6 +422,24 @@ public function setSessionManager(AbstractSessionManager $sessionManager) {
public function getSessionManager() {
return $this->sessionManager;
}

/**
* Set the identifiers of the outcome variables that must not be applied their default value at outcome processing time.
*
* @param array $identifiers
*/
public function setPreservedOutcomeVariables(array $identifiers) {
$this->preservedOutcomeVariables = $identifiers;
}

/**
* Get the identifiers of the outcome variables that must not be applied their default value at outcome processing time.
*
* @return array
*/
public function getPreservedOutcomeVariables() {
return $this->preservedOutcomeVariables;
}

/**
* Get a weight by using a prefixed identifier e.g. 'Q01.weight1'
Expand Down Expand Up @@ -1718,7 +1744,7 @@ protected function outcomeProcessing() {
// As per QTI Spec:
// The values of the test's outcome variables are always reset to their defaults prior
// to carrying out the instructions described by the outcomeRules.
$this->resetOutcomeVariables();
$this->resetOutcomeVariables(true, $this->getPreservedOutcomeVariables());

$outcomeProcessing = $this->getAssessmentTest()->getOutcomeProcessing();

Expand Down
33 changes: 33 additions & 0 deletions test/qtism/runtime/tests/AssessmentTestSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1409,4 +1409,37 @@ public function testEmptySection() {
// and the session is then closed.
$this->assertEquals(AssessmentTestSessionState::CLOSED, $session->getState());
}

public function testPreserveOutcomes() {
// Aims at testing that even a section of the test is empty,
// it is simply ignored at runtime.
$doc = new XmlCompactDocument();
$doc->load(self::samplesDir() . 'custom/runtime/preserve_test_outcomes.xml');
$manager = new SessionManager();

$session = $manager->createAssessmentTestSession($doc->getDocumentComponent());
$session->setPreservedOutcomeVariables(array('PRESERVED'));
$session->beginTestSession();

$this->assertEquals('I will be preserved!', $session['PRESERVED']->getValue());
$session['PRESERVED'] = new String('I am still preserved!');

$this->assertEquals(0, $session['NOTPRESERVED']->getValue());

$this->assertEquals('Q01', $session->getCurrentAssessmentItemRef()->getIdentifier());
$session->beginAttempt();
$session->endAttempt(new State(array(new ResponseVariable('RESPONSE', BaseType::IDENTIFIER, Cardinality::SINGLE, new Identifier('ChoiceA')))));
$session->moveNext();

$this->assertEquals('I am still preserved!', $session['PRESERVED']->getValue());
$this->assertEquals(1, $session['NOTPRESERVED']->getValue());

$this->assertEquals('Q02', $session->getCurrentAssessmentItemRef()->getIdentifier());
$session->beginAttempt();
$session->endAttempt(new State(array(new ResponseVariable('RESPONSE', BaseType::IDENTIFIER, Cardinality::SINGLE, new Identifier('ChoiceB')))));
$session->moveNext();

$this->assertEquals('I am still preserved!', $session['PRESERVED']->getValue());
$this->assertEquals(1, $session['NOTPRESERVED']->getValue());
}
}

0 comments on commit 6973113

Please sign in to comment.