/** * Check if $value is a valid View enumeration value. * * @throws InvalidArgumentException If $value is not a valid View enumeration value. */ protected function checkType($value) { if (!in_array($value, View::asArray())) { $msg = "The ViewsCollection class only accept View enumeration values, '{$value}' given."; throw new InvalidArgumentException($msg); } }
/** * Marshall an OutcomeDeclaration object into a DOMElement object. * * @param \qtism\data\QtiComponent $component An OutcomeDeclaration object. * @return \DOMElement The according DOMElement object. */ protected function marshall(QtiComponent $component) { $element = parent::marshall($component); $version = $this->getVersion(); // deal with views. // !!! If $arrayViews contain all possible views, it means that the treated // !!! outcome is relevant to all views, as per QTI 2.1 spec. if (Version::compare($version, '2.1.0', '>=') === true && !in_array($component->getViews()->getArrayCopy(), View::asArray())) { $arrayViews = array(); foreach ($component->getViews() as $view) { $arrayViews[] = View::getNameByConstant($view); } if (count($arrayViews) > 0) { static::setDOMElementAttribute($element, 'view', implode(" ", $arrayViews)); } } // deal with interpretation. if ($component->getInterpretation() != '') { static::setDOMElementAttribute($element, 'interpretation', $component->getInterpretation()); } // deal with long interpretation. if ($component->getLongInterpretation() != '') { static::setDOMElementAttribute($element, 'longInterpretation', $component->getLongInterpretation()); } // Deal with normal maximum. if ($component->getNormalMaximum() !== false) { static::setDOMElementAttribute($element, 'normalMaximum', $component->getNormalMaximum()); } // Deal with normal minimum. if (Version::compare($version, '2.1.0', '>=') === true && $component->getNormalMinimum() !== false) { static::setDOMElementAttribute($element, 'normalMinimum', $component->getNormalMinimum()); } // Deal with mastery value. if (Version::compare($version, '2.1.0', '>=') === true && $component->getMasteryValue() !== false) { static::setDOMElementAttribute($element, 'masteryValue', $component->getMasteryValue()); } // Deal with lookup table. if ($component->getLookupTable() != null) { $lookupTableMarshaller = $this->getMarshallerFactory()->createMarshaller($component->getLookupTable(), array($component->getBaseType())); $element->appendChild($lookupTableMarshaller->marshall($component->geTLookupTable())); } return $element; }
/** * Unmarshall a DOMElement object corresponding to a QTI rubrickBlock element. * * @param DOMElement $element A DOMElement object. * @return RubricBlock A RubricBlock object. * @throws UnmarshallingException If the mandatory attribute 'href' is missing from $element. */ protected function unmarshall(DOMElement $element) { // First we retrieve the mandatory views. if (($value = static::getDOMElementAttributeAs($element, 'view', 'string')) !== null) { $viewsArray = explode(" ", $value); $viewsCollection = new ViewCollection(); $ref = View::asArray(); foreach ($viewsArray as $viewString) { $key = strtoupper(str_replace("ò", " ", $viewString)); if (array_key_exists($key, $ref)) { $viewsCollection[] = $ref[$key]; } } $object = new RubricBlock($viewsCollection); if (($value = static::getDOMElementAttributeAs($element, 'use', 'string')) !== null) { $object->setUse($value); } if (($xmlBase = static::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } $stylesheets = new StylesheetCollection(); $content = new FlowStaticCollection(); foreach (self::getChildElements($element, true) as $elt) { if ($elt instanceof DOMText) { $elt = self::getDOMCradle()->createElement('textRun', $elt->wholeText); } $marshaller = $this->getMarshallerFactory()->createMarshaller($elt); $cpt = $marshaller->unmarshall($elt); if ($cpt instanceof Stylesheet) { $stylesheets[] = $cpt; } else { if ($cpt instanceof FlowStatic && !in_array($cpt->getQtiClassName(), array('hottext', 'feedbackBlock', 'feedbackInline', 'rubricBlock', 'infoControl'))) { $content[] = $cpt; } else { $msg = "The 'rubricBlock' cannot contain '" . $cpt->getQtiClassName() . "' elements."; throw new UnmarshallingException($msg, $element); } } } $object->setStylesheets($stylesheets); $object->setContent($content); self::fillBodyElement($object, $element); return $object; } else { $msg = "The mandatory attribute 'views' is missing."; throw new UnmarshallingException($msg, $element); } }