public function build($validation) { $mapping = new Mapping($this->buildMapEntryCollection($validation)); $mapping->setLowerBound(0.0); $mapping->setUpperBound($this->getUpperBound($validation)); $mapping->setDefaultValue(0.0); return $mapping; }
/** * Unmarshall a DOMElement object corresponding to a QTI mapping element. * * @param \DOMElement $element A DOMElement object. * @return \qtism\data\QtiComponent A Mapping object. * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException */ protected function unmarshall(DOMElement $element) { $mapEntriesElts = self::getChildElementsByTagName($element, 'mapEntry'); $mapEntries = new MapEntryCollection(); foreach ($mapEntriesElts as $mapEntryElt) { $marshaller = $this->getMarshallerFactory()->createMarshaller($mapEntryElt, array($this->getBaseType())); $mapEntries[] = $marshaller->unmarshall($mapEntryElt); } try { $object = new Mapping($mapEntries); if (($defaultValue = static::getDOMElementAttributeAs($element, 'defaultValue', 'float')) !== null) { $object->setDefaultValue($defaultValue); } if (($lowerBound = static::getDOMElementAttributeAs($element, 'lowerBound', 'float')) !== null) { $object->setLowerBound($lowerBound); } if (($upperBound = static::getDOMElementAttributeAs($element, 'upperBound', 'float')) !== null) { $object->setUpperBound($upperBound); } return $object; } catch (InvalidArgumentException $e) { $msg = "A 'mapping' element must contain at least one 'mapEntry' element. None found"; throw new UnmarshallingException($msg, $element, $e); } }