Ejemplo n.º 1
0
 /**
  * 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 = Shape::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);
     }
 }
Ejemplo n.º 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, Shape::asArray())) {
         $this->shape = $shape;
     } else {
         $msg = "The shape argument must be a value from the Shape enumeration, '" . $shape . "' given.";
         throw new InvalidArgumentException($msg);
     }
 }
Ejemplo n.º 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', Shape::getNameByConstant($component->getShape()));
     $fragment->firstChild->setAttribute('data-coords', $component->getCoords()->__toString());
     if ($component->hasHotspotLabel() === true) {
         $fragment->firstChild->setAttribute('data-hotspot-label', $component->getHotspotLabel());
     }
 }
 /**
  * Unmarshall a QTI inside operator element into an Inside object.
  *
  * @param DOMElement The inside element to unmarshall.
  * @param QtiComponentCollection A collection containing the child Expression objects composing the Operator.
  * @return QtiComponent An Inside object.
  * @throws UnmarshallingException
  */
 protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children)
 {
     if (($shape = static::getDOMElementAttributeAs($element, 'shape')) !== null) {
         if (($coords = static::getDOMElementAttributeAs($element, 'coords')) !== null) {
             $shape = Shape::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);
     }
 }
Ejemplo n.º 5
0
    public function createFakeExpression($point = null, Coords $coords = null)
    {
        $point = is_null($point) || !$point instanceof Point ? new Point(2, 2) : $point;
        $coords = is_null($coords) ? new Coords(Shape::RECT, array(0, 0, 5, 3)) : $coords;
        return $this->createComponentFromXml('
			<inside shape="' . Shape::getNameByConstant($coords->getShape()) . '" coords="' . $coords . '">
				<baseValue baseType="point">' . $point . '</baseValue>
			</inside>
		');
    }
 /**
  * Unmarshall a DOMElement object corresponding to a hotspotChoice/associableHotspot element.
  * 
  * @param DOMElement $element A DOMElement object.
  * @return QtiComponent A HotspotChoice/AssociableHotspot object.
  * @throws UnmarshallingException
  */
 protected function unmarshall(DOMElement $element)
 {
     if (($identifier = self::getDOMElementAttributeAs($element, 'identifier')) !== null) {
         if (($shape = self::getDOMElementAttributeAs($element, 'shape')) !== null) {
             if (($coords = self::getDOMElementAttributeAs($element, 'coords')) !== null) {
                 $shape = Shape::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);
                         if (($matchMin = self::getDOMElementAttributeAs($element, 'matchMin', 'integer')) !== null) {
                             $component->setMatchMin($matchMin);
                         }
                     } 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);
                     }
                 }
                 self::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 . "'.";
     }
 }