/** * 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; }
/** * 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; }