/** * Set the orientation of the choices. * * @param integer $orientation A value from the Orientation enumeration. * @throws InvalidArgumentException If $orientation is not a value from the Orientation enumeration. */ public function setOrientation($orientation) { if (in_array($orientation, Orientation::asArray()) === true) { $this->orientation = $orientation; } else { $msg = "The 'orientation' argument must be a value from the Orientation enumeration, '" . gettype($orientation) . "' given."; throw new InvalidArgumentException($msg); } }
protected function marshallChildrenKnown(QtiComponent $component, array $elements) { $element = self::getDOMCradle()->createElement($component->getQtiClassName()); self::fillElement($element, $component); self::setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier()); if ($component->hasPrompt() === true) { $element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getPrompt())->marshall($component->getPrompt())); } if ($component->mustShuffle() !== false) { self::setDOMElementAttribute($element, 'shuffle', true); } if ($component instanceof ChoiceInteraction && $component->getMaxChoices() !== 1 || $component instanceof OrderInteraction && $component->getMaxChoices() !== -1) { self::setDOMElementAttribute($element, 'maxChoices', $component->getMaxChoices()); } if ($component instanceof ChoiceInteraction && $component->getMinChoices() !== 0 || $component instanceof OrderInteraction && $component->getMinChoices() !== -1) { self::setDOMElementAttribute($element, 'minChoices', $component->getMinChoices()); } if ($component->getOrientation() !== Orientation::VERTICAL) { self::setDOMElementAttribute($element, 'orientation', Orientation::getNameByConstant(Orientation::HORIZONTAL)); } if ($component->hasXmlBase() === true) { self::setXmlBase($element, $component->getXmlBase()); } foreach ($elements as $e) { $element->appendChild($e); } return $element; }
/** * @see \qtism\data\storage\xml\marshalling\RecursiveMarshaller::marshallChildrenKnown() */ protected function marshallChildrenKnown(QtiComponent $component, array $elements) { $version = $this->getVersion(); $isOrderInteraction = $component instanceof OrderInteraction; $isChoiceInteraction = $component instanceof ChoiceInteraction; $element = self::getDOMCradle()->createElement($component->getQtiClassName()); $this->fillElement($element, $component); self::setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier()); // prompt. if ($component->hasPrompt() === true) { $element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getPrompt())->marshall($component->getPrompt())); } // shuffle. if (Version::compare($version, '2.0.0', '==') === true) { self::setDOMElementAttribute($element, 'shuffle', $component->mustShuffle()); } elseif ($component->mustShuffle() !== false) { self::setDOMElementAttribute($element, 'shuffle', true); } // maxChoices. if ($isChoiceInteraction && Version::compare($version, '2.0.0', '==') === true) { self::setDOMElementAttribute($element, 'maxChoices', $component->getMaxChoices()); } elseif ($isChoiceInteraction && $component->getMaxChoices() !== 0 || $isOrderInteraction && $component->getMaxChoices() !== -1 && Version::compare($version, '2.1.0', '>=') === true) { self::setDOMElementAttribute($element, 'maxChoices', $component->getMaxChoices()); } // minChoices. if (Version::compare($version, '2.1.0', '>=') === true) { if ($isChoiceInteraction && $component->getMinChoices() !== 0 || $isOrderInteraction && $component->getMinChoices() !== -1) { self::setDOMElementAttribute($element, 'minChoices', $component->getMinChoices()); } } // orientation. if (Version::compare($version, '2.0.0', '==') === true && $isOrderInteraction && $component->getOrientation() !== Orientation::VERTICAL) { self::setDOMElementAttribute($element, 'orientation', Orientation::getNameByConstant(Orientation::HORIZONTAL)); } elseif (Version::compare($version, '2.1.0', '>=') === true && $component->getOrientation() !== Orientation::VERTICAL) { self::setDOMElementAttribute($element, 'orientation', Orientation::getNameByConstant(Orientation::HORIZONTAL)); } // xml:base. if ($component->hasXmlBase() === true) { self::setXmlBase($element, $component->getXmlBase()); } foreach ($elements as $e) { $element->appendChild($e); } return $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); } }