/** * 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); } }
public function testMarshall() { $sliderInteraction = new SliderInteraction('RESPONSE', 0.0, 100.0, 'my-slider', 'slide-it'); $sliderInteraction->setStep(1); $sliderInteraction->setStepLabel(true); $sliderInteraction->setOrientation(Orientation::VERTICAL); $sliderInteraction->setReverse(true); $prompt = new Prompt(); $prompt->setContent(new FlowStaticCollection(array(new TextRun('Prompt...')))); $sliderInteraction->setPrompt($prompt); $element = $this->getMarshallerFactory('2.1.0')->createMarshaller($sliderInteraction)->marshall($sliderInteraction); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<sliderInteraction id="my-slider" class="slide-it" responseIdentifier="RESPONSE" lowerBound="0" upperBound="100" step="1" stepLabel="true" orientation="vertical" reverse="true"><prompt>Prompt...</prompt></sliderInteraction>', $dom->saveXML($element)); }