/**
  * Unmarshall a DOMElement object corresponding to a QTI templateDeclaration element.
  *
  * @param \DOMElement $element A DOMElement object.
  * @return \qtism\data\QtiComponent A TemplateDeclaration object.
  * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
  */
 protected function unmarshall(DOMElement $element)
 {
     try {
         $baseComponent = parent::unmarshall($element);
         $object = new TemplateDeclaration($baseComponent->getIdentifier());
         $object->setBaseType($baseComponent->getBaseType());
         $object->setCardinality($baseComponent->getCardinality());
         $object->setDefaultValue($baseComponent->getDefaultValue());
         $version = $this->getVersion();
         if (($paramVariable = self::getDOMElementAttributeAs($element, 'paramVariable', 'boolean')) !== null) {
             $object->setParamVariable($paramVariable);
         } elseif (Version::compare($version, '2.0.0', '==') === true) {
             $msg = "The mandatory attribute 'paramVariable' is missing from element '" . $element->localName . "'.";
             throw new UnmarshallingException($msg, $element);
         }
         if (($mathVariable = self::getDOMElementAttributeAs($element, 'mathVariable', 'boolean')) !== null) {
             $object->setMathVariable($mathVariable);
         } elseif (Version::compare($version, '2.0.0', '==') === true) {
             $msg = "The mandatory attribute 'mathVariable' is missing from element '" . $element->localName . "'.";
             throw new UnmarshallingException($msg, $element);
         }
         return $object;
     } catch (InvalidArgumentException $e) {
         $msg = "An unexpected error occured while unmarshalling the templateDeclaration.";
         throw new UnmarshallingException($msg, $element, $e);
     }
 }
Exemplo n.º 2
0
 /**
  * Set the QTI $version in use for this document.
  * 
  * @param string $version A QTI version number e.g. '2.1.1'.
  * @throws \InvalidArgumentException If $version is unknown regarding existing QTI versions.
  */
 public function setVersion($version)
 {
     if (Version::isKnown($version) === true) {
         $this->version = Version::appendPatchVersion($version);
     } else {
         $msg = "Version '{$version}' is not a known QTI version. Known versions are '" . implode(', ', Version::knownVersions()) . "'";
         throw new InvalidArgumentException($msg);
     }
 }
Exemplo n.º 3
0
 public function getMarshallerFactory($version = '2.1')
 {
     if (Version::compare($version, '2.0.0', '==') === true) {
         return new Qti20MarshallerFactory();
     } elseif (Version::compare($version, '2.1.1', '==') === true) {
         return new Qti211MarshallerFactory();
     } elseif (Version::compare($version, '2.2.0', '==') === true) {
         return new Qti22MarshallerFactory();
     } else {
         return new Qti21MarshallerFactory();
     }
 }
Exemplo n.º 4
0
 /**
  * Get the XML schema to use for a given QTI version.
  *
  * @return string A filename pointing at an XML Schema file.
  */
 public static function getSchemaLocation($version = '2.1')
 {
     $dS = DIRECTORY_SEPARATOR;
     $version = Version::appendPatchVersion($version);
     if ($version === '2.1.0') {
         $filename = dirname(__FILE__) . $dS . 'schemes' . $dS . 'imsqti_v2p1.xsd';
     } elseif ($version === '2.1.1') {
         $filename = dirname(__FILE__) . $dS . 'schemes' . $dS . 'imsqti_v2p1p1.xsd';
     } elseif ($version === '2.2.0') {
         $filename = dirname(__FILE__) . $dS . 'schemes' . $dS . 'imsqti_v2p2.xsd';
     } else {
         $filename = dirname(__FILE__) . $dS . 'schemes' . $dS . 'imsqti_v2p0.xsd';
     }
     return $filename;
 }
 /**
  * Unmarshall a DOMElement object corresponding to an positionObjectInteraction element.
  *
  * @param \DOMElement $element A DOMElement object.
  * @return \qtism\data\QtiComponent A PositionObjectInteraction object.
  * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
  */
 protected function unmarshall(DOMElement $element)
 {
     $version = $this->getVersion();
     if (($responseIdentifier = self::getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) {
         $objectElts = self::getChildElementsByTagName($element, 'object');
         if (count($objectElts) > 0) {
             $object = $this->getMarshallerFactory()->createMarshaller($objectElts[0])->unmarshall($objectElts[0]);
             $component = new PositionObjectInteraction($responseIdentifier, $object);
             if (($maxChoices = self::getDOMElementAttributeAs($element, 'maxChoices', 'integer')) !== null) {
                 $component->setMaxChoices($maxChoices);
             }
             if (Version::compare($version, '2.1.0', '>=') === true && ($minChoices = self::getDOMElementAttributeAs($element, 'minChoices', 'integer')) !== null) {
                 $component->setMinChoices($minChoices);
             }
             if (($centerPoint = self::getDOMElementAttributeAs($element, 'centerPoint')) !== null) {
                 $points = explode(" ", $centerPoint);
                 $pointsCount = count($points);
                 if ($pointsCount === 2) {
                     if (Format::isInteger($points[0]) === true) {
                         if (Format::isInteger($points[1]) === true) {
                             $component->setCenterPoint(new QtiPoint(intval($points[0]), intval($points[1])));
                         } else {
                             $msg = "The 2nd integer of the 'centerPoint' attribute value is not a valid integer for element 'positionObjectInteraction'.";
                             throw new UnmarshallingException($msg, $element);
                         }
                     } else {
                         $msg = "The 1st value of the 'centerPoint' attribute value is not a valid integer for element 'positionObjectInteraction'.";
                         throw new UnmarshallingException($msg, $element);
                     }
                 } else {
                     $msg = "The value of the 'centePoint' attribute of a 'positionObjectInteraction' element must be composed of exactly 2 integer values, {$pointsCount} given.";
                     throw new UnmarshallingException($msg, $element);
                 }
             }
             $this->fillBodyElement($component, $element);
             return $component;
         } else {
             $msg = "A 'positionObjectInteraction' element must contain exactly one 'object' element, none given.";
             throw new UnmarshallingException($msg, $element);
         }
     } else {
         $msg = "The mandatory 'responseIdentifier' attribute is missing from the 'positionObjectInteraction' object.";
         throw new UnmarshallingException($msg, $element);
     }
 }
Exemplo n.º 6
0
 /**
  * @see \qtism\data\storage\xml\marshalling\RecursiveMarshaller::marshallChildrenKnown()
  */
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $version = $this->getVersion();
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     $this->fillElement($element, $component);
     self::setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
     if ($component->isFixed() === true) {
         self::setDOMElementAttribute($element, 'fixed', true);
     }
     if (Version::compare($version, '2.1.0', '>=') === true && $component->hasTemplateIdentifier() === true) {
         self::setDOMElementAttribute($element, 'templateIdentifier', $component->getTemplateIdentifier());
     }
     if (Version::compare($version, '2.1.0', '>=') === true && $component->getShowHide() !== ShowHide::SHOW) {
         self::setDOMElementAttribute($element, 'showHide', ShowHide::getNameByConstant(ShowHide::HIDE));
     }
     foreach ($elements as $e) {
         $element->appendChild($e);
     }
     return $element;
 }
 /**
  * @see \qtism\data\storage\xml\marshalling\RecursiveMarshaller::marshallChildrenKnown()
  */
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $version = $this->getVersion();
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     $this->fillElement($element, $component);
     self::setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
     if ($component->mustShuffle() === true || Version::compare($version, '2.0.0', '==') === true) {
         self::setDOMElementAttribute($element, 'shuffle', $component->mustShuffle());
     }
     if ($component->hasXmlBase() === true) {
         self::setXmlBase($element, $component->getXmlBase());
     }
     if ($component->hasPrompt() === true) {
         $element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getPrompt())->marshall($component->getPrompt()));
     }
     foreach ($component->getGapChoices() as $g) {
         $element->appendChild($this->getMarshallerFactory()->createMarshaller($g)->marshall($g));
     }
     foreach ($elements as $e) {
         $element->appendChild($e);
     }
     return $element;
 }
 /**
  * Unmarshall a DOMElement object corresponding to a selectPointInteraction element.
  *
  * @param \DOMElement $element A DOMElement object.
  * @return \qtism\data\QtiComponent A SelectPointInteraction object.
  * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
  */
 protected function unmarshall(DOMElement $element)
 {
     $version = $this->getVersion();
     if (($responseIdentifier = self::getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) {
         $objectElts = self::getChildElementsByTagName($element, 'object');
         if (count($objectElts) > 0) {
             $object = $this->getMarshallerFactory()->createMarshaller($objectElts[0])->unmarshall($objectElts[0]);
             if (($maxChoices = self::getDOMElementAttributeAs($element, 'maxChoices', 'integer')) !== null) {
                 $component = new SelectPointInteraction($responseIdentifier, $object, $maxChoices);
                 if (Version::compare($version, '2.1.0', '>=') === true && ($minChoices = self::getDOMElementAttributeAs($element, 'minChoices', 'integer')) !== null) {
                     $component->setMinChoices($minChoices);
                 }
                 if (($xmlBase = self::getXmlBase($element)) !== false) {
                     $component->setXmlBase($xmlBase);
                 }
                 $promptElts = self::getChildElementsByTagName($element, 'prompt');
                 if (count($promptElts) > 0) {
                     $promptElt = $promptElts[0];
                     $prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt);
                     $component->setPrompt($prompt);
                 }
                 $this->fillBodyElement($component, $element);
                 return $component;
             } else {
                 $msg = "The mandatory 'maxChoices' attribute is missing from the 'selectPointInteraction' element.";
                 throw new UnmarshallingException($msg, $element);
             }
         } else {
             $msg = "A 'selectPointInteraction' element must contain exactly one 'object' element, none given.";
             throw new UnmarshallingException($msg, $element);
         }
     } else {
         $msg = "The mandatory 'responseIdentifier' attribute is missing from the 'selectPointInteraction' element.";
         throw new UnmarshallingException($msg, $element);
     }
 }
Exemplo n.º 9
0
 /**
  * Fill $element with the attributes of $bodyElement.
  *
  * @param DOMElement $element The element from where the atribute values will be
  * @param BodyElement $bodyElement The bodyElement to be fill.
  */
 protected function fillElement(DOMElement $element, BodyElement $bodyElement)
 {
     if (($id = $bodyElement->getId()) !== '') {
         $element->setAttribute('id', $id);
     }
     if (($class = $bodyElement->getClass()) !== '') {
         $element->setAttribute('class', $class);
     }
     if (($lang = $bodyElement->getLang()) !== '') {
         $element->setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:lang', $lang);
     }
     if (($label = $bodyElement->getLabel()) != '') {
         $element->setAttribute('label', $label);
     }
     $version = $this->getVersion();
     if (Version::compare($version, '2.2.0', '>=') === true && ($dir = $bodyElement->getDir()) !== Direction::AUTO && in_array($bodyElement->getQtiClassName(), self::$dirClasses) === true) {
         $element->setAttribute('dir', Direction::getNameByConstant($dir));
     }
 }
 /**
  * @see \qtism\data\storage\xml\marshalling\RecursiveMarshaller::marshallChildrenKnown()
  */
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $version = $this->getVersion();
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     $this->fillElement($element, $component);
     self::setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
     if ($component->mustShuffle() !== false || Version::compare($version, '2.0.0', '==') === true) {
         self::setDOMElementAttribute($element, 'shuffle', $component->mustShuffle());
     }
     if (Version::compare($version, '2.1.0', '>=') && $component->isRequired() !== false) {
         self::setDOMElementAttribute($element, 'required', $component->isRequired());
     }
     if ($component->hasXmlBase() === true) {
         self::setXmlBase($element, $component->getXmlBase());
     }
     foreach ($elements as $e) {
         $element->appendChild($e);
     }
     return $element;
 }
Exemplo n.º 11
0
 /**
  * @see \qtism\data\storage\xml\marshalling\RecursiveMarshaller::marshallChildrenKnown()
  */
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $version = $this->getVersion();
     $isOrderInteraction = $component instanceof OrderInteraction;
     $isChoiceInteraction = $component instanceof ChoiceInteraction;
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     $this->fillElement($element, $component);
     self::setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
     // prompt.
     if ($component->hasPrompt() === true) {
         $element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getPrompt())->marshall($component->getPrompt()));
     }
     // shuffle.
     if (Version::compare($version, '2.0.0', '==') === true) {
         self::setDOMElementAttribute($element, 'shuffle', $component->mustShuffle());
     } elseif ($component->mustShuffle() !== false) {
         self::setDOMElementAttribute($element, 'shuffle', true);
     }
     // maxChoices.
     if ($isChoiceInteraction && Version::compare($version, '2.0.0', '==') === true) {
         self::setDOMElementAttribute($element, 'maxChoices', $component->getMaxChoices());
     } elseif ($isChoiceInteraction && $component->getMaxChoices() !== 0 || $isOrderInteraction && $component->getMaxChoices() !== -1 && Version::compare($version, '2.1.0', '>=') === true) {
         self::setDOMElementAttribute($element, 'maxChoices', $component->getMaxChoices());
     }
     // minChoices.
     if (Version::compare($version, '2.1.0', '>=') === true) {
         if ($isChoiceInteraction && $component->getMinChoices() !== 0 || $isOrderInteraction && $component->getMinChoices() !== -1) {
             self::setDOMElementAttribute($element, 'minChoices', $component->getMinChoices());
         }
     }
     // orientation.
     if (Version::compare($version, '2.0.0', '==') === true && $isOrderInteraction && $component->getOrientation() !== Orientation::VERTICAL) {
         self::setDOMElementAttribute($element, 'orientation', Orientation::getNameByConstant(Orientation::HORIZONTAL));
     } elseif (Version::compare($version, '2.1.0', '>=') === true && $component->getOrientation() !== Orientation::VERTICAL) {
         self::setDOMElementAttribute($element, 'orientation', Orientation::getNameByConstant(Orientation::HORIZONTAL));
     }
     // xml:base.
     if ($component->hasXmlBase() === true) {
         self::setXmlBase($element, $component->getXmlBase());
     }
     foreach ($elements as $e) {
         $element->appendChild($e);
     }
     return $element;
 }
Exemplo n.º 12
0
 /**
  * Unmarshall a DOMElement object corresponding to a printedVariable element.
  *
  * @param \DOMElement $element A DOMElement object.
  * @return \qtism\data\QtiComponent A PrintedVariable object.
  * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
  */
 protected function unmarshall(DOMElement $element)
 {
     $version = $this->getVersion();
     if (($identifier = self::getDOMElementAttributeAs($element, 'identifier')) !== null) {
         $component = new PrintedVariable($identifier);
         if (($format = self::getDOMElementAttributeAs($element, 'format')) !== null) {
             $component->setFormat($format);
         }
         if (Version::compare($version, '2.1.0', '>=') === true && ($powerForm = self::getDOMElementAttributeAs($element, 'powerForm', 'boolean')) !== null) {
             $component->setPowerForm($powerForm);
         }
         if (($base = self::getDOMElementAttributeAs($element, 'base')) !== null) {
             $component->setBase(Format::isInteger($base) === true ? intval($base) : $base);
         }
         if (($index = self::getDOMElementAttributeAs($element, 'index')) !== null) {
             $component->setIndex(Format::isInteger($index) === true ? intval($index) : $base);
         }
         if (Version::compare($version, '2.1.0', '>=') === true && ($delimiter = self::getDOMElementAttributeAs($element, 'delimiter')) !== null) {
             $component->setDelimiter($delimiter);
         }
         if (($field = self::getDOMElementAttributeAs($element, 'field')) !== null) {
             $component->setField($field);
         }
         if (Version::compare($version, '2.1.0', '>=') === true && ($mappingIndicator = self::getDOMElementAttributeAs($element, 'mappingIndicator')) !== null) {
             $component->setMappingIndicator($mappingIndicator);
         }
         if (($xmlBase = self::getXmlBase($element)) !== false) {
             $component->setXmlBase($xmlBase);
         }
         $this->fillBodyElement($component, $element);
         return $component;
     } else {
         $msg = "The mandatory 'identifier' attribute is missing from the 'printedVariable' element.";
         throw new UnmarshallingException($msg, $element);
     }
 }
Exemplo n.º 13
0
 /**
  * @see \qtism\data\storage\xml\marshalling\RecursiveMarshaller::marshallChildrenKnown()
  */
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $version = $this->getVersion();
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     $this->fillElement($element, $component);
     self::setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
     self::setDOMElementAttribute($element, 'matchMax', $component->getMatchMax());
     if (Version::compare($version, '2.1.0', '>=') === true && $component->getMatchMin() !== 0) {
         self::setDOMElementAttribute($element, 'matchMin', $matchMin);
     }
     if ($component->isFixed() === true) {
         self::setDOMElementAttribute($element, 'fixed', true);
     }
     if (Version::compare($version, '2.1.0', '>=') === true && $component->hasTemplateIdentifier() === true) {
         self::setDOMElementAttribute($element, 'templateIdentifier', $component->getTemplateIdentifier());
     }
     if (Version::compare($version, '2.1.0', '>=') === true && $component->getShowHide() !== ShowHide::SHOW) {
         self::setDOMElementAttribute($element, 'showHide', ShowHide::getNameByConstant(ShowHide::HIDE));
     }
     if ($element->localName === 'gapImg' && $component->hasObjectLabel() === true) {
         self::setDOMElementAttribute($element, 'objectLabel', $component->getObjectLabel());
     }
     foreach ($elements as $e) {
         if ($element->localName === 'gapImg') {
             $element->appendChild($e);
         } else {
             // 'gapText'...
             if (Version::compare($version, '2.1.0', '>=') || Version::compare($version, '2.1.0', '<') && $e instanceof DOMCharacterData) {
                 // In QTI 2.0, only plain text is allowed...
                 $element->appendChild($e);
             }
         }
     }
     if (Version::compare($version, '2.1.0', '<') === true) {
         $matchGroup = $component->getMatchGroup();
         if (count($matchGroup) > 0) {
             self::setDOMElementAttribute($element, 'matchGroup', implode(' ', $matchGroup->getArrayCopy()));
         }
     }
     return $element;
 }
 /**
  * @see \qtism\data\storage\xml\marshalling\RecursiveMarshaller::marshallChildrenKnown()
  */
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $version = $this->getVersion();
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     $this->fillElement($element, $component);
     // responseIdentifier.
     self::setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
     // prompt.
     if ($component->hasPrompt() === true) {
         $element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getPrompt())->marshall($component->getPrompt()));
     }
     // shuffle.
     if (Version::compare($version, '2.1.0', '>=') && $component->mustShuffle() !== false) {
         self::setDOMElementAttribute($element, 'shuffle', true);
     } else {
         if (Version::compare($version, '2.0.0', '==') === true) {
             self::setDOMElementAttribute($element, 'shuffle', $component->mustShuffle());
         }
     }
     // maxAssociations.
     if (Version::compare($version, '2.0.0', '==') === true || Version::compare($version, '2.1.0', '>=') === true && $component->getMaxAssociations() !== 1) {
         self::setDOMElementAttribute($element, 'maxAssociations', $component->getMaxAssociations());
     }
     // minAssociations.
     if (Version::compare($version, '2.1.0', '>=') && $component->getMinAssociations() !== 0) {
         self::setDOMElementAttribute($element, 'minAssociations', $component->getMinAssociations());
     }
     // xml:base.
     if ($component->hasXmlBase() === true) {
         self::setXmlBase($element, $component->getXmlBase());
     }
     foreach ($elements as $e) {
         $element->appendChild($e);
     }
     return $element;
 }
Exemplo n.º 15
0
 /**
  * Unmarshall a DOMElement object corresponding to a textEntryInteraction/extendedTextInteraction element.
  *
  * @param \DOMElement $element A DOMElement object.
  * @return \qtism\data\QtiComponent A TextEntryInteraction/ExtendedTextInteraction object.
  * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
  */
 protected function unmarshall(DOMElement $element)
 {
     $version = $this->getVersion();
     if (($responseIdentifier = self::getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) {
         try {
             $class = 'qtism\\data\\content\\interactions\\' . ucfirst($element->localName);
             $component = new $class($responseIdentifier);
         } catch (InvalidArgumentException $e) {
             $msg = "The value '{$responseIdentifier}' of the 'responseIdentifier' attribute of the '" . $element->localName . "' element is not a valid identifier.";
             throw new UnmarshallingException($msg, $element, $e);
         }
         if (($base = self::getDOMElementAttributeAs($element, 'base', 'integer')) !== null) {
             $component->setBase($base);
         }
         if (($stringIdentifier = self::getDOMElementAttributeAs($element, 'stringIdentifier')) !== null) {
             $component->setStringIdentifier($stringIdentifier);
         }
         if (($expectedLength = self::getDOMElementAttributeAs($element, 'expectedLength', 'integer')) !== null) {
             $component->setExpectedLength($expectedLength);
         }
         if (($patternMask = self::getDOMElementAttributeAs($element, 'patternMask')) !== null) {
             $component->setPatternMask($patternMask);
         }
         if (($placeholderText = self::getDOMElementAttributeAs($element, 'placeholderText')) !== null) {
             $component->setPlaceholderText($placeholderText);
         }
         if (($xmlBase = self::getXmlBase($element)) !== false) {
             $component->setXmlBase($xmlBase);
         }
         if ($element->localName === 'extendedTextInteraction') {
             if (($maxStrings = self::getDOMElementAttributeAs($element, 'maxStrings', 'integer')) !== null) {
                 $component->setMaxStrings($maxStrings);
             }
             if (Version::compare($version, '2.1.0', '>=') === true && ($minStrings = self::getDOMElementAttributeAs($element, 'minStrings', 'integer')) !== null) {
                 $component->setMinStrings($minStrings);
             }
             if (($expectedLines = self::getDOMElementAttributeAs($element, 'expectedLines', 'integer')) !== null) {
                 $component->setExpectedLines($expectedLines);
             }
             if (Version::compare($version, '2.1.0', '>=') === true && ($format = self::getDOMElementAttributeAs($element, 'format')) !== null) {
                 $component->setFormat(TextFormat::getConstantByName($format));
             }
             $promptElts = self::getChildElementsByTagName($element, 'prompt');
             if (count($promptElts) > 0) {
                 $component->setPrompt($this->getMarshallerFactory()->createMarshaller($promptElts[0])->unmarshall($promptElts[0]));
             }
         }
         $this->fillBodyElement($component, $element);
         return $component;
     } else {
         $msg = "The mandatory 'responseIdentifier' attribute is missing from the '" . $element->localName . "' element.";
         throw new UnmarshallingException($msg, $element);
     }
 }
 /**
  * @see \qtism\data\storage\xml\marshalling\RecursiveMarshaller::marshallChildrenKnown()
  */
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $version = $this->getVersion();
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     $this->fillElement($element, $component);
     self::setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
     self::setDOMElementAttribute($element, 'maxChoices', $component->getMaxChoices());
     if ($component->hasPrompt() === true) {
         $element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getPrompt())->marshall($component->getPrompt()));
     }
     $element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getObject())->marshall($component->getObject()));
     if (Version::compare($version, '2.1.0', '>=') === true && $component->getMinChoices() !== 0) {
         self::setDOMElementAttribute($element, 'minChoices', $component->getMinChoices());
     }
     self::setDOMElementAttribute($element, 'maxChoices', $component->getMaxChoices());
     if ($component->hasXmlBase() === true) {
         self::setXmlBase($element, $component->getXmlBase());
     }
     foreach ($elements as $e) {
         $element->appendChild($e);
     }
     return $element;
 }
Exemplo n.º 17
0
 public function testUnknownOperator()
 {
     $msg = "Unknown operator '!=='. Known operators are '<, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne'.";
     $this->setExpectedException('\\InvalidArgumentException', $msg);
     Version::compare('2.1.1', '2.2.0', '!==');
 }
Exemplo n.º 18
0
 /**
  * Unmarshall a DOMElement object corresponding to a QTI mapEntry element.
  *
  * @param \DOMElement $element A DOMElement object.
  * @return \qtism\data\QtiComponent A MapEntry object.
  * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
  */
 protected function unmarshall(DOMElement $element)
 {
     if (($mapKey = static::getDOMElementAttributeAs($element, 'mapKey')) !== null) {
         try {
             $mapKey = Utils::stringToDatatype($mapKey, $this->getBaseType());
             if (($mappedValue = static::getDOMElementAttributeAs($element, 'mappedValue', 'float')) !== null) {
                 $object = new MapEntry($mapKey, $mappedValue);
                 if (Version::compare($this->getVersion(), '2.0.0', '>') && ($caseSensitive = static::getDOMElementAttributeAs($element, 'caseSensitive', 'boolean')) !== null) {
                     $object->setCaseSensitive($caseSensitive);
                 }
                 return $object;
             } else {
                 $msg = "The mandatory 'mappedValue' attribute is missing from element '" . $element->nodName . "'.";
                 throw new UnmarshallingException($msg, $element);
             }
         } catch (UnexpectedValueException $e) {
             $msg = "The value of the 'mapKey' attribute '{$mapKey}' could not be converted to qti:valueType.";
             throw new UnmarshallingException($msg, $element, $e);
         }
     } else {
         $msg = "The mandatory 'mapKey' attribute is missing from the '" . $element->localName . "' element";
         throw new UnmarshallingException($msg, $element);
     }
 }
Exemplo n.º 19
0
 /**
  * Unmarshall a DOMElement object corresponding to an XHTML gap element.
  *
  * @param \DOMElement $element A DOMElement object.
  * @return \qtism\data\QtiComponent A Gap object.
  * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
  */
 protected function unmarshall(DOMElement $element)
 {
     $version = $this->getVersion();
     if (($identifier = self::getDOMElementAttributeAs($element, 'identifier')) !== null) {
         $component = new Gap($identifier);
         if (($fixed = self::getDOMElementAttributeAs($element, 'fixed', 'boolean')) !== null) {
             $component->setFixed($fixed);
         }
         if (Version::compare($version, '2.1.0', '>=') === true && ($templateIdentifier = self::getDOMElementAttributeAs($element, 'templateIdentifier')) !== null) {
             $component->setTemplateIdentifier($templateIdentifier);
         }
         if (Version::compare($version, '2.1.0', '>=') === true && ($showHide = self::getDOMElementAttributeAs($element, 'showHide')) !== null) {
             $component->setShowHide(ShowHide::getConstantByName($showHide));
         }
         if (Version::compare($version, '2.1.0', '>=') === true && ($required = self::getDOMElementAttributeAs($element, 'required', 'boolean')) !== null) {
             $component->setRequired($required);
         }
         if (Version::compare($version, '2.1.0', '<') === true && ($matchGroup = self::getDOMElementAttributeAs($element, 'matchGroup')) !== null) {
             $component->setMatchGroup(new IdentifierCollection(explode(" ", $matchGroup)));
         }
         $this->fillBodyElement($component, $element);
         return $component;
     } else {
         $msg = "The mandatory 'identifier' attribute is missing from the 'gap' element.";
         throw new UnmarshallingException($msg, $element);
     }
 }
Exemplo n.º 20
0
 /**
  * Unmarshall a DOMElement object corresponding to a hotspotChoice/associableHotspot element.
  *
  * @param \DOMElement $element A DOMElement object.
  * @return \qtism\data\QtiComponent A HotspotChoice/AssociableHotspot object.
  * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
  */
 protected function unmarshall(DOMElement $element)
 {
     $version = $this->getVersion();
     if (($identifier = self::getDOMElementAttributeAs($element, 'identifier')) !== null) {
         if (($shape = self::getDOMElementAttributeAs($element, 'shape')) !== null) {
             if (($coords = self::getDOMElementAttributeAs($element, 'coords')) !== null) {
                 $shape = QtiShape::getConstantByName($shape);
                 if ($shape === false) {
                     $msg = "The value of the mandatory attribute 'shape' is not a value from the 'shape' enumeration.";
                     throw new UnmarshallingException($msg, $element);
                 }
                 try {
                     $coords = Utils::stringToCoords($coords, $shape);
                 } catch (UnexpectedValueException $e) {
                     $msg = "The coordinates 'coords' of element '" . $element->localName . "' are not valid regarding the shape they are bound to.";
                     throw new UnmarshallingException($msg, $element, $e);
                 } catch (InvalidArgumentException $e) {
                     $msg = "The coordinates 'coords' of element '" . $element->localName . "' could not be converted.";
                     throw new UnmarshallingException($msg, $element, $e);
                 }
                 if ($element->localName === 'hotspotChoice') {
                     $component = new HotspotChoice($identifier, $shape, $coords);
                 } else {
                     if (($matchMax = self::getDOMElementAttributeAs($element, 'matchMax', 'integer')) !== null) {
                         $component = new AssociableHotspot($identifier, $matchMax, $shape, $coords);
                     } else {
                         $msg = "The mandatory attribute 'matchMax' is missing from element 'associableHotspot'.";
                         throw new UnmarshallingException($msg, $element);
                     }
                 }
                 if (($hotspotLabel = self::getDOMElementAttributeAs($element, 'hotspotLabel')) !== null) {
                     $component->setHotspotLabel($hotspotLabel);
                 }
                 if (($fixed = self::getDOMElementAttributeAs($element, 'fixed', 'boolean')) !== null) {
                     $component->setFixed($fixed);
                 }
                 if (($templateIdentifier = self::getDOMElementAttributeAs($element, 'templateIdentifier')) !== null) {
                     $component->setTemplateIdentifier($templateIdentifier);
                 }
                 if (($showHide = self::getDOMElementAttributeAs($element, 'showHide')) !== null) {
                     if (($showHide = ShowHide::getConstantByName($showHide)) !== false) {
                         $component->setShowHide($showHide);
                     } else {
                         $msg = "The value of the 'showHide' attribute of element '" . $element->localName . "' is not a value from the 'showHide' enumeration.";
                         throw new UnmarshallingException($msg, $element);
                     }
                 }
                 if ($element->localName === 'associableHotspot') {
                     if (Version::compare($version, '2.1.0', '<') === true) {
                         if (($matchGroup = self::getDOMElementAttributeAs($element, 'matchGroup')) !== null) {
                             $component->setMatchGroup(new IdentifierCollection(explode(" ", $matchGroup)));
                         }
                     }
                     if (Version::compare($version, '2.1.0', '>=') === true) {
                         if (($matchMin = self::getDOMElementAttributeAs($element, 'matchMin', 'integer')) !== null) {
                             $component->setMatchMin($matchMin);
                         }
                     }
                 }
                 $this->fillBodyElement($component, $element);
                 return $component;
             } else {
                 $msg = "The mandatory attribute 'coords' is missing from element '" . $element->localName . "'.";
                 throw new UnmarshallingException($msg, $element);
             }
         } else {
             $msg = "The mandatory attribute 'shape' is missing from element '" . $element->localName . "'.";
             throw new UnmarshallingException($msg, $element);
         }
     } else {
         $msg = "The mandatory attribute 'identifier' is missing from element '" . $element->localName . "'.";
     }
 }
 /**
  * Unmarshall a DOMElement object corresponding to a QTI outcomeDeclaration element.
  *
  * @param \DOMElement $element A DOMElement object.
  * @return \qtism\data\QtiComponent An OutcomeDeclaration object.
  * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
  */
 protected function unmarshall(DOMElement $element)
 {
     try {
         $version = $this->getVersion();
         $baseComponent = parent::unmarshall($element);
         $object = new OutcomeDeclaration($baseComponent->getIdentifier());
         $object->setBaseType($baseComponent->getBaseType());
         $object->setCardinality($baseComponent->getCardinality());
         $object->setDefaultValue($baseComponent->getDefaultValue());
         // deal with views.
         if (Version::compare($version, '2.1.0', '>=') === true && ($views = static::getDOMElementAttributeAs($element, 'view')) != null) {
             $viewCollection = new ViewCollection();
             foreach (explode(" ", $views) as $viewName) {
                 $viewCollection[] = View::getConstantByName($viewName);
             }
             $object->setViews($viewCollection);
         }
         // deal with interpretation.
         if (($interpretation = static::getDOMElementAttributeAs($element, 'interpretation')) != null) {
             $object->setInterpretation($interpretation);
         }
         // deal with longInterpretation.
         if (($longInterpretation = static::getDOMElementAttributeAs($element, 'longInterpretation')) != null) {
             $object->setLongInterpretation($longInterpretation);
         }
         // deal with normalMaximum.
         if (($normalMaximum = static::getDOMElementAttributeAs($element, 'normalMaximum', 'float')) !== null) {
             $object->setNormalMaximum($normalMaximum);
         }
         // deal with normalMinimum.
         if (Version::compare($version, '2.1.0', '>=') === true && ($normalMinimum = static::getDOMElementAttributeAs($element, 'normalMinimum', 'float')) !== null) {
             $object->setNormalMinimum($normalMinimum);
         }
         // deal with matseryValue.
         if (Version::compare($version, '2.1.0', '>=') === true && ($masteryValue = static::getDOMElementAttributeAs($element, 'masteryValue', 'float')) !== null) {
             $object->setMasteryValue($masteryValue);
         }
         // deal with lookupTable.
         $interpolationTables = $element->getElementsByTagName('interpolationTable');
         $matchTable = $element->getElementsByTagName('matchTable');
         if ($interpolationTables->length == 1 || $matchTable->length == 1) {
             // we have a lookupTable defined.
             $lookupTable = null;
             if ($interpolationTables->length == 1) {
                 $lookupTable = $interpolationTables->item(0);
             } else {
                 $lookupTable = $matchTable->item(0);
             }
             $lookupTableMarshaller = $this->getMarshallerFactory()->createMarshaller($lookupTable, array($object->getBaseType()));
             $object->setLookupTable($lookupTableMarshaller->unmarshall($lookupTable));
         }
         return $object;
     } catch (InvalidArgumentException $e) {
         $msg = "An unexpected error occured while unmarshalling the outcomeDeclaration.";
         throw new UnmarshallingException($msg, $element, $e);
     }
 }