/**
  * 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);
     }
 }
Exemple #2
0
 /**
  * Set the shape.
  *
  * @param int $shape A value from the Shape enumeration.
  * @throws \InvalidArgumentException If $shape is not a value from the Shape enumeration.
  */
 public function setShape($shape)
 {
     if (in_array($shape, QtiShape::asArray())) {
         $this->shape = $shape;
     } else {
         $msg = "The shape argument must be a value from the Shape enumeration, '" . $shape . "' given.";
         throw new InvalidArgumentException($msg);
     }
 }
Exemple #3
0
 /**
  * @see \qtism\runtime\rendering\markup\xhtml\ChoiceRenderer::appendAttributes()
  */
 protected function appendAttributes(DOMDocumentFragment $fragment, QtiComponent $component, $base = '')
 {
     parent::appendAttributes($fragment, $component, $base);
     $this->additionalClass('qti-hotspot');
     $fragment->firstChild->setAttribute('data-shape', QtiShape::getNameByConstant($component->getShape()));
     $fragment->firstChild->setAttribute('data-coords', $component->getCoords()->__toString());
     if ($component->hasHotspotLabel() === true) {
         $fragment->firstChild->setAttribute('data-hotspot-label', $component->getHotspotLabel());
     }
 }
Exemple #4
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);
     }
 }
 /**
  * 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 . "'.";
     }
 }
    public function createFakeExpression($point = null, QtiCoords $coords = null)
    {
        $point = is_null($point) || !$point instanceof QtiPoint ? new QtiPoint(2, 2) : $point;
        $coords = is_null($coords) ? new QtiCoords(QtiShape::RECT, array(0, 0, 5, 3)) : $coords;
        return $this->createComponentFromXml('
			<inside shape="' . QtiShape::getNameByConstant($coords->getShape()) . '" coords="' . $coords . '">
				<baseValue baseType="point">' . $point . '</baseValue>
			</inside>
		');
    }