/**
  * Unmarshall a DOMElement object corresponding to a QTI areaMapEntry element.
  *
  * @param \DOMElement $element A DOMElement object.
  * @return \qtism\data\QtiComponent An AreaMapEntry object.
  * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
  */
 protected function unmarshall(DOMElement $element)
 {
     if (($shape = static::getDOMElementAttributeAs($element, 'shape')) !== null) {
         $shape = QtiShape::getConstantByName($shape);
         if ($shape !== false) {
             if (($coords = static::getDOMElementAttributeAs($element, 'coords')) !== null) {
                 try {
                     $coords = Utils::stringToCoords($coords, $shape);
                     if (($mappedValue = static::getDOMElementAttributeAs($element, 'mappedValue', 'float')) !== null) {
                         return new AreaMapEntry($shape, $coords, $mappedValue);
                     } else {
                         $msg = "The mandatory attribute 'mappedValue' is missing from element '" . $element->localName . "'.";
                         throw new UnmarshallingException($msg, $element);
                     }
                 } catch (Exception $e) {
                     $msg = "The attribute 'coords' with value '{$coords}' is has an invalid value.";
                     throw new UnmarshallingException($msg, $element, $e);
                 }
             } else {
                 $msg = "The mandatory attribute 'coords' is missing from element '" . $element->localName . "'.";
                 throw new UnmarshallingException($msg, $element);
             }
         } else {
             $msg = "The 'shape' attribute value '{$shape}' is not a valid value to represent QTI shapes.";
             throw new UnmarshallingException($msg, $element);
         }
     } else {
         $msg = "The mandatory attribute 'shape' is missing from element '" . $element->localName . "'.";
         throw new UnmarshallingException($msg, $element);
     }
 }
示例#2
0
 /**
  * @see \qtism\data\storage\xml\marshalling\OperatorMarshaller::unmarshallChildrenKnown()
  */
 protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children)
 {
     if (($shape = static::getDOMElementAttributeAs($element, 'shape')) !== null) {
         if (($coords = static::getDOMElementAttributeAs($element, 'coords')) !== null) {
             $shape = QtiShape::getConstantByName($shape);
             $coords = Utils::stringToCoords($coords, $shape);
             $object = new Inside($children, $shape, $coords);
             return $object;
         } 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);
     }
 }
示例#3
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 . "'.";
     }
 }