public function map(array $organisationElements)
 {
     $organisations = [];
     foreach ($organisationElements as $organisationElement) {
         $organisation = new Organization();
         $organisation->setIdentifier(Marshaller::getDOMElementAttributeAs($organisationElement, 'identifier'));
         $organisation->setStructure(Marshaller::getDOMElementAttributeAs($organisationElement, 'structure'));
         $titleElements = Marshaller::getChildElementsByTagName($organisationElement, 'title');
         if (count($titleElements) >= 1) {
             $organisation->setTitle($titleElements[0]->nodeValue);
         }
         $itemElements = Marshaller::getChildElementsByTagName($organisationElement, 'item');
         $items = [];
         foreach ($itemElements as $itemElement) {
             $item = new Item();
             $item->setTitle(Marshaller::getChildElementsByTagName($itemElement, 'title'));
             $item->setIdentifier(Marshaller::getDOMElementAttributeAs($itemElement, 'identifier'));
             $item->setIdentifierref(Marshaller::getDOMElementAttributeAs($itemElement, 'identifierref'));
             $item->setIsvisible(Marshaller::getDOMElementAttributeAs($itemElement, 'isvisible'));
             $items[] = $item;
         }
         $organisation->setItems($items);
         $organisations[] = $organisation;
     }
     return $organisations;
 }
 /**
  * Parse an array of DOMElement to array of Dependency models
  *
  * @param [DOMElement]  $dependencyListElements
  * @return array
  */
 public function mapDependencyElements(array $dependencyListElements)
 {
     $dependencies = [];
     if (is_array($dependencyListElements)) {
         foreach ($dependencyListElements as $dependencyElement) {
             $dependency = new Dependency();
             $dependency->setIdentifierref(Marshaller::getDOMElementAttributeAs($dependencyElement, 'identifierref'));
             $dependencies[] = $dependency;
         }
     }
     return $dependencies;
 }
 protected function appendChildren(DOMDocumentFragment $fragment, QtiComponent $component, $base = '')
 {
     parent::appendChildren($fragment, $component, $base);
     // Retrieve the two rendered simpleMatchSets and shuffle if needed.
     $currentSet = 0;
     $choiceElts = array();
     $simpleMatchSetElts = array();
     for ($i = 0; $i < $fragment->firstChild->childNodes->length; $i++) {
         $n = $fragment->firstChild->childNodes->item($i);
         if (Utils::hasClass($n, 'qti-simpleMatchSet') === true) {
             $simpleMatchSetElts[] = $n;
             $sets = $component->getSimpleMatchSets();
             if ($this->getRenderingEngine()->mustShuffle() === true) {
                 Utils::shuffle($n, new ShufflableCollection($sets[$currentSet]->getSimpleAssociableChoices()->getArrayCopy()));
             }
             // Retrieve the two content of the two simpleMatchSets, separately.
             $choiceElts[] = Marshaller::getChildElementsByTagName($n, 'div');
             $currentSet++;
         }
     }
     // simpleMatchSet class cannot be rendered into a table :/
     foreach ($simpleMatchSetElts as $sms) {
         $fragment->firstChild->removeChild($sms);
     }
     $table = $fragment->ownerDocument->createElement('table');
     $fragment->firstChild->appendChild($table);
     // Build the table header.
     $tr = $fragment->ownerDocument->createElement('tr');
     $table->appendChild($tr);
     // Empty upper left cell.
     $tr->appendChild($fragment->ownerDocument->createElement('th'));
     for ($i = 0; $i < count($choiceElts[1]); $i++) {
         $tr->appendChild(XmlUtils::changeElementName($choiceElts[1][$i], 'th'));
     }
     // Build all remaining rows.
     for ($i = 0; $i < count($choiceElts[0]); $i++) {
         $tr = $fragment->ownerDocument->createElement('tr');
         $tr->appendChild(XmlUtils::changeElementName($choiceElts[0][$i], 'th'));
         $table->appendChild($tr);
         for ($j = 0; $j < count($choiceElts[1]); $j++) {
             $input = $fragment->ownerDocument->createElement('input');
             $input->setAttribute('type', 'checkbox');
             $td = $fragment->ownerDocument->createElement('td');
             $td->appendChild($input);
             $tr->appendChild($td);
         }
     }
 }
 public function parseManifestElement(\DOMElement $rootElement)
 {
     // Manifest mapping start!
     $manifest = new Manifest();
     $manifest->setIdentifier(Marshaller::getDOMElementAttributeAs($rootElement, 'identifier'));
     // Mapping <resource>(s) to Resource model
     $resourcesElement = Marshaller::getChildElementsByTagName($rootElement, 'resources');
     if (!empty($resourcesElement)) {
         if (count($resourcesElement) !== 1) {
             throw new MappingException('Resources tag must occur once');
         }
         $resourceMapper = new ResourcesMapper();
         $resourcesListElements = Marshaller::getChildElementsByTagName($resourcesElement[0], 'resource');
         $resources = $resourceMapper->map($resourcesListElements);
         $manifest->setResources($resources);
     }
     // Mapping <organisation>(s) to Organisation model
     $organizationElements = Marshaller::getChildElementsByTagName($rootElement, 'organizations');
     if (!empty($organizationElements)) {
         if (count($organizationElements) !== 1) {
             throw new MappingException('Organisations tag must occur once');
         }
         $organisationsMapper = new OrganizationsMapper();
         $organisationListElements = Marshaller::getChildElementsByTagName($organizationElements[0], 'organization');
         $organisations = $organisationsMapper->map($organisationListElements);
         $manifest->setOrganizations($organisations);
     }
     // Mapping package Metadata
     $metadataElement = Marshaller::getChildElementsByTagName($rootElement, 'metadata');
     if (!empty($metadataElement)) {
         if (count($metadataElement) !== 1) {
             throw new MappingException('Metadata tag must occur once');
         }
         $metadataMapper = new MetadataMapper();
         $manifest->setMetadata($metadataMapper->map($metadataElement[0]));
     }
     // Mapping sub-manifest
     $subManifestElement = Marshaller::getChildElementsByTagName($rootElement, 'manifest');
     if (!empty($subManifestElement)) {
         if (count($subManifestElement) !== 1) {
             throw new MappingException('Manifest tag must occur once');
         }
         $manifest->setManifest($this->parseManifestElement($subManifestElement[0]));
     }
     return $manifest;
 }
 /**
  * Create a new DefaultValueMarshaller object.
  * 
  * @param string $version The QTI version number on which the Marshaller operates e.g. '2.1'.
  * @param integer $baseType The baseType of the Variable holding this DefaultValue.
  */
 public function __construct($version, $baseType = -1)
 {
     parent::__construct($version);
     $this->setBaseType($baseType);
 }
 /**
  * @see \qtism\runtime\rendering\markup\xhtml\AbstractXhtmlRenderer::appendChildren()
  */
 protected function appendChildren(DOMDocumentFragment $fragment, QtiComponent $component, $base = '')
 {
     parent::appendChildren($fragment, $component, $base);
     // Retrieve the two rendered simpleMatchSets and shuffle if needed.
     $currentSet = 0;
     $choiceElts = array();
     $simpleMatchSetElts = array();
     for ($i = 0; $i < $fragment->firstChild->childNodes->length; $i++) {
         $n = $fragment->firstChild->childNodes->item($i);
         if (Utils::hasClass($n, 'qti-simpleMatchSet') === true) {
             $simpleMatchSetElts[] = $n;
             $sets = $component->getSimpleMatchSets();
             if ($this->getRenderingEngine()->getShufflingPolicy() === AbstractMarkupRenderingEngine::CONTEXT_AWARE && $component->mustShuffle()) {
                 Utils::shuffle($n, new ShufflableCollection($sets[$currentSet]->getSimpleAssociableChoices()->getArrayCopy()));
             }
             // Retrieve the two content of the two simpleMatchSets, separately.
             $choiceElts[] = Marshaller::getChildElementsByTagName($n, 'li');
             $currentSet++;
         }
     }
     // simpleMatchSet class cannot be rendered into a table :/
     foreach ($simpleMatchSetElts as $sms) {
         $fragment->firstChild->removeChild($sms);
     }
     $table = $fragment->ownerDocument->createElement('table');
     $fragment->firstChild->appendChild($table);
     // Build the table header.
     $tr = $fragment->ownerDocument->createElement('tr');
     $table->appendChild($tr);
     // Empty upper left cell.
     $tr->appendChild($fragment->ownerDocument->createElement('th'));
     $ifVerticalStatementsStorage = array();
     for ($i = 0; $i < count($choiceElts[1]); $i++) {
         $ifStatements = Utils::extractStatements($choiceElts[1][$i], Utils::EXTRACT_IF);
         $incStatements = Utils::extractStatements($choiceElts[1][$i], Utils::EXTRACT_INCLUDE);
         if (empty($incStatements) === false) {
             $tr->appendChild($incStatements[0]);
         }
         if (empty($ifStatements) === false) {
             $ifVerticalStatementsStorage[$i] = $ifStatements;
             $tr->appendChild($ifStatements[0]);
         }
         $th = XmlUtils::changeElementName($choiceElts[1][$i], 'th');
         $tr->appendChild($th);
         if (empty($incStatements) === false) {
             $th->parentNode->insertBefore($incStatements[1], $th->nextSibling);
         }
         if (empty($ifStatements) === false) {
             $th->parentNode->insertBefore($ifStatements[1], $th->nextSibling);
         }
     }
     // Build all remaining rows.
     for ($i = 0; $i < count($choiceElts[0]); $i++) {
         $tr = $fragment->ownerDocument->createElement('tr');
         $ifStatements = Utils::extractStatements($choiceElts[0][$i], Utils::EXTRACT_IF);
         $incStatements = Utils::extractStatements($choiceElts[0][$i], Utils::EXTRACT_INCLUDE);
         $th = XmlUtils::changeElementName($choiceElts[0][$i], 'th');
         $tr->appendChild($th);
         $table->appendChild($tr);
         if (empty($incStatements) === false) {
             $tr->parentNode->insertBefore($incStatements[0], $tr);
         }
         if (empty($ifStatements) === false) {
             $tr->parentNode->insertBefore($ifStatements[0], $tr);
         }
         for ($j = 0; $j < count($choiceElts[1]); $j++) {
             $input = $fragment->ownerDocument->createElement('input');
             $input->setAttribute('type', 'checkbox');
             $td = $fragment->ownerDocument->createElement('td');
             $td->appendChild($input);
             $tr->appendChild($td);
             if (isset($ifVerticalStatementsStorage[$j])) {
                 $td->parentNode->insertBefore($ifVerticalStatementsStorage[$j][0]->cloneNode(), $td);
                 $td->parentNode->insertBefore($ifVerticalStatementsStorage[$j][1]->cloneNode(), $td->nextSibling);
             }
         }
         if (empty($incStatements) === false && isset($td)) {
             $tr->parentNode->insertBefore($incStatements[1], $tr->nextSibling);
         }
         if (empty($ifStatements) === false && isset($td)) {
             $tr->parentNode->insertBefore($ifStatements[1], $tr->nextSibling);
         }
     }
 }
示例#7
0
 /**
  * Create a new RecursiveMarshaller object.
  * 
  * @param string $version The QTI version number on which the Marshaller operates e.g. '2.1'.
  */
 public function __construct($version)
 {
     parent::__construct($version);
 }
 /**
  * @depends testGetXmlBase
  */
 public function testSetXmlBase()
 {
     $dom = new DOMDocument('1.0');
     $dom->loadXML('<foo><bar>2000</bar><baz>f****d up beyond all recognition</baz></foo>');
     $foo = $dom->getElementsByTagName('foo')->item(0);
     $bar = $dom->getElementsByTagName('bar')->item(0);
     $baz = $dom->getElementsByTagName('baz')->item(0);
     $this->assertFalse(Marshaller::getXmlBase($foo));
     $this->assertFalse(Marshaller::getXmlBase($bar));
     $this->assertFalse(Marshaller::getXmlBase($baz));
     Marshaller::setXmlBase($bar, 'http://my-new-base.com');
     $this->assertFalse(Marshaller::getXmlBase($foo));
     $this->assertEquals('http://my-new-base.com', Marshaller::getXmlBase($bar));
     $this->assertFalse(Marshaller::getXmlBase($baz));
 }