/**
  * @see \qtism\data\storage\xml\marshalling\RecursiveMarshaller::marshallChildrenKnown()
  */
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $version = $this->getVersion();
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     $this->fillElement($element, $component);
     self::setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
     self::setDOMElementAttribute($element, 'matchMax', $component->getMatchMax());
     if ($component->isFixed() === true) {
         self::setDOMElementAttribute($element, 'fixed', true);
     }
     if ($component->hasTemplateIdentifier() === true && Version::compare($version, '2.1.0', '>=') === true) {
         self::setDOMElementAttribute($element, 'templateIdentifier', $component->getTemplateIdentifier());
     }
     if ($component->getShowHide() !== ShowHide::SHOW && Version::compare($version, '2.1.0', '>=') === true) {
         self::setDOMElementAttribute($element, 'showHide', ShowHide::getNameByConstant(ShowHide::HIDE));
     }
     if ($component->getMatchMin() !== 0 && Version::compare($version, '2.1.0', '>=') === true) {
         self::setDOMElementAttribute($element, 'matchMin', $component->getMatchMin());
     }
     if (Version::compare($version, '2.1.0', '<') === true) {
         $matchGroup = $component->getMatchGroup();
         if (count($matchGroup) > 0) {
             self::setDOMElementAttribute($element, 'matchGroup', implode(' ', $matchGroup->getArrayCopy()));
         }
     }
     foreach ($elements as $e) {
         $element->appendChild($e);
     }
     return $element;
 }
 /**
  * Marshall a RandomFloat object into a DOMElement object.
  *
  * @param \qtism\data\QtiComponent $component A RandomFloat object.
  * @return \DOMElement The according DOMElement object.
  */
 protected function marshall(QtiComponent $component)
 {
     $element = static::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'min', $component->getMin());
     self::setDOMElementAttribute($element, 'max', $component->getMax());
     return $element;
 }
 /**
  * Marshall a VariableMapping object into a DOMElement object.
  *
  * @param \qtism\data\QtiComponent $component A VariableMapping object.
  * @return \DOMElement The according DOMElement object.
  */
 protected function marshall(QtiComponent $component)
 {
     $element = static::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'sourceIdentifier', $component->getSource());
     self::setDOMElementAttribute($element, 'targetIdentifier', $component->getTarget());
     return $element;
 }
Example #4
0
 /**
  * Marshall a BaseValue object into a DOMElement object.
  *
  * @param \qtism\data\QtiComponent $component A BaseValue object.
  * @return \DOMElement The according DOMElement object.
  */
 protected function marshall(QtiComponent $component)
 {
     $element = static::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'baseType', BaseType::getNameByConstant($component->getBaseType()));
     self::setDOMElementValue($element, $component->getValue());
     return $element;
 }
Example #5
0
 /**
  * Marshall a Selection object into a DOMElement object.
  *
  * @param \qtism\data\QtiComponent $component A Selection object.
  * @return \DOMElement The according DOMElement object.
  */
 protected function marshall(QtiComponent $component)
 {
     $element = static::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'select', $component->getSelect());
     self::setDOMElementAttribute($element, 'withReplacement', $component->isWithReplacement());
     return $element;
 }
 /**
  * Marshall a RubricBlock object into a DOMElement object.
  * 
  * @param QtiComponent $component A RubricBlock object.
  * @return DOMElement The according DOMElement object.
  */
 protected function marshall(QtiComponent $component)
 {
     $element = static::getDOMCradle()->createElement($component->getQtiClassName());
     $arrayViews = array();
     foreach ($component->getViews() as $view) {
         $key = array_search($view, View::asArray());
         // replace '_' by the space char.
         $arrayViews[] = strtolower(str_replace("ò", " ", $key));
     }
     if (count($arrayViews) > 0) {
         static::setDOMElementAttribute($element, 'view', implode(" ", $arrayViews));
     }
     if ($component->getUse() != '') {
         static::setDOMElementAttribute($element, 'use', $component->getUse());
     }
     if ($component->hasXmlBase() === true) {
         static::setXmlBase($element, $component->getXmlBase());
     }
     foreach ($component->getContent() as $block) {
         $marshaller = $this->getMarshallerFactory()->createMarshaller($block);
         $element->appendChild($marshaller->marshall($block));
     }
     foreach ($component->getStylesheets() as $stylesheet) {
         $stylesheetMarshaller = $this->getMarshallerFactory()->createMarshaller($stylesheet);
         $element->appendChild($stylesheetMarshaller->marshall($stylesheet));
     }
     self::fillElement($element, $component);
     return $element;
 }
 /**
  * Marshall a RubricBlockRef object to its XML counterpart.
  * 
  * @return DOMElement
  */
 public function marshall(QtiComponent $component)
 {
     $element = self::getDOMCradle()->createElement('rubricBlockRef');
     self::setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
     self::setDOMElementAttribute($element, 'href', $component->getHref());
     return $element;
 }
 /**
  * Marshall a PreCondition object into a DOMElement object.
  * 
  * @param QtiComponent $component A PreCondition object.
  * @return DOMElement The according DOMElement object.
  */
 protected function marshall(QtiComponent $component)
 {
     $element = static::getDOMCradle()->createElement($component->getQtiClassName());
     $marshaller = $this->getMarshallerFactory()->createMarshaller($component->getExpression());
     $element->appendChild($marshaller->marshall($component->getExpression()));
     return $element;
 }
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     $headers = $component->getHeaders();
     if (count($headers) > 0) {
         self::setDOMElementAttribute($element, 'headers', implode(" ", $headers->getArrayCopy()));
     }
     if ($component->hasScope() === true) {
         self::setDOMElementAttribute($element, 'scope', TableCellScope::getNameByConstant($component->getScope()));
     }
     if ($component->hasAbbr() === true) {
         self::setDOMElementAttribute($element, 'abbr', $component->getAbbr());
     }
     if ($component->hasAxis() === true) {
         self::setDOMElementAttribute($element, 'axis', $component->getAxis());
     }
     if ($component->hasRowspan() === true) {
         self::setDOMElementAttribute($element, 'rowspan', $component->getRowspan());
     }
     if ($component->hasColspan() === true) {
         self::setDOMElementAttribute($element, 'colspan', $component->getColspan());
     }
     foreach ($component->getContent() as $c) {
         $marshaller = $this->getMarshallerFactory()->createMarshaller($c);
         $element->appendChild($marshaller->marshall($c));
     }
     self::fillElement($element, $component);
     return $element;
 }
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     self::fillElement($element, $component);
     self::setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
     if ($component->hasPrompt() === true) {
         $element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getPrompt())->marshall($component->getPrompt()));
     }
     if ($component->mustShuffle() !== false) {
         self::setDOMElementAttribute($element, 'shuffle', true);
     }
     if ($component->getMaxAssociations() !== 1) {
         self::setDOMElementAttribute($element, 'maxAssociations', $component->getMaxAssociations());
     }
     if ($component->getMinAssociations() !== 0) {
         self::setDOMElementAttribute($element, 'minAssociations', $component->getMinAssociations());
     }
     if ($component->hasXmlBase() === true) {
         self::setXmlBase($element, $component->getXmlBase());
     }
     foreach ($elements as $e) {
         $element->appendChild($e);
     }
     return $element;
 }
 /**
  * Marshall a Weight object into a DOMElement object.
  * 
  * @param QtiComponent $component A Weight object.
  * @return DOMElement The according DOMElement object.
  */
 protected function marshall(QtiComponent $component)
 {
     $element = static::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
     self::setDOMElementAttribute($element, 'value', $component->getValue());
     return $element;
 }
 public static function buildContent(QtiComponent $component, $content)
 {
     $reflectionClass = new \ReflectionClass($component);
     // TODO: Assumption `setContent` always has content setter on first parameter
     $parameterClass = $reflectionClass->getMethod('setContent')->getParameters()[0]->getClass();
     $contentType = $parameterClass->getShortName();
     try {
         /** @var QtiComponentCollection $content */
         $content = self::validateContent($content);
         if ($contentType === 'InlineCollection') {
             return self::buildInlineCollectionContent($content);
         } elseif ($contentType === 'BlockCollection') {
             return self::buildBlockCollectionContent($content);
         } elseif ($contentType === 'BlockStaticCollection') {
             return self::buildBlockStaticCollectionContent($content);
         } elseif ($contentType === 'FlowCollection') {
             return self::buildFlowCollectionContent($content);
         } elseif ($contentType === 'ObjectFlowCollection') {
             return self::buildFlowCollectionContent($content);
         } elseif ($contentType === 'FlowStaticCollection') {
             return self::buildFlowStaticCollectionContent($content);
         }
         throw new MappingException('Invalid content');
     } catch (\Exception $e) {
         throw new MappingException('Fail mapping `' . $component->getQtiClassName() . '` - ' . $e->getMessage());
     }
 }
 /**
  * Marshall a TemplateProcessing object into a DOMElement object.
  *
  * @param \qtism\data\QtiComponent $component A TemplateProcessing object.
  * @return \DOMElement The according DOMElement object.
  * @throws \qtism\data\storage\xml\marshalling\MarshallingException
  */
 protected function marshall(QtiComponent $component)
 {
     $element = self::getDOMCradle()->createElement('templateProcessing');
     foreach ($component->getTemplateRules() as $templateRule) {
         $element->appendChild($this->getMarshallerFactory()->createMarshaller($templateRule)->marshall($templateRule));
     }
     return $element;
 }
 /**
  * Marshall an AreaMapEntry object into a DOMElement object.
  *
  * @param \qtism\data\QtiComponent $component An AreaMapEntry object.
  * @return \DOMElement The according DOMElement object.
  */
 protected function marshall(QtiComponent $component)
 {
     $element = static::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'shape', Shape::getNameByConstant($component->getShape()));
     self::setDOMElementAttribute($element, 'coords', $component->getCoords());
     self::setDOMElementAttribute($element, 'mappedValue', $component->getMappedValue());
     return $element;
 }
 /**
  * Marshall an InterpolationTableEntry object into a DOMElement object.
  * 
  * @param QtiComponent $component An InterpolationTableEntry object.
  * @return DOMElement The according DOMElement object.
  */
 protected function marshall(QtiComponent $component)
 {
     $element = static::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'sourceValue', $component->getSourceValue());
     self::setDOMElementAttribute($element, 'targetValue', $component->getTargetValue());
     self::setDOMElementAttribute($element, 'includeBoundary', $component->doesIncludeBoundary());
     return $element;
 }
 /**
  * @see \qtism\data\storage\xml\marshalling\RecursiveMarshaller::marshallChildrenKnown()
  */
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     foreach ($elements as $e) {
         $element->appendChild($e);
     }
     return $element;
 }
 /**
  * Unmarshall an FieldValue object into a QTI fieldValue element.
  * 
  * @param QtiComponent The FieldValue object to marshall.
  * @param array An array of child DOMEelement objects.
  * @return DOMElement The marshalled QTI fieldValue element.
  */
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'fieldIdentifier', $component->getFieldIdentifier());
     foreach ($elements as $elt) {
         $element->appendChild($elt);
     }
     return $element;
 }
Example #18
0
 /**
  * Marshall a Br object into a DOMElement object.
  *
  * @param \qtism\data\QtiComponent $component A Br object.
  * @return \DOMElement The according DOMElement object.
  * @throws \qtism\data\storage\xml\marshalling\MarshallingException
  */
 protected function marshall(QtiComponent $component)
 {
     $element = self::getDOMCradle()->createElement('br');
     if ($component->hasXmlBase() === true) {
         self::setXmlBase($element, $component->setXmlBase());
     }
     $this->fillElement($element, $component);
     return $element;
 }
 /**
  * Marshall a Col object into a DOMElement object.
  * 
  * @param QtiComponent $component A Col object.
  * @return DOMElement The according DOMElement object.
  * @throws MarshallingException
  */
 protected function marshall(QtiComponent $component)
 {
     $element = self::getDOMCradle()->createElement('col');
     if ($component->getSpan() !== 1) {
         self::setDOMElementAttribute($element, 'span', $component->getSpan());
     }
     self::fillElement($element, $component);
     return $element;
 }
 /**
  * Marshall an OutcomeProcessing object into a DOMElement object.
  *
  * @param \qtism\data\QtiComponent $component An OutcomeProcessing object.
  * @return \DOMElement The according DOMElement object.
  * @throws \qtism\data\storage\xml\marshalling\MarshallingException
  */
 protected function marshall(QtiComponent $component)
 {
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     foreach ($component->getOutcomeRules() as $outcomeRule) {
         $marshaller = $this->getMarshallerFactory()->createMarshaller($outcomeRule);
         $element->appendChild($marshaller->marshall($outcomeRule));
     }
     return $element;
 }
 /**
  * Unmarshall a StatsOperator object into a QTI statsOperator element.
  *
  * @param \qtism\data\QtiComponent $component The StatsOperator object to marshall.
  * @param array $elements An array of child DOMEelement objects.
  * @return \DOMElement The marshalled QTI statsOperator element.
  */
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'name', Statistics::getNameByConstant($component->getName()));
     foreach ($elements as $elt) {
         $element->appendChild($elt);
     }
     return $element;
 }
 /**
  * Marshall a ShufflingGroup object into a DOMElement object.
  *
  * @param \qtism\data\QtiComponent $component A ShufflingGroup object.
  * @return \DOMElement The according DOMElement object.
  */
 protected function marshall(QtiComponent $component)
 {
     $element = static::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'identifiers', implode(" ", $component->getIdentifiers()->getArrayCopy()));
     $fixedIdentifiers = $component->getFixedIdentifiers();
     if (count($fixedIdentifiers) > 0) {
         self::setDOMElementAttribute($element, 'fixedIdentifiers', implode(" ", $component->getFixedIdentifiers()->getArrayCopy()));
     }
     return $element;
 }
Example #23
0
 /**
  * Marshall a Shuffling object into a DOMElement object.
  *
  * @param \qtism\data\QtiComponent $component A Shuffling object.
  * @return \DOMElement The according DOMElement object.
  */
 protected function marshall(QtiComponent $component)
 {
     $element = static::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
     foreach ($component->getShufflingGroups() as $shufflingGroup) {
         $marshaller = $this->getMarshallerFactory()->createMarshaller($shufflingGroup);
         $element->appendChild($marshaller->marshall($shufflingGroup));
     }
     return $element;
 }
 /**
  * Marshall a TemplateDefault object into a DOMElement object.
  * 
  * @param QtiComponent $component A TemplateDefault object.
  * @return DOMElement The according DOMElement object.
  */
 protected function marshall(QtiComponent $component)
 {
     $element = static::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'templateIdentifier', $component->getTemplateIdentifier());
     $expr = $component->getExpression();
     $exprMarshaller = $this->getMarshallerFactory()->createMarshaller($expr);
     $exprElt = $exprMarshaller->marshall($expr);
     $element->appendChild($exprElt);
     return $element;
 }
 /**
  * Unmarshall a RoundTo object into a QTI roundTo element.
  * 
  * @param QtiComponent The RoundTo object to marshall.
  * @param array An array of child DOMEelement objects.
  * @return DOMElement The marshalled QTI roundTo element.
  */
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'figures', $component->getFigures());
     self::setDOMElementAttribute($element, 'roundingMode', RoundingMode::getNameByConstant($component->getRoundingMode()));
     foreach ($elements as $elt) {
         $element->appendChild($elt);
     }
     return $element;
 }
 /**
  * Marshall a Tbody/Thead/Tfoot object into a DOMElement object.
  * 
  * @param QtiComponent $component A TBody/Thead/Tfoot object.
  * @return DOMElement The according DOMElement object.
  * @throws MarshallingException
  */
 protected function marshall(QtiComponent $component)
 {
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     foreach ($component->getContent() as $tr) {
         $marshaller = $this->getMarshallerFactory()->createMarshaller($tr);
         $element->appendChild($marshaller->marshall($tr));
     }
     self::fillElement($element, $component);
     return $element;
 }
 /**
  * Marshall a Variable object into a DOMElement object.
  * 
  * @param QtiComponent $component A Variable object.
  * @return DOMElement The according DOMElement object.
  */
 protected function marshall(QtiComponent $component)
 {
     $element = static::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
     $weightIdentifier = $component->getWeightIdentifier();
     if (!empty($weightIdentifier)) {
         self::setDOMElementAttribute($element, 'weightIdentifier', $weightIdentifier);
     }
     return $element;
 }
 /**
  * Unmarshall a StringMatch object into a QTI stringMatch element.
  * 
  * @param QtiComponent The StringMatch object to marshall.
  * @param array An array of child DOMEelement objects.
  * @return DOMElement The marshalled QTI stringMatch element.
  */
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'caseSensitive', $component->isCaseSensitive());
     self::setDOMElementAttribute($element, 'substring', $component->mustSubstring());
     foreach ($elements as $elt) {
         $element->appendChild($elt);
     }
     return $element;
 }
 /**
  * Marshall an PositionObjectStage object into a DOMElement object.
  * 
  * @param QtiComponent $component A PositionObjectStage object.
  * @return DOMElement The according DOMElement object.
  * @throws MarshallingException
  */
 protected function marshall(QtiComponent $component)
 {
     $element = self::getDOMCradle()->createElement('positionObjectStage');
     $object = $component->getObject();
     $element->appendChild($this->getMarshallerFactory()->createMarshaller($object)->marshall($object));
     foreach ($component->getPositionObjectInteractions() as $interaction) {
         $element->appendChild($this->getMarshallerFactory()->createMarshaller($interaction)->marshall($interaction));
     }
     return $element;
 }
Example #30
0
 /**
  * Marshall a Gap object into a DOMElement object.
  *
  * @param \qtism\data\QtiComponent $component A Gap object.
  * @return \DOMElement The according DOMElement object.
  * @throws \qtism\data\storage\xml\marshalling\MarshallingException
  */
 protected function marshall(QtiComponent $component)
 {
     $version = $this->getVersion();
     $element = self::getDOMCradle()->createElement('gap');
     self::setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
     if ($component->isFixed() === true) {
         self::setDOMElementAttribute($element, 'fixed', true);
     }
     if (Version::compare($version, '2.1.0', '>=') === true && $component->hasTemplateIdentifier() === true) {
         self::setDOMElementAttribute($element, 'templateIdentifier', $component->getTemplateIdentifier());
     }
     if (Version::compare($version, '2.1.0', '>=') === true && $component->getShowHide() === ShowHide::HIDE) {
         self::setDOMElementAttribute($element, 'showHide', ShowHide::getNameByConstant(ShowHide::HIDE));
     }
     if (Version::compare($version, '2.1.0', '>=') === true && $component->isRequired() === true) {
         self::setDOMElementAttribute($element, 'required', true);
     }
     if (Version::compare($version, '2.1.0', '<') === true) {
         $matchGroup = $component->getMatchGroup();
         if (count($matchGroup) > 0) {
             self::setDOMElementAttribute($element, 'matchGroup', implode(' ', $matchGroup->getArrayCopy()));
         }
     }
     $this->fillElement($element, $component);
     return $element;
 }