protected function appendAttributes(DOMDocumentFragment $fragment, QtiComponent $component, $base = '') { parent::appendAttributes($fragment, $component, $base); $fragment->firstChild->setAttribute('name', $component->getName()); $fragment->firstChild->setAttribute('value', $component->getValue()); $fragment->firstChild->setAttribute('valuetype', ParamType::getNameByConstant($component->getValueType())); if ($component->hasType() === true) { $fragment->firstChild->setAttribute('type', $component->hasType()); } }
/** * Unmarshall a DOMElement object corresponding to an XHTML param element. * * @param \DOMElement $element A DOMElement object. * @return \qtism\data\QtiComponent A Param object. * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException */ protected function unmarshall(DOMElement $element) { if (($name = self::getDOMElementAttributeAs($element, 'name')) === null) { // XSD use="required" but can be empty. $name = ''; } if (($value = self::getDOMElementAttributeAs($element, 'value')) === null) { // XSD use="required" but can be empty. $value = ''; } if (($valueType = self::getDOMElementAttributeAs($element, 'valuetype')) !== null) { $component = new Param($name, $value, ParamType::getConstantByName($valueType)); if (($type = self::getDOMElementAttributeAs($element, 'type')) !== null) { $component->setType($type); } return $component; } else { $msg = "The mandatory attribute 'valueType' is missing from the 'param' element."; throw new UnmarshallingException($msg, $element); } }
/** * Set the valueType attribute. * * @param integer $valueType A value from the ParamType enumeration. * @throws InvalidArgumentException If $valueType is not a value from the ParamType enumeration. */ public function setValueType($valueType) { if (in_array($valueType, ParamType::asArray()) === true) { $this->valueType = $valueType; } else { $msg = "The 'valueType' argument must be a value from the ParamType enumeration, '" . gettype($valueType) . "' given."; throw new InvalidArgumentException($msg); } }