/** * @see \qtism\data\storage\xml\marshalling\RecursiveMarshaller::unmarshallChildrenKnown() */ protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children, AssessmentSection $assessmentSection = null) { $baseMarshaller = new SectionPartMarshaller($this->getVersion()); $baseComponent = $baseMarshaller->unmarshall($element); if (($title = static::getDOMElementAttributeAs($element, 'title')) !== null) { if (($visible = static::getDOMElementAttributeAs($element, 'visible', 'boolean')) !== null) { if (empty($assessmentSection)) { $object = new AssessmentSection($baseComponent->getIdentifier(), $title, $visible); } else { $object = $assessmentSection; $object->setIdentifier($baseComponent->getIdentifier()); $object->setTitle($title); $object->setVisible($visible); } // One day... We will be able to overload methods in PHP... :'( $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 the keepTogether attribute. if (($keepTogether = static::getDOMElementAttributeAs($element, 'keepTogether', 'boolean')) !== null) { $object->setKeepTogether($keepTogether); } // Deal with selection elements. $selectionElements = static::getChildElementsByTagName($element, 'selection'); if (count($selectionElements) == 1) { $marshaller = $this->getMarshallerFactory()->createMarshaller($selectionElements[0]); $object->setSelection($marshaller->unmarshall($selectionElements[0])); } // Deal with ordering elements. $orderingElements = static::getChildElementsByTagName($element, 'ordering'); if (count($orderingElements) == 1) { $marshaller = $this->getMarshallerFactory()->createMarshaller($orderingElements[0]); $object->setOrdering($marshaller->unmarshall($orderingElements[0])); } // Deal with rubrickBlocks. $rubricBlockElements = static::getChildElementsByTagName($element, 'rubricBlock'); if (count($rubricBlockElements) > 0) { $rubricBlocks = new RubricBlockCollection(); for ($i = 0; $i < count($rubricBlockElements); $i++) { $marshaller = $this->getMarshallerFactory()->createMarshaller($rubricBlockElements[$i]); $rubricBlocks[] = $marshaller->unmarshall($rubricBlockElements[$i]); } $object->setRubricBlocks($rubricBlocks); } // Deal with section parts... which are known :) ! $object->setSectionParts($children); return $object; } else { $msg = "The mandatory attribute 'visible' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory attribute 'title' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }
/** * 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); } }