示例#1
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);
     }
 }
 public function testMarshall()
 {
     $gap = new Gap('gap1', true, 'my-gap', 'gaps');
     $gap->setFixed(false);
     $gap->setTemplateIdentifier('tpl-gap');
     $marshaller = $this->getMarshallerFactory()->createMarshaller($gap);
     $element = $marshaller->marshall($gap);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<gap identifier="gap1" templateIdentifier="tpl-gap" required="true" id="my-gap" class="gaps"/>', $dom->saveXML($element));
 }
示例#3
0
 /**
  * @depends testMarshall21
  */
 public function testMarshallNoMatchGroup21()
 {
     // Aims at testing that no matchGroup attribute is in
     // the output in a QTI 2.1 context.
     $gap = new Gap('gap1');
     $gap->setMatchGroup(new IdentifierCollection(array('identifier1')));
     $marshaller = $this->getMarshallerFactory('2.1.0')->createMarshaller($gap);
     $element = $marshaller->marshall($gap);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<gap identifier="gap1"/>', $dom->saveXML($element));
 }
 /**
  * Unmarshall a DOMElement object corresponding to an XHTML gap element.
  * 
  * @param DOMElement $element A DOMElement object.
  * @return QtiComponent A Gap object.
  * @throws UnmarshallingException
  */
 protected function unmarshall(DOMElement $element)
 {
     if (($identifier = self::getDOMElementAttributeAs($element, 'identifier')) !== null) {
         $component = new Gap($identifier);
         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) {
             $component->setShowHide(ShowHide::getConstantByName($showHide));
         }
         if (($required = self::getDOMElementAttributeAs($element, 'required', 'boolean')) !== null) {
             $component->setRequired($required);
         }
         self::fillBodyElement($component, $element);
         return $component;
     } else {
         $msg = "The mandatory 'identifier' attribute is missing from the 'gap' element.";
         throw new UnmarshallingException($msg, $element);
     }
 }