protected function appendAttributes(DOMDocumentFragment $fragment, QtiComponent $component, $base = '') { parent::appendAttributes($fragment, $component, $base); $this->additionalClass('qti-blockInteraction'); $this->additionalClass('qti-extendedTextInteraction'); $fragment->firstChild->setAttribute('data-min-strings', $component->getMinStrings()); $fragment->firstChild->setAttribute('data-format', TextFormat::getNameByConstant($component->getFormat())); if ($component->hasMaxStrings() === true) { $fragment->firstChild->setAttribute('data-max-strings', $component->getMaxStrings()); } if ($component->hasExpectedLines() === true) { $fragment->firstChild->setAttribute('data-expected-lines', $component->getExpectedLines()); } }
/** * Set the format of the text entered by the candidate. * * @param integer $format A value from the TextFormat enumeration. * @throws InvalidArgumentException If $format is not a value from the TextFormat enumeration. */ public function setFormat($format) { if (in_array($format, TextFormat::asArray()) === true) { $this->format = $format; } else { $msg = "The 'format' argument must be a value from the TextFormat enumeration, '" . gettype($format) . "' given."; throw new InvalidArgumentException($msg); } }
/** * Unmarshall a DOMElement object corresponding to a textEntryInteraction/extendedTextInteraction element. * * @param DOMElement $element A DOMElement object. * @return QtiComponent A TextEntryInteraction/ExtendedTextInteraction object. * @throws UnmarshallingException */ protected function unmarshall(DOMElement $element) { if (($responseIdentifier = self::getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) { try { $class = 'qtism\\data\\content\\interactions\\' . ucfirst($element->localName); $component = new $class($responseIdentifier); } catch (InvalidArgumentException $e) { $msg = "The value '{$responseIdentifier}' of the 'responseIdentifier' attribute of the '" . $element->localName . "' element is not a valid identifier."; throw new UnmarshallingException($msg, $element, $e); } if (($base = self::getDOMElementAttributeAs($element, 'base', 'integer')) !== null) { $component->setBase($base); } if (($stringIdentifier = self::getDOMElementAttributeAs($element, 'stringIdentifier')) !== null) { $component->setStringIdentifier($stringIdentifier); } if (($expectedLength = self::getDOMElementAttributeAs($element, 'expectedLength', 'integer')) !== null) { $component->setExpectedLength($expectedLength); } if (($patternMask = self::getDOMElementAttributeAs($element, 'patternMask')) !== null) { $component->setPatternMask($patternMask); } if (($placeholderText = self::getDOMElementAttributeAs($element, 'placeholderText')) !== null) { $component->setPlaceholderText($placeholderText); } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } if ($element->localName === 'extendedTextInteraction') { if (($maxStrings = self::getDOMElementAttributeAs($element, 'maxStrings', 'integer')) !== null) { $component->setMaxStrings($maxStrings); } if (($minStrings = self::getDOMElementAttributeAs($element, 'minStrings', 'integer')) !== null) { $component->setMinStrings($minStrings); } if (($expectedLines = self::getDOMElementAttributeAs($element, 'expectedLines', 'integer')) !== null) { $component->setExpectedLines($expectedLines); } if (($format = self::getDOMElementAttributeAs($element, 'format')) !== null) { $component->setFormat(TextFormat::getConstantByName($format)); } $promptElts = self::getChildElementsByTagName($element, 'prompt'); if (count($promptElts) > 0) { $component->setPrompt($this->getMarshallerFactory()->createMarshaller($promptElts[0])->unmarshall($promptElts[0])); } } self::fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory 'responseIdentifier' attribute is missing from the '" . $element->localName . "' element."; throw new UnmarshallingException($msg, $element); } }