protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children) { if (($identifier = self::getDOMElementAttributeAs($element, 'identifier')) !== null) { if (($matchMax = self::getDOMElementAttributeAs($element, 'matchMax', 'integer')) !== null) { $fqClass = $this->lookupClass($element); $component = new $fqClass($identifier, $matchMax); 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 (($matchMin = self::getDOMElementAttributeAs($element, 'matchMin', 'integer')) !== null) { $component->setMatchMin($matchMin); } $component->setContent(new FlowStaticCollection($children->getArrayCopy())); self::fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory 'matchMax' attribute is missing from the 'simpleAssociableChoice' element."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'identifier' attribute is missing from the 'simpleAssociableChoice' element."; throw new UnmarshallingException($msg, $element); } }
protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children) { if (($identifier = self::getDOMElementAttributeAs($element, 'identifier')) !== null) { $fqClass = $this->lookupClass($element); try { $component = new $fqClass($identifier); } catch (InvalidArgumentException $e) { $msg = "'{$identifier}' is not a valid identifier for an 'inlineChoice' element."; throw new UnmarshallingException($msg, $element, $e); } try { $component->setContent(new TextOrVariableCollection($children->getArrayCopy())); } catch (InvalidArgumentException $e) { $msg = "'inlineChoice' elements must only contain text or 'printedVariable' elements."; throw new UnmarshallingException($msg, $element, $e); } 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)); } self::fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory 'identifier' attribute is missing from the 'simpleChoice' element."; throw new UnmarshallingException($msg, $element); } }
/** * 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); } }
/** * @see \qtism\data\storage\xml\marshalling\RecursiveMarshaller::unmarshallChildrenKnown() */ protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children) { if (($identifier = self::getDOMElementAttributeAs($element, 'identifier')) !== null) { $fqClass = $this->lookupClass($element); $component = new $fqClass($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 (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } $component->setContent(new InlineStaticCollection($children->getArrayCopy())); $this->fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory 'identifier' attribute is missing from the 'hottext' element."; throw new UnmarshallingException($msg, $element); } }
/** * @see \qtism\data\storage\xml\marshalling\RecursiveMarshaller::unmarshallChildrenKnown() */ protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children) { $version = $this->getVersion(); if (($identifier = self::getDOMElementAttributeAs($element, 'identifier')) !== null) { if (($matchMax = self::getDOMElementAttributeAs($element, 'matchMax', 'integer')) !== null) { $fqClass = $this->lookupClass($element); if ($element->localName === 'gapImg') { if (count($children) === 1) { $component = new $fqClass($identifier, $matchMax, $children[0]); } else { $msg = "A 'gapImg' element must contain a single 'object' element, " . count($children) . " given."; throw new UnmarshallingException($msg, $element); } } else { $component = new $fqClass($identifier, $matchMax); } if (Version::compare($version, '2.1.0', '>=') === true && ($matchMin = self::getDOMElementAttributeAs($element, 'matchMin', 'integer')) !== null) { $component->setMatchMin($matchMin); } 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 ($element->localName === 'gapText') { if (Version::compare($version, '2.1.0', '<') === true && $children->exclusivelyContainsComponentsWithClassName('textRun') === false) { $msg = "A 'gapText' element must only contain text. Children elements found."; throw new UnmarshallingException($msg, $element); } try { $component->setContent(new TextOrVariableCollection($children->getArrayCopy())); } catch (InvalidArgumentException $e) { $msg = "Invalid content in 'gapText' element."; throw new UnmarshallingException($msg, $element, $e); } } else { if (($objectLabel = self::getDOMElementAttributeAs($element, 'objectLabel')) !== null) { $component->setObjectLabel($objectLabel); } } 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 'matchMax' attribute is missing from the 'simpleChoice' element."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'identifier' attribute is missing from the 'simpleChoice' element."; throw new UnmarshallingException($msg, $element); } }
protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children) { $fqClass = $this->lookupClass($element); if (($outcomeIdentifier = self::getDOMElementAttributeAs($element, 'outcomeIdentifier')) !== null) { if (($identifier = self::getDOMElementAttributeAs($element, 'identifier')) !== null) { $component = new $fqClass($outcomeIdentifier, $identifier); if (($showHide = self::getDOMElementAttributeAs($element, 'showHide')) !== null) { try { $component->setShowHide(ShowHide::getConstantByName($showHide)); } catch (InvalidArgumentException $e) { $msg = "'{$showHide}' is not a valid value for the 'showHide' attribute of element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element, $e); } $inline = $element->localName === 'feedbackInline'; $content = $inline === true ? new InlineCollection() : new FlowCollection(); $blockExclusion = array('hottext', 'rubricBlock', 'endAttemptInteraction', 'inlineChoiceInteraction', 'textEntryInteraction'); foreach ($children as $child) { $qtiClassName = $child->getQtiClassName(); if ($inline === false && !$child instanceof Flow) { $msg = "A '{$qtiClassName}' cannot be contained by a 'feedbackBlock'."; throw new UnmarshallingException($msg, $element); } if ($inline === false && in_array($child->getQtiClassName(), $blockExclusion) === true) { $msg = "A '{$qtiClassName}' cannot be contained by a 'feedbackBlock'."; throw new UnmarshallingException($msg, $element); } $content[] = $child; } $component->setContent($content); if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } self::fillBodyElement($component, $element); return $component; } } else { $msg = "The mandatory 'identifier' attribute is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'outcomeIdentifier' attribute is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }
protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children) { $fqClass = $this->lookupClass($element); if (($templateIdentifier = self::getDOMElementAttributeAs($element, 'templateIdentifier')) !== null) { if (($identifier = self::getDOMElementAttributeAs($element, 'identifier')) !== null) { $component = new $fqClass($templateIdentifier, $identifier); if (($showHide = self::getDOMElementAttributeAs($element, 'showHide')) !== null) { try { $component->setShowHide(ShowHide::getConstantByName($showHide)); } catch (InvalidArgumentException $e) { $msg = "'{$showHide}' is not a valid value for the 'showHide' attribute of element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element, $e); } try { $content = $element->localName === 'templateInline' ? new InlineStaticCollection() : new FlowStaticCollection(); foreach ($children as $c) { if (!$c instanceof FlowStatic || $element->localName === 'templateBlock' && in_array($c->getQtiClassName(), array('hottext', 'rubricBlock', 'infoControl'))) { $msg = "The '" . $element->localName . "' cannot contain '" . $c->getQtiClassName() . "' elements."; throw new UnmarshallingException($msg, $element); } $content[] = $c; } $component->setContent($content); } catch (InvalidArgumentException $e) { $mustContain = $element->localName === 'feedbackInline' ? 'inline' : 'block'; $msg = "The content of the '" . $element->localName . "' is invalid. It must only contain '{$mustContain}' elements."; throw new UnmarshallingException($msg, $element, $e); } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } self::fillBodyElement($component, $element); return $component; } } else { $msg = "The mandatory 'identifier' attribute is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'templateIdentifier' attribute is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }
/** * @see \qtism\data\storage\xml\marshalling\RecursiveMarshaller::unmarshallChildrenKnown() */ protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children) { $version = $this->getVersion(); if (($identifier = self::getDOMElementAttributeAs($element, 'identifier')) !== null) { $fqClass = $this->lookupClass($element); $component = new $fqClass($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)); } $component->setContent(new FlowStaticCollection($children->getArrayCopy())); $this->fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory 'identifier' attribute is missing from the 'simpleChoice' element."; throw new UnmarshallingException($msg, $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); } }
protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children) { $fqClass = $this->lookupClass($element); if (($outcomeIdentifier = self::getDOMElementAttributeAs($element, 'outcomeIdentifier')) !== null) { if (($identifier = self::getDOMElementAttributeAs($element, 'identifier')) !== null) { $component = new $fqClass($outcomeIdentifier, $identifier); if (($showHide = self::getDOMElementAttributeAs($element, 'showHide')) !== null) { try { $component->setShowHide(ShowHide::getConstantByName($showHide)); } catch (InvalidArgumentException $e) { $msg = "'{$showHide}' is not a valid value for the 'showHide' attribute of element 'modalFeedback'."; throw new UnmarshallingException($msg, $element, $e); } try { $content = new FlowStaticCollection($children->getArrayCopy()); $component->setContent($content); } catch (InvalidArgumentException $e) { $msg = "The content of the 'modalFeedback' is invalid. It must only contain 'flowStatic' elements."; throw new UnmarshallingException($msg, $element, $e); } if (($title = self::getDOMElementAttributeAs($element, 'title')) !== null) { $component->setTitle($title); } return $component; } else { $msg = "The mandatory 'showHide' attribute is missing from element 'modalFeedback'."; } } else { $msg = "The mandatory 'identifier' attribute is missing from element 'modalFeedback'."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'outcomeIdentifier' attribute is missing from element 'modalFeedback'."; 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); } }
/** * 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 . "'."; } }
/** * 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); } }