Skip to content

Commit

Permalink
Merge branch 'legacy' of https://github.com/oat-sa/qti-sdk into legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Sep 21, 2015
2 parents 3d14e38 + 0646960 commit 5f692c1
Show file tree
Hide file tree
Showing 90 changed files with 179 additions and 266 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.11",
"version": "0.9.12",
"authors": [
{
"name": "Open Assessment Technologies S.A.",
Expand Down
53 changes: 53 additions & 0 deletions qtism/runtime/tests/AssessmentItemSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ class AssessmentItemSession extends State {
* @var AbstractSessionManager
*/
private $sessionManager;

/**
* List of callback functions
* @var array
*/
private $callbacks = array();

/**
* Create a new AssessmentItemSession object.
Expand Down Expand Up @@ -586,6 +592,7 @@ public function beginAttempt() {

// Register a time reference that will be used later on to compute the duration built-in variable.
$this->timeReference = new DateTime('now', new DateTimeZone('UTC'));
$this->runCallback('beginAttempt');
}

/**
Expand Down Expand Up @@ -741,6 +748,7 @@ public function endAttempt(State $responses = null, $responseProcessing = true,
// Wait for the next attempt.

$this->attempting = false;
$this->runCallback('endAttempt');
}

/**
Expand All @@ -760,6 +768,7 @@ public function suspend() {

$this->updateDuration();
$this->state = AssessmentItemSessionState::SUSPENDED;
$this->runCallback('suspend');
}
}

Expand All @@ -783,6 +792,7 @@ public function interact() {

// Reset the time reference. If not, the time spent in SUSPENDED mode will be taken into account!
$this->setTimeReference(new DateTime('now', new DateTimeZone('UTC')));
$this->runCallback('interact');
}
}

Expand Down Expand Up @@ -1114,6 +1124,49 @@ public function onDurationUpdate(array $callback) {
$this->onDurationUpdate[] = $callback;
}

/**
* Register callback function which will be invoked after method
* specified in the <i>$eventName</i> parameter is called.
* Events available for callback registration:
* <ul>
* <li>beginAttempt</li>
* <li>endAttempt</li>
* <li>suspend</li>
* <li>interact</li>
* </ul>
*
* Note that first parameter passed to the callback function always will be instance of current class,
* and the remaining parameters will be taken from the <i>$params</i> array.
*
* @param string $eventName name of method of current class after which callback function will be invoked.
* @param array $callback The function or method to be called.
* This parameter may be an array, with the name of the class, and the method, or a string, with a function name.
* @param array $params Parameters to be passed to the callback, as an indexed array.
*/
public function registerCallback($eventName, $callback, $params = array())
{
$this->callbacks[$eventName][] = array(
'callback' => $callback,
'params' => $params
);
}

/**
* Call callback functions registered for method specified in <i>$eventName</i> parameter.
* $this variable will be passed to the callback function as first parameter.
*
* @param string $eventName
*/
protected function runCallback($eventName)
{
if (isset($this->callbacks[$eventName])) {
foreach($this->callbacks[$eventName] as $callback) {
array_unshift($callback['params'], $this);
call_user_func_array($callback['callback'], $callback['params']);
}
}
}

public function __clone() {
$newData = array();
$oldData = $this->getDataPlaceHolder();
Expand Down
3 changes: 1 addition & 2 deletions test/qtism/data/storage/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use qtism\data\storage\Utils;
use qtism\common\enums\BaseType;
use qtism\common\datatypes\Shape;
use \stdClass;

require_once (dirname(__FILE__) . '/../../../QtiSmTestCase.php');

Expand Down Expand Up @@ -358,4 +357,4 @@ public function invalidUriToSanitizeProvider() {
array(true)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use qtism\common\storage\MemoryStream;
use qtism\data\storage\php\marshalling\PhpMarshallingContext;
use qtism\data\storage\php\PhpStreamAccess;
use \RuntimeException;
use \InvalidArgumentException;

require_once (dirname(__FILE__) . '/../../../../../QtiSmTestCase.php');

Expand Down Expand Up @@ -119,4 +117,4 @@ public function testGenerateVariableName() {
$this->assertEquals('point_1', $ctx->generateVariableName(new Point(0, 1)));
$this->assertEquals('coords_2', $ctx->generateVariableName(new Coords(Shape::CIRCLE, array(5, 5, 3))));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
use qtism\data\storage\LocalFileResolver;
use qtism\data\NavigationMode;
use qtism\data\storage\xml\XmlDocument;
use qtism\data\AssessmentTest;
use \DOMDocument;

require_once (dirname(__FILE__) . '/../../../../QtiSmTestCase.php');

Expand Down Expand Up @@ -217,4 +215,4 @@ public function testExplodeRubricBlocks() {

unlink($file);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?php

use qtism\data\storage\xml\marshalling\Marshaller;
use qtism\data\expressions\ExpressionCollection;
use qtism\data\expressions\operators\AnyN;
use qtism\data\expressions\BaseValue;
use qtism\common\enums\BaseType;
use \DOMDocument;

require_once (dirname(__FILE__) . '/../../../../../QtiSmTestCase.php');

Expand Down Expand Up @@ -53,4 +51,4 @@ public function testUnmarshall() {
$this->assertEquals(2, $component->getMax());
$this->assertEquals(3, count($component->getExpressions()));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php

use qtism\data\storage\xml\marshalling\Marshaller;
use qtism\data\state\AreaMapEntry;
use qtism\common\datatypes\Shape;
use qtism\common\datatypes\Coords;
use \DOMDocument;

require_once (dirname(__FILE__) . '/../../../../../QtiSmTestCase.php');

Expand Down Expand Up @@ -41,4 +39,4 @@ public function testUnmarshall() {
$this->assertInternalType('float', $component->getMappedValue());
$this->assertEquals(1.337, $component->getMappedValue());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

use qtism\common\datatypes\Coords;
use qtism\common\datatypes\Shape;
use qtism\data\storage\xml\marshalling\Marshaller;
use qtism\data\state\AreaMapping;
use qtism\data\state\AreaMapEntry;
use qtism\data\state\AreaMapEntryCollection;
use \DOMDocument;

require_once (dirname(__FILE__) . '/../../../../../QtiSmTestCase.php');

Expand Down Expand Up @@ -46,4 +44,4 @@ public function testUnmarshallMinimal() {

$this->assertInstanceOf('qtism\\data\\state\\AreaMapping', $component);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
use qtism\data\state\OutcomeDeclaration;
use qtism\common\enums\Cardinality;
use qtism\common\enums\BaseType;
use qtism\data\storage\xml\marshalling\Marshaller;
use qtism\data\AssessmentItem;

use \DOMDocument;

require_once (dirname(__FILE__) . '/../../../../../QtiSmTestCase.php');

class AssessmentItemMarshallerTest extends QtiSmTestCase {
Expand Down Expand Up @@ -146,4 +143,4 @@ public function testUnmarshallMaximal() {
$outcomeDeclarations = $component->getOutcomeDeclarations();
$this->assertEquals(2, count($outcomeDeclarations));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use qtism\common\datatypes\Duration;
use qtism\common\enums\BaseType;
use qtism\data\storage\xml\marshalling\Marshaller;
use qtism\data\AssessmentItemRef;
use qtism\data\state\WeightCollection;
use qtism\data\state\Weight;
Expand All @@ -18,7 +17,6 @@
use qtism\data\TimeLimits;
use qtism\data\ItemSessionControl;
use qtism\common\collections\IdentifierCollection;
use \DOMDocument;

require_once (dirname(__FILE__) . '/../../../../../QtiSmTestCase.php');

Expand Down Expand Up @@ -174,4 +172,4 @@ public function testUnmarshallMaximal() {
$this->assertInstanceOf('qtism\\data\\TimeLimits', $component->getTimeLimits());
$this->assertInstanceOf('qtism\\data\\ItemSessionControl', $component->getItemSessionControl());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
use qtism\data\AssessmentItemRef;
use qtism\data\SectionPartCollection;
use qtism\data\ItemSessionControl;
use qtism\data\storage\xml\marshalling\Marshaller;
use qtism\data\AssessmentSection;
use qtism\data\rules\PreCondition;
use qtism\data\rules\PreConditionCollection;
use qtism\data\rules\BranchRule;
use qtism\data\rules\BranchRuleCollection;
use qtism\data\expressions\BaseValue;
use qtism\common\enums\BaseType;
use \DOMDocument;

require_once (dirname(__FILE__) . '/../../../../../QtiSmTestCase.php');

Expand Down Expand Up @@ -314,4 +312,4 @@ public function testUnmarshallOneSectionAssessmentItemRefOnly() {
$assessmentItemRefs = $component->getSectionParts();
$this->assertEquals(3, count($assessmentItemRefs));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php

use qtism\data\storage\xml\marshalling\Marshaller;
use qtism\data\AssessmentSectionRef;
use \DOMDocument;

require_once (dirname(__FILE__) . '/../../../../../QtiSmTestCase.php');

Expand Down Expand Up @@ -34,4 +32,4 @@ public function testUnmarshall() {
$this->assertEquals($component->getIdentifier(), 'mySectionRef');
$this->assertEquals($component->getHref(), 'http://www.rdfabout.com');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
use qtism\data\TestPart;
use qtism\data\AssessmentSectionCollection;
use qtism\data\AssessmentSection;
use qtism\data\storage\xml\marshalling\Marshaller;
use qtism\data\AssessmentTest;
use \DOMDocument;

require_once (dirname(__FILE__) . '/../../../../../QtiSmTestCase.php');

Expand Down Expand Up @@ -119,4 +117,4 @@ public function testUnmarshall() {
$this->assertEquals(1, count($component->getOutcomeDeclarations()));
$this->assertEquals(1, count($component->getOutcomeProcessing()));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<?php

use qtism\data\storage\xml\marshalling\Marshaller;
use qtism\data\expressions\BaseValue;
use qtism\common\enums\BaseType;
use qtism\data\storage\Utils;
use \DOMDocument;

require_once (dirname(__FILE__) . '/../../../../../QtiSmTestCase.php');

Expand Down Expand Up @@ -46,4 +43,4 @@ public function testUnmarshallCDATA() {
$this->assertEquals($component->getBaseType(), BaseType::STRING);
$this->assertEquals('A string...', $component->getValue());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use qtism\data\content\TextRun;
use qtism\data\content\FlowCollection;
use qtism\data\content\xhtml\text\Div;
use \DOMDocument;

require_once (dirname(__FILE__) . '/../../../../../QtiSmTestCase.php');

Expand Down Expand Up @@ -60,4 +59,4 @@ public function testMarshall() {

$this->assertEquals('<blockquote class="physics"><h4>Albert Einstein</h4><div class="description">An old Physicist.</div></blockquote>', $dom->saveXML($element));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php

use qtism\data\storage\xml\marshalling\Marshaller;
use qtism\data\rules\BranchRule;
use qtism\data\expressions\BaseValue;
use qtism\common\enums\BaseType;
use \DOMDocument;

require_once (dirname(__FILE__) . '/../../../../../QtiSmTestCase.php');

Expand Down Expand Up @@ -41,4 +39,4 @@ public function testUnmarshall() {
$this->assertEquals('target1', $component->getTarget());
$this->assertInstanceOf('qtism\\data\\expressions\\BaseValue', $component->getExpression());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php

use qtism\data\storage\xml\marshalling\Marshaller;
use qtism\data\expressions\Correct;
use \DOMDocument;

require_once (dirname(__FILE__) . '/../../../../../QtiSmTestCase.php');

Expand Down Expand Up @@ -31,4 +29,4 @@ public function testUnmarshall() {
$this->assertInstanceOf('qtism\\data\\expressions\\Correct', $component);
$this->assertEquals($component->getIdentifier(), 'myCorrect1');
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?php

use qtism\data\storage\xml\marshalling\Marshaller;
use qtism\data\state\CorrectResponse;
use qtism\data\state\Value;
use qtism\data\state\ValueCollection;
use qtism\common\enums\BaseType;
use qtism\common\datatypes\Pair;
use \DOMDocument;

require_once (dirname(__FILE__) . '/../../../../../QtiSmTestCase.php');

Expand Down Expand Up @@ -83,4 +81,4 @@ public function testUnmarshallTwo() {
$this->assertFalse($value->isPartOfRecord());
}
}
}
}
Loading

0 comments on commit 5f692c1

Please sign in to comment.