/** * Unmarshall a DOMElement object corresponding to a MediaInteraction element. * * @param DOMElement $element A DOMElement object. * @return QtiComponent A MediaInteraction object. * @throws UnmarshallingException */ protected function unmarshall(DOMElement $element) { if (($responseIdentifier = self::getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) { if (($autostart = self::getDOMElementAttributeAs($element, 'autostart', 'boolean')) !== null) { $objectElts = self::getChildElementsByTagName($element, 'object'); if (count($objectElts) > 0) { $objectElt = $objectElts[0]; $object = $this->getMarshallerFactory()->createMarshaller($objectElt)->unmarshall($objectElt); $component = new MediaInteraction($responseIdentifier, $autostart, $object); $promptElts = self::getChildElementsByTagName($element, 'prompt'); if (count($promptElts) > 0) { $promptElt = $promptElts[0]; $prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt); $component->setPrompt($prompt); } if (($minPlays = self::getDOMElementAttributeAs($element, 'minPlays', 'integer')) !== null) { $component->setMinPlays($minPlays); } if (($maxPlays = self::getDOMElementAttributeAs($element, 'maxPlays', 'integer')) !== null) { $component->setMaxPlays($maxPlays); } if (($loop = self::getDOMElementAttributeAs($element, 'loop', 'boolean')) !== null) { $component->setLoop($loop); } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } self::fillBodyElement($component, $element); return $component; } else { $msg = "A 'mediaInteraction' element must contain exactly one 'object' element, none given."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'autostart' attribute is missing from the 'mediaInteraction' element."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'responseIdentifier' attribute is missing from the 'mediaInteraction' element."; throw new UnmarshallingException($msg, $element); } }
public function testMarshall() { $object = new Object('my-video.mp4', 'video/mp4'); $object->setWidth(400); $object->setHeight(300); $mediaInteraction = new MediaInteraction('RESPONSE', false, $object, 'my-media'); $mediaInteraction->setMinPlays(1); $mediaInteraction->setMaxPlays(2); $mediaInteraction->setLoop(true); $prompt = new Prompt(); $prompt->setContent(new FlowStaticCollection(array(new TextRun('Prompt...')))); $mediaInteraction->setPrompt($prompt); $element = $this->getMarshallerFactory('2.1.0')->createMarshaller($mediaInteraction)->marshall($mediaInteraction); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<mediaInteraction id="my-media" responseIdentifier="RESPONSE" autostart="false" minPlays="1" maxPlays="2" loop="true"><prompt>Prompt...</prompt><object data="my-video.mp4" type="video/mp4" width="400" height="300"/></mediaInteraction>', $dom->saveXML($element)); }