-
Notifications
You must be signed in to change notification settings - Fork 31
Common Components
The QTI-SDK is providing base components.
All QTI Base Types are available in the QTI-SDK and can be instantiated as PHP objects. The classes representing the QTI Base Types are all implementing the common qtism\common\datatypes\QtiDatatype interface. The existence of these classes is motivated by the fact that PHP does not natively support all the data types required by QTI (e.g. pair, identifier, ...) but must be processed by Response/Outcome/Template Processing engines that needs to know what kind of data they are manipulating at processing time.
-
identifier:qtism\common\datatypes\QtiIdentifier -
boolean:qtism\common\datatypes\QtiBoolean -
integer:qtism\common\datatypes\QtiInteger -
float:qtism\common\datatypes\QtiFloat -
string:qtism\common\datatypes\QtiString -
point:qtism\common\datatypes\QtiPoint -
pair:qtism\common\datatypes\QtiPair -
directedPair:qtism\common\datatypes\QtiDirectedPair -
duration:qtism\common\datatypes\QtiDuration -
file:qtism\common\datatypes\QtiFile -
uri:qtism\common\datatypes\QtiUri -
intOrIdentifier:qtism\common\datatypes\QtiIntOrIdentifier
QTI variables can either be single-valued or multi-valued. In this context, the QTI-SDK provides a set of containers storing qtism\common\datatypes\QtiDatatype objects. The following container implementations are available:
The qtism\runtime\common\MultipleContainer implementation does not consider ordering as important. Container [A, B, C] is considered being equivalent to [C, B, A]. Multiple cardinality containers must contain values of the same QTI Base Type.
use qtism\runtime\common\MultipleContainer;
use qtism\common\enums\BaseType;
use qtism\common\datatypes\QtiIdentifier;
$container = new MultipleContainer(
BaseType::IDENTIFIER,
[new QtiIdentifier('A'), new QtiIdentifier('B'), new QtiIdentifier('C')]
);The qtism\runtime\common\OrderedContainer implementation considers ordering as important. Container [A, B, C] is considered not being equivalent to [C, B, A]. Ordered cardinality containers must contain values of the same QTI Base Type.
use qtism\runtime\common\OrderedContainer;
use qtism\common\enums\BaseType;
use qtism\common\datatypes\QtiIdentifier;
$container = new OrderedContainer(
BaseType::IDENTIFIER,
[new QtiIdentifier('C'), new QtiIdentifier('B'), new QtiIdentifier('A')]
);The qtism\runtime\common\RecordContainer implementation is a special type of container containing independent values each identified by its own key. Record containers can contain a set of values having different QTI Base Types.
use qtism\runtime\common\RecordContainer;
use qtism\common\enums\BaseType;
use qtism\common\datatypes\QtiIdentifier;
use qtism\common\datatypes\QtiInteger;
$record = new RecordContainer([
'key1' => new QtiInteger(1),
'key2' => new QtiIdentifier('myidentifier')
]);Containers are implementing the qtism\common\Comparable. This means that they can be compared easily using the Comparable::equals() method.
The first example below demonstrates the comparison of two MultipleContainer objects.
use qtism\runtime\common\MultipleContainer;
use qtism\common\enums\BaseType;
use qtism\common\datatypes\QtiInteger
// As the order does not matter in Multiple cardinality containers, the comparison will return true.
$c1 = new MultipleContainer(BaseType::INTEGER, [new QtiInteger(5), new QtiInteger(4)]);
$c2 = new MultipleContainer(BaseType::INTEGER, [new QtiInteger(4), new QtiInteger(5)]);
// Returns true.
$c1->equals($c2);This second example demonstrates the comparison of two OrderedContainer objects.
use qtism\runtime\common\OrderedContainer;
use qtism\common\enums\BaseType;
use qtism\common\datatypes\QtiInteger
// As the order matters in Orderded cardinality containers, the comparison will return false.
$c1 = new OrderedContainer(BaseType::INTEGER, [new QtiInteger(5), new QtiInteger(4)]);
$c2 = new OrderedContainer(BaseType::INTEGER, [new QtiInteger(4), new QtiInteger(5)]);
// Returns false.
$c1->equals($c2);