Ejemplo n.º 1
0
 /**
  * Unmarshall a DOMElement to its TestFeedbackRef data model representation.
  *
  * @param \DOMElement $element
  * @return \qtism\data\QtiComponent A TestFeedbackRef object.
  * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the element cannot be unmarshalled.
  */
 public function unmarshall(DOMElement $element)
 {
     if (($identifier = self::getDOMElementAttributeAs($element, 'identifier')) !== null) {
         if (($href = self::getDOMElementAttributeAs($element, 'href')) !== null) {
             if (($outcomeIdentifier = self::getDOMElementAttributeAs($element, 'outcomeIdentifier')) !== null) {
                 if (($access = self::getDOMElementAttributeAs($element, 'access')) !== null) {
                     if (($showHide = self::getDOMElementAttributeAs($element, 'showHide')) !== null) {
                         $access = TestFeedbackAccess::getConstantByName($access);
                         $showHide = ShowHide::getConstantByName($showHide);
                         $component = new TestFeedbackRef($identifier, $outcomeIdentifier, $access, $showHide, $href);
                         return $component;
                     } else {
                         $msg = "The mandatory 'showHide' attribute is missing from element 'testFeedbackRef'.";
                         throw new UnmarshallingException($msg, $element);
                     }
                 } else {
                     $msg = "The mandatory 'access' attribute is missing from element 'testFeedbackRef'.";
                     throw new UnmarshallingException($msg, $element);
                 }
             } else {
                 $msg = "The mandatory 'outcomeIdentifier' attribute is missing from element 'testFeedbackRef'.";
                 throw new UnmarshallingException($msg, $element);
             }
         } else {
             $msg = "The mandatory 'href' attribute is missing from element 'testFeedbackRef'.";
             throw new UnmarshallingException($msg, $element);
         }
     } else {
         $msg = "The mandatory 'identifier' attribute is missing from element 'testFeedbackRef'.";
         throw new UnmarshallingException($msg, $element);
     }
 }
 protected function appendAttributes(DOMDocumentFragment $fragment, QtiComponent $component, $base = '')
 {
     parent::appendAttributes($fragment, $component, $base);
     $this->additionalClass('qti-feedbackElement');
     $fragment->firstChild->setAttribute('data-outcome-identifier', $component->getOutcomeIdentifier());
     $fragment->firstChild->setAttribute('data-show-hide', ShowHide::getNameByConstant($component->getShowHide()));
     $fragment->firstChild->setAttribute('data-identifier', $component->getIdentifier());
     if ($this->getRenderingEngine()->getFeedbackShowHidePolicy() === XhtmlRenderingEngine::CONTEXT_STATIC) {
         $this->additionalClass($component->getShowHide() === ShowHide::SHOW ? 'qti-hide' : 'qti-show');
     }
 }
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'outcomeIdentifier', $component->getOutcomeIdentifier());
     self::setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
     self::setDOMElementAttribute($element, 'showHide', ShowHide::getNameByConstant($component->getShowHide()));
     if ($component->hasTitle() === true) {
         self::setDOMElementAttribute($element, 'title', $component->getTitle());
     }
     foreach ($elements as $e) {
         $element->appendChild($e);
     }
     return $element;
 }
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     self::fillElement($element, $component);
     self::setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
     if ($component->isFixed() === true) {
         self::setDOMElementAttribute($element, 'fixed', true);
     }
     if ($component->hasTemplateIdentifier() === true) {
         self::setDOMElementAttribute($element, 'templateIdentifier', $component->getTemplateIdentifier());
     }
     if ($component->getShowHide() !== ShowHide::SHOW) {
         self::setDOMElementAttribute($element, 'showHide', ShowHide::getNameByConstant(ShowHide::HIDE));
     }
     foreach ($elements as $e) {
         $element->appendChild($e);
     }
     return $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);
     }
 }
 /**
  * Unmarshall a DOMElement to its ModalFeedbackRule data model representation.
  *
  * @param \DOMElement $element
  * @return \qtism\data\QtiComponent A ModalFeedbackRule object.
  * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the 'identifier', 'outcomeIdentifier', 'showHide', or attribute is missing from the XML definition.
  */
 public function unmarshall(DOMElement $element)
 {
     if (($identifier = self::getDOMElementAttributeAs($element, 'identifier')) !== null) {
         if (($outcomeIdentifier = self::getDOMElementAttributeAs($element, 'outcomeIdentifier')) !== null) {
             if (($showHide = self::getDOMElementAttributeAs($element, 'showHide', 'string')) !== null) {
                 $showHide = ShowHide::getConstantByName($showHide);
                 $component = new ModalFeedbackRule($outcomeIdentifier, $showHide, $identifier);
                 if (($title = self::getDOMElementAttributeAs($element, 'title')) !== null) {
                     $component->setTitle($title);
                 }
                 return $component;
             } else {
                 $msg = "The mandatory 'showHide' attribute is missing from element 'modalFeedbackRule'.";
                 throw new UnmarshallingException($msg, $element);
             }
         } else {
             $msg = "The mandatory 'outcomeIdentifier' attribute is missing from element 'modalFeedbackRule'.";
             throw new UnmarshallingException($msg, $element);
         }
     } else {
         $msg = "The mandatory 'identifier' attribute is missing from element 'modalFeedbackRule'.";
         throw new UnmarshallingException($msg, $element);
     }
 }
Ejemplo n.º 7
0
 /**
  * Set the visibility of the choice.
  * 
  * @param integer $showHide A value from the ShowHide enumeration.
  * @throws InvalidArgumentException If $showHide is not a value from the ShowHide enumeration.
  */
 public function setShowHide($showHide)
 {
     if (in_array($showHide, ShowHide::asArray()) === true) {
         $this->showHide = $showHide;
     } else {
         $msg = "The 'showHide' argument must be a value from the ShowHide enumeration.";
         throw new InvalidArgumentException($msg);
     }
 }
Ejemplo n.º 8
0
 /**
  * Set how the feedback should be displayed.
  *
  * @param boolean $showHide A value from the ShowHide enumeration.
  * @throws \InvalidArgumentException If $showHide is not a value from the ShowHide enumeration.
  */
 public function setShowHide($showHide)
 {
     if (in_array($showHide, ShowHide::asArray())) {
         $this->showHide = $showHide;
     } else {
         $msg = "'{$showHide}' is not a value from the ShowHide enumeration.";
         throw new InvalidArgumentException($msg);
     }
 }
Ejemplo n.º 9
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) {
         if (Version::compare($version, '2.1.0', '>=') || Version::compare($version, '2.1.0', '<') && $e instanceof DOMCharacterData) {
             $element->appendChild($e);
         }
     }
     return $element;
 }
 /**
  * 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 . "'.";
     }
 }
Ejemplo n.º 11
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);
     self::setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
     self::setDOMElementAttribute($element, 'matchMax', $component->getMatchMax());
     if ($component->isFixed() === true) {
         self::setDOMElementAttribute($element, 'fixed', true);
     }
     if ($component->hasTemplateIdentifier() === true && Version::compare($version, '2.1.0', '>=') === true) {
         self::setDOMElementAttribute($element, 'templateIdentifier', $component->getTemplateIdentifier());
     }
     if ($component->getShowHide() !== ShowHide::SHOW && Version::compare($version, '2.1.0', '>=') === true) {
         self::setDOMElementAttribute($element, 'showHide', ShowHide::getNameByConstant(ShowHide::HIDE));
     }
     if ($component->getMatchMin() !== 0 && Version::compare($version, '2.1.0', '>=') === true) {
         self::setDOMElementAttribute($element, 'matchMin', $component->getMatchMin());
     }
     if (Version::compare($version, '2.1.0', '<') === true) {
         $matchGroup = $component->getMatchGroup();
         if (count($matchGroup) > 0) {
             self::setDOMElementAttribute($element, 'matchGroup', implode(' ', $matchGroup->getArrayCopy()));
         }
     }
     foreach ($elements as $e) {
         $element->appendChild($e);
     }
     return $element;
 }
Ejemplo n.º 13
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);
     }
 }