/** * Unmarshall a DOMElement object corresponding to a QTI assessmentSectionRef element. * * @param DOMElement $element A DOMElement object. * @return QtiComponent An AssessmentSectionRef object. * @throws UnmarshallingException If the mandatory attribute 'href' is missing. */ protected function unmarshall(DOMElement $element) { $baseComponent = parent::unmarshall($element); if (($href = static::getDOMElementAttributeAs($element, 'href', 'string')) !== null) { $object = new AssessmentSectionRef($baseComponent->getIdentifier(), $href); $object->setRequired($baseComponent->isRequired()); $object->setFixed($baseComponent->isFixed()); $object->setPreConditions($baseComponent->getPreConditions()); $object->setBranchRules($baseComponent->getBranchRules()); $object->setItemSessionControl($baseComponent->getItemSessionControl()); $object->setTimeLimits($baseComponent->getTimeLimits()); return $object; } else { $msg = "Mandatory attribute 'href' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }
/** * Unmarshall a DOMElement object corresponding to a QTI assessmentItemRef element. * * @param DOMElement $element A DOMElement object. * @return QtiComponent An AssessmentItemRef object. * @throws UnmarshallingException If the mandatory attribute 'href' is missing. */ protected function unmarshall(DOMElement $element) { $baseComponent = parent::unmarshall($element); if (($href = static::getDOMElementAttributeAs($element, 'href')) !== null) { $object = new AssessmentItemRef($baseComponent->getIdentifier(), $href); $object->setRequired($baseComponent->isRequired()); $object->setFixed($baseComponent->isFixed()); $object->setPreConditions($baseComponent->getPreConditions()); $object->setBranchRules($baseComponent->getBranchRules()); $object->setItemSessionControl($baseComponent->getItemSessionControl()); $object->setTimeLimits($baseComponent->getTimeLimits()); // Deal with categories. if (($category = static::getDOMElementAttributeAs($element, 'category')) !== null) { $object->setCategories(new IdentifierCollection(explode(" ", $category))); } // Deal with variableMappings. $variableMappingElts = $element->getElementsByTagName('variableMapping'); $variableMappings = new VariableMappingCollection(); for ($i = 0; $i < $variableMappingElts->length; $i++) { $marshaller = $this->getMarshallerFactory()->createMarshaller($variableMappingElts->item($i)); $variableMappings[] = $marshaller->unmarshall($variableMappingElts->item($i)); } $object->setVariableMappings($variableMappings); // Deal with weights. $weightElts = $element->getElementsByTagName('weight'); $weights = new WeightCollection(); for ($i = 0; $i < $weightElts->length; $i++) { $marshaller = $this->getMarshallerFactory()->createMarshaller($weightElts->item($i)); $weights[] = $marshaller->unmarshall($weightElts->item($i)); } $object->setWeights($weights); // Deal with templateDefaults. $templateDefaultElts = $element->getElementsByTagName('templateDefault'); $templateDefaults = new TemplateDefaultCollection(); for ($i = 0; $i < $templateDefaultElts->length; $i++) { $marshaller = $this->getMarshallerFactory()->createMarshaller($templateDefaultElts->item($i)); $templateDefaults[] = $marshaller->unmarshall($templateDefaultElts->item($i)); } $object->setTemplateDefaults($templateDefaults); return $object; } else { $msg = "The mandatory attribute 'href' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }
/** * @see \qtism\data\storage\xml\marshalling\RecursiveMarshaller::marshallChildrenKnown() */ protected function marshallChildrenKnown(QtiComponent $component, array $elements) { $baseMarshaller = new SectionPartMarshaller($this->getVersion()); $element = $baseMarshaller->marshall($component); self::setDOMElementAttribute($element, 'title', $component->getTitle()); self::setDOMElementAttribute($element, 'visible', $component->isVisible()); self::setDOMElementAttribute($element, 'keepTogether', $component->mustKeepTogether()); // Deal with selection element $selection = $component->getSelection(); if (!empty($selection)) { $marshaller = $this->getMarshallerFactory()->createMarshaller($selection); $element->appendChild($marshaller->marshall($selection)); } // Deal with ordering element. $ordering = $component->getOrdering(); if (!empty($ordering)) { $marshaller = $this->getMarshallerFactory()->createMarshaller($ordering); $element->appendChild($marshaller->marshall($ordering)); } // Deal with rubricBlock elements. foreach ($component->getRubricBlocks() as $rubricBlock) { $marshaller = $this->getMarshallerFactory()->createMarshaller($rubricBlock); $element->appendChild($marshaller->marshall($rubricBlock)); } // And finally... // Deal with sectionPart elements that are actually known... foreach ($elements as $elt) { $element->appendChild($elt); } return $element; }