/** * Update all the item files found within the $itemRootPath * @param boolean $changeItemContent - tells if the item files will be written with the updated content or not * @return array of modified item instances */ public function update($changeItemContent = false) { $returnValue = array(); $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->itemPath), RecursiveIteratorIterator::SELF_FIRST); $i = 0; $fixed = 0; foreach ($objects as $itemFile => $cursor) { if (is_file($itemFile)) { $this->checkedFiles[$itemFile] = false; if (basename($itemFile) === 'qti.xml') { $i++; $xml = new \DOMDocument(); $xml->load($itemFile); $parser = new ParserFactory($xml); $item = $parser->load(); \common_Logger::i('checking item #' . $i . ' id:' . $item->attr('identifier') . ' file:' . $itemFile); if ($this->updateItem($item, $itemFile)) { $this->checkedFiles[$itemFile] = true; $returnValue[$itemFile] = $item; \common_Logger::i('fixed required for #' . $i . ' id:' . $item->attr('identifier') . ' file:' . $itemFile); if ($changeItemContent) { $fixed++; \common_Logger::i('item fixed #' . $i . ' id:' . $item->attr('identifier') . ' file:' . $itemFile); file_put_contents($itemFile, $item->toXML()); } } } } } \common_Logger::i('total item fixed : ' . $fixed); return $returnValue; }
/** * @param string $file * @param string $expected * @dataProvider findNamespaceProvider */ public function testFindNamespace($file, $expected) { $xml = new \DOMDocument(); $xml->load($file); $parser = new ParserFactory($xml); $parser->setItem(new Item([])); $this->assertEquals($expected, $parser->findNamespace('MathML')); }
public function feed(ParserFactory $parser, DOMElement $data) { $ns = $parser->getPicNamespace(); $pciNodes = $parser->queryXPathChildren(array('portableInfoControl'), $data, $ns); if (!$pciNodes->length) { throw new QtiModelException('no portableInfoControl node found'); } $typeIdentifier = $pciNodes->item(0)->getAttribute('infoControlTypeIdentifier'); if (empty($typeIdentifier)) { throw new QtiModelException('the type identifier of the pic is missing'); } else { $this->setTypeIdentifier($typeIdentifier); } $this->setEntryPoint($pciNodes->item(0)->getAttribute('hook')); $version = $pciNodes->item(0)->getAttribute('version'); if ($version) { $this->setVersion($version); } $libNodes = $parser->queryXPathChildren(array('portableInfoControl', 'resources', 'libraries', 'lib'), $data, $ns); $libs = array(); foreach ($libNodes as $libNode) { $libs[] = $libNode->getAttribute('id'); } $this->setLibraries($libs); $stylesheetNodes = $parser->queryXPathChildren(array('portableInfoControl', 'resources', 'stylesheets', 'link'), $data, $ns); $stylesheets = array(); foreach ($stylesheetNodes as $styleNode) { $stylesheets[] = $styleNode->getAttribute('href'); } $this->setStylesheets($stylesheets); $mediaNodes = $parser->queryXPathChildren(array('portableInfoControl', 'resources', 'mediaFiles', 'file'), $data, $ns); $media = array(); foreach ($mediaNodes as $mediaNode) { $media[] = $mediaNode->getAttribute('src'); } $this->setMediaFiles($media); $propertyNodes = $parser->queryXPathChildren(array('portableInfoControl', 'properties'), $data, $ns); if ($propertyNodes->length) { $properties = $this->extractProperties($propertyNodes->item(0), $ns); $this->setProperties($properties); } $markupNodes = $parser->queryXPathChildren(array('portableInfoControl', 'markup'), $data, $ns); if ($markupNodes->length) { $markup = $parser->getBodyData($markupNodes->item(0), true, true); $this->setMarkup($markup); } }
/** * Feed the pci instance with data provided in the pci dom node * * @param \oat\taoQtiItem\model\qti\ParserFactory $parser * @param DOMElement $data */ public function feed(ParserFactory $parser, DOMElement $data) { $ns = $parser->getPciNamespace(); $pciNodes = $parser->queryXPathChildren(array('portableCustomInteraction'), $data, $ns); if ($pciNodes->length) { $typeIdentifier = $pciNodes->item(0)->getAttribute('customInteractionTypeIdentifier'); if (empty($typeIdentifier)) { throw new QtiModelException('the type identifier of the pci is missing'); } else { $this->setTypeIdentifier($typeIdentifier); } $entryPoint = $pciNodes->item(0)->getAttribute('hook'); if (empty($entryPoint)) { throw new QtiModelException('the entry point of the pci is missing'); } else { $this->setEntryPoint($entryPoint); } } $libNodes = $parser->queryXPathChildren(array('portableCustomInteraction', 'resources', 'libraries', 'lib'), $data, $ns); $libs = array(); foreach ($libNodes as $libNode) { $libs[] = $libNode->getAttribute('id'); } $this->setLibraries($libs); $propertyNodes = $parser->queryXPathChildren(array('portableCustomInteraction', 'properties'), $data, $ns); if ($propertyNodes->length) { $properties = $this->extractPciProperties($propertyNodes->item(0), $ns); $this->setProperties($properties); } $markupNodes = $parser->queryXPathChildren(array('portableCustomInteraction', 'markup'), $data, $ns); if ($markupNodes->length) { $markup = $parser->getBodyData($markupNodes->item(0), true); $this->setMarkup($markup); } }
/** * load the file content, parse it and build the a QTI_Item instance * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @param boolean resolveXInclude * @return \oat\taoQtiItem\model\qti\Item */ public function load($resolveXInclude = false) { $returnValue = null; if (!$this->valid) { libxml_use_internal_errors(true); //retrieve errors if no validation has been done previously } //load it using the DOMDocument library $xml = new DOMDocument(); switch ($this->sourceType) { case self::SOURCE_FILE: $xml->load($this->source); break; case self::SOURCE_URL: $xmlContent = tao_helpers_Request::load($this->source, true); $xml->loadXML($xmlContent); break; case self::SOURCE_STRING: $xml->loadXML($this->source); break; } if ($xml !== false) { $basePath = ''; if ($this->sourceType == self::SOURCE_FILE || $this->sourceType == self::SOURCE_URL) { $basePath = dirname($this->source) . '/'; } //build the item from the xml $parserFactory = new ParserFactory($xml, $basePath); try { $returnValue = $parserFactory->load(); } catch (UnsupportedQtiElement $e) { $this->addError($e); } if (!$this->valid) { $this->valid = true; libxml_clear_errors(); } } else { if (!$this->valid) { $this->addErrors(libxml_get_errors()); libxml_clear_errors(); } } return $returnValue; }
/** * load an xml string into the body of the XInclude * * @param \oat\taoQtiItem\model\qti\XInclude $xinclude * @param string $filePath * @throws XIncludeException */ private function loadXInclude(XInclude $xinclude, $filePath) { //load DOMDocument $xml = new DOMDocument(); $loadSuccess = $xml->load($filePath); $node = $xml->documentElement; if ($loadSuccess && !is_null($node)) { //parse the href content $parser = new ParserFactory($xml); $parser->loadContainerStatic($node, $xinclude->getBody()); } else { throw new XIncludeException('Cannot load the XInclude DOM XML', $xinclude); } }
public function feed(ParserFactory $parser, DOMElement $data) { $ns = $parser->getPicNamespace(); $pciNodes = $parser->queryXPathChildren(array('portableInfoControl'), $data, $ns); if ($pciNodes->length) { $typeIdentifier = $pciNodes->item(0)->getAttribute('infoControlTypeIdentifier'); $this->setTypeIdentifier($typeIdentifier); $entryPoint = $pciNodes->item(0)->getAttribute('hook'); $this->setEntryPoint($entryPoint); } $libNodes = $parser->queryXPathChildren(array('portableInfoControl', 'resources', 'libraries', 'lib'), $data, $ns); $libs = array(); foreach ($libNodes as $libNode) { $libs[] = $libNode->getAttribute('id'); } $this->setLibraries($libs); $propertyNodes = $parser->queryXPathChildren(array('portableInfoControl', 'properties'), $data, $ns); if ($propertyNodes->length) { $properties = $this->extractPciProperties($propertyNodes->item(0), $ns); $this->setProperties($properties); } $markupNodes = $parser->queryXPathChildren(array('portableInfoControl', 'markup'), $data, $ns); if ($markupNodes->length) { $markup = $parser->getBodyData($markupNodes->item(0), true, true); $this->setMarkup($markup); } }
public function feed(ParserFactory $parser, DOMElement $data) { $markup = $parser->getBodyData($data->item(0), true); $this->setMarkup($markup); }