protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children) { if (($responseIdentifier = self::getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) { $fqClass = $this->lookupClass($element); $component = new $fqClass($responseIdentifier, new SimpleChoiceCollection($children->getArrayCopy())); if (($shuffle = self::getDOMElementAttributeAs($element, 'shuffle', 'boolean')) !== null) { $component->setShuffle($shuffle); } if (($maxChoices = self::getDOMElementAttributeAs($element, 'maxChoices', 'integer')) !== null) { if ($element->localName === 'orderInteraction') { if ($maxChoices !== 0) { $component->setMaxChoices($maxChoices); } } else { $component->setMaxChoices($maxChoices); } } if (($minChoices = self::getDOMElementAttributeAs($element, 'minChoices', 'integer')) !== null) { if ($element->localName === 'orderInteraction') { /* * Lots of QTI implementations output minChoices = 0 while * dealing with orderInteraction unmarshalling. However, regarding * the IMS QTI Specification, it is invalid. * * "If specified, minChoices must be 1 or greater but must not exceed the * number of choices available." * * See http://www.imsglobal.org/question/qtiv2p1/imsqti_infov2p1.html#element10283 */ if ($minChoices !== 0) { $component->setMinChoices($minChoices); } } else { $component->setMinChoices($minChoices); } } if (($orientation = self::getDOMElementAttributeAs($element, 'orientation')) !== null) { $component->setOrientation(Orientation::getConstantByName($orientation)); } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } $promptElts = self::getChildElementsByTagName($element, 'prompt'); if (count($promptElts) > 0) { $promptElt = $promptElts[0]; $prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt); $component->setPrompt($prompt); } self::fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory 'responseIdentifier' attribute is missing from the " . $element->localName . " element."; throw new UnmarshallingException($msg, $element); } }
/** * Unmarshall a DOMElement object corresponding to a SliderInteraction element. * * @param DOMElement $element A DOMElement object. * @return QtiComponent A SliderInteraction object. * @throws UnmarshallingException */ protected function unmarshall(DOMElement $element) { if (($responseIdentifier = self::getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) { if (($lowerBound = self::getDOMElementAttributeAs($element, 'lowerBound', 'float')) !== null) { if (($upperBound = self::getDOMElementAttributeAs($element, 'upperBound', 'float')) !== null) { $component = new SliderInteraction($responseIdentifier, $lowerBound, $upperBound); $promptElts = self::getChildElementsByTagName($element, 'prompt'); if (count($promptElts) > 0) { $promptElt = $promptElts[0]; $prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt); $component->setPrompt($prompt); } if (($step = self::getDOMElementAttributeAs($element, 'step', 'integer')) !== null) { $component->setStep($step); } if (($stepLabel = self::getDOMElementAttributeAs($element, 'stepLabel', 'boolean')) !== null) { $component->setStepLabel($stepLabel); } if (($orientation = self::getDOMElementAttributeAs($element, 'orientation')) !== null) { try { $component->setOrientation(Orientation::getConstantByName($orientation)); } catch (InvalidArgumentException $e) { $msg = "The value of the 'orientation' attribute of the 'sliderInteraction' is invalid."; throw new UnmarshallingException($msg, $element, $e); } } if (($reverse = self::getDOMElementAttributeAs($element, 'reverse', 'boolean')) !== null) { $component->setReverse($reverse); } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } self::fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory 'upperBound' attribute is missing from the 'sliderInteraction' element."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'lowerBound' attribute is missing from the 'sliderInteraction' element."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'responseIdentifier' attribute is missing from the 'sliderInteraction' element."; throw new UnmarshallingException($msg, $element); } }