/** * Import XML * * @param * @return */ function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping) { // Container import => test object already created include_once "./Modules/Test/classes/class.ilObjTest.php"; ilObjTest::_setImportDirectory($this->getImportDirectory()); if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) { $newObj = ilObjectFactory::getInstanceByObjId($new_id, false); } else { // Shouldn't happen $GLOBALS['ilLog']->write(__METHOD__ . ': Called in non container mode'); return false; } list($xml_file, $qti_file) = $this->parseXmlFileNames(); if (!@file_exists($xml_file)) { $GLOBALS['ilLog']->write(__METHOD__ . ': Cannot find xml definition: ' . $xml_file); return false; } if (!@file_exists($qti_file)) { $GLOBALS['ilLog']->write(__METHOD__ . ': Cannot find xml definition: ' . $qti_file); return false; } // FIXME: Copied from ilObjTestGUI::importVerifiedFileObject // TODO: move all logic to ilObjTest::importVerifiedFile and call // this method from ilObjTestGUI and ilTestImporter $newObj->mark_schema->flush(); // Important: The container question pool is the test object implicitly. If we do not pass a valid object id here, there will be problems concerning // filesystem path determinations $qpl_id = $newObj->getId(); // start parsing of QTI files include_once "./Services/QTI/classes/class.ilQTIParser.php"; $qtiParser = new ilQTIParser($qti_file, IL_MO_PARSE_QTI, $qpl_id, array()); $qtiParser->setTestObject($newObj); $result = $qtiParser->startParsing(); $newObj->saveToDb(); // import page data include_once "./Modules/LearningModule/classes/class.ilContObjParser.php"; $contParser = new ilContObjParser($newObj, $xml_file, basename($this->getImportDirectory())); $contParser->setQuestionMapping($qtiParser->getImportMapping()); $contParser->startParsing(); $a_mapping->addMapping("Modules/Test", "tst", $a_id, $newObj->getId()); ilObjTest::_setImportDirectory(); }
/** * imports question(s) into the questionpool (after verification) */ function importVerifiedFileObject() { include_once "./Modules/Test/classes/class.ilObjTest.php"; // create new questionpool object $newObj = new ilObjTest(0, true); // set type of questionpool object $newObj->setType($_GET["new_type"]); // set title of questionpool object to "dummy" $newObj->setTitle("dummy"); // set description of questionpool object $newObj->setDescription("test import"); // create the questionpool class in the ILIAS database (object_data table) $newObj->create(true); // create a reference for the questionpool object in the ILIAS database (object_reference table) $newObj->createReference(); // put the questionpool object in the administration tree $newObj->putInTree($_GET["ref_id"]); // get default permissions and set the permissions for the questionpool object $newObj->setPermissions($_GET["ref_id"]); // notify the questionpool object and all its parent objects that a "new" object was created $newObj->notify("new", $_GET["ref_id"], $_GET["parent_non_rbac_id"], $_GET["ref_id"], $newObj->getRefId()); // empty mark schema $newObj->mark_schema->flush(); // start parsing of QTI files include_once "./Services/QTI/classes/class.ilQTIParser.php"; // Handle selection of "no questionpool" as qpl_id = -1 -> use test object id instead. // TODO: chek if empty strings in $_POST["qpl_id"] relates to a bug or not if ($_POST["qpl_id"] == "-1") { $qpl_id = $newObj->id; } else { $qpl_id = $_POST["qpl_id"]; } $qtiParser = new ilQTIParser($_SESSION["tst_import_qti_file"], IL_MO_PARSE_QTI, $qpl_id, $_POST["ident"]); $qtiParser->setTestObject($newObj); $result = $qtiParser->startParsing(); $newObj->saveToDb(); // import page data include_once "./Modules/LearningModule/classes/class.ilContObjParser.php"; $contParser = new ilContObjParser($newObj, $_SESSION["tst_import_xml_file"], $_SESSION["tst_import_subdir"]); $contParser->setQuestionMapping($qtiParser->getImportMapping()); $contParser->startParsing(); // import test results if (@file_exists($_SESSION["tst_import_results_file"])) { include_once "./Modules/Test/classes/class.ilTestResultsImportParser.php"; $results = new ilTestResultsImportParser($_SESSION["tst_import_results_file"], $newObj); $results->startParsing(); } // delete import directory ilUtil::delDir(ilObjTest::_getImportDirectory()); ilUtil::sendSuccess($this->lng->txt("object_imported"), true); $newObj->updateMetaData(); ilUtil::redirect("ilias.php?ref_id=" . $newObj->getRefId() . "&baseClass=ilObjTestGUI"); }
/** * Import lm from directory * * @param * @return */ function importFromDirectory($a_directory, $a_validate = true) { global $lng; // determine filename of xml file $subdir = basename($a_directory); $xml_file = $a_directory . "/" . $subdir . ".xml"; // check directory exists within zip file if (!is_dir($a_directory)) { return sprintf($lng->txt("cont_no_subdir_in_zip"), $subdir); } // check whether xml file exists within zip file if (!is_file($xml_file)) { return sprintf($lng->txt("cont_zip_file_invalid"), $subdir . "/" . $subdir . ".xml"); } // import questions $qti_file = $a_directory . "/qti.xml"; $qtis = array(); if (is_file($qti_file)) { include_once "./Services/QTI/classes/class.ilQTIParser.php"; include_once "./Modules/Test/classes/class.ilObjTest.php"; $qtiParser = new ilQTIParser($qti_file, IL_MO_VERIFY_QTI, 0, ""); $result = $qtiParser->startParsing(); $founditems =& $qtiParser->getFoundItems(); $testObj = new ilObjTest(0, true); if (count($founditems) > 0) { $qtiParser = new ilQTIParser($qti_file, IL_MO_PARSE_QTI, 0, ""); $qtiParser->setTestObject($testObj); $result = $qtiParser->startParsing(); $qtis = array_merge($qtis, $qtiParser->getImportMapping()); } } include_once "./Modules/LearningModule/classes/class.ilContObjParser.php"; $contParser = new ilContObjParser($this, $xml_file, $subdir, $qmapping); $contParser->setQuestionMapping($qtis); $contParser->startParsing(); ilObject::_writeImportId($this->getId(), $this->getImportId()); $this->MDUpdateListener('General'); // import style $style_file = $a_directory . "/style.xml"; $style_zip_file = $a_directory . "/style.zip"; if (is_file($style_zip_file)) { require_once "./Services/Style/classes/class.ilObjStyleSheet.php"; $style = new ilObjStyleSheet(); $style->import($style_zip_file); $this->writeStyleSheetId($style->getId()); } else { if (is_file($style_file)) { require_once "./Services/Style/classes/class.ilObjStyleSheet.php"; $style = new ilObjStyleSheet(); $style->import($style_file); $this->writeStyleSheetId($style->getId()); } } // // validate if ($a_validate) { $mess = $this->validatePages(); } if ($mess == "") { // handle internal links to this learning module include_once "./Modules/LearningModule/classes/class.ilLMPage.php"; ilLMPage::_handleImportRepositoryLinks($this->getImportId(), $this->getType(), $this->getRefId()); } return $mess; }
public function dbImportSco($slm, $sco, $asset = false) { $qtis = array(); $d = ilUtil::getDir($this->packageFolder); foreach ($d as $f) { //continue; if ($f[type] == 'file' && substr($f[entry], 0, 4) == 'qti_') { include_once "./Services/QTI/classes/class.ilQTIParser.php"; include_once "./Modules/Test/classes/class.ilObjTest.php"; $qtiParser = new ilQTIParser($this->packageFolder . "/" . $f[entry], IL_MO_VERIFY_QTI, 0, ""); $result = $qtiParser->startParsing(); $founditems =& $qtiParser->getFoundItems(); // die(print_r($founditems)); foreach ($founditems as $qp) { $newObj = new ilObjTest(0, true); // This creates a lot of invalid repository objects for each question // question are not repository objects (see e.g. table object_data), alex 29 Sep 2009 // $newObj->setType ( $qp ['type'] ); // $newObj->setTitle ( $qp ['title'] ); // $newObj->create ( true ); // $newObj->createReference (); // $newObj->putInTree ($_GET ["ref_id"]); // $newObj->setPermissions ( $sco->getId ()); // $newObj->notify ("new", $_GET["ref_id"], $sco->getId (), $_GET["ref_id"], $newObj->getRefId () ); // $newObj->mark_schema->flush (); $qtiParser = new ilQTIParser($this->packageFolder . "/" . $f[entry], IL_MO_PARSE_QTI, 0, ""); $qtiParser->setTestObject($newObj); $result = $qtiParser->startParsing(); // $newObj->saveToDb (); $qtis = array_merge($qtis, $qtiParser->getImportMapping()); } } } //exit; include_once 'Modules/Scorm2004/classes/class.ilSCORM2004Page.php'; $doc = new SimpleXMLElement($this->imsmanifest->saveXml()); $l = $doc->xpath("/ContentObject/MetaData"); if ($l[0]) { include_once 'Services/MetaData/classes/class.ilMDXMLCopier.php'; $mdxml =& new ilMDXMLCopier($l[0]->asXML(), $slm->getId(), $sco->getId(), $sco->getType()); $mdxml->startParsing(); $mdxml->getMDObject()->update(); } $l = $doc->xpath("/ContentObject/PageObject"); foreach ($l as $page_xml) { $tnode = $page_xml->xpath('MetaData/General/Title'); $page = new ilSCORM2004PageNode($slm); $page->setTitle($tnode[0]); $page->setSLMId($slm->getId()); $page->create(true); ilSCORM2004Node::putInTree($page, $sco->getId(), $target); $pmd = $page_xml->xpath("MetaData"); if ($pmd[0]) { include_once 'Services/MetaData/classes/class.ilMDXMLCopier.php'; $mdxml =& new ilMDXMLCopier($pmd[0]->asXML(), $slm->getId(), $page->getId(), $page->getType()); $mdxml->startParsing(); $mdxml->getMDObject()->update(); } $tnode = $page_xml->xpath("//MediaObject/MediaAlias | //InteractiveImage/MediaAlias"); foreach ($tnode as $ttnode) { include_once './Services/MediaObjects/classes/class.ilObjMediaObject.php'; $OriginId = $ttnode[OriginId]; $medianodes = $doc->xpath("//MediaObject[MetaData/General/Identifier/@Entry='" . $OriginId . "']"); $medianode = $medianodes[0]; if ($medianode) { $media_object = new ilObjMediaObject(); $media_object->setTitle($medianode->MetaData->General->Title); $media_object->setDescription($medianode->MetaData->General->Description); $media_object->create(false); $mmd = $medianode->xpath("MetaData"); if ($mmd[0]) { include_once 'Services/MetaData/classes/class.ilMDXMLCopier.php'; $mdxml =& new ilMDXMLCopier($mmd[0]->asXML(), 0, $media_object->getId(), $media_object->getType()); $mdxml->startParsing(); $mdxml->getMDObject()->update(); } // determine and create mob directory, move uploaded file to directory $media_object->createDirectory(); $mob_dir = ilObjMediaObject::_getDirectory($media_object->getId()); foreach ($medianode->MediaItem as $xMediaItem) { $media_item =& new ilMediaItem(); $media_object->addMediaItem($media_item); $media_item->setPurpose($xMediaItem[Purpose]); $media_item->setFormat($xMediaItem->Format); $media_item->setLocation($xMediaItem->Location); $media_item->setLocationType($xMediaItem->Location[Type]); $media_item->setWidth($xMediaItem->Layout[Width]); $media_item->setHeight($xMediaItem->Layout[Height]); $media_item->setHAlign($xMediaItem->Layout[HorizontalAlign]); $media_item->setCaption($xMediaItem->Caption); $media_item->setTextRepresentation($xMediaItem->TextRepresentation); $nr = 0; // add map areas (external links only) foreach ($xMediaItem->MapArea as $n => $v) { if ($v->ExtLink[Href] != "") { include_once "./Services/MediaObjects/classes/class.ilMapArea.php"; $ma = new ilMapArea(); $map_area = new ilMapArea(); $map_area->setShape($v[Shape]); $map_area->setCoords($v[Coords]); $map_area->setLinkType(IL_EXT_LINK); $map_area->setTitle($v->ExtLink); $map_area->setHref($v->ExtLink[Href]); $media_item->addMapArea($map_area); } } if ($media_item->getLocationType() == "LocalFile") { // $tmp_name = $this->packageFolder."/objects/".$OriginId."/".$xMediaItem->Location; // copy($tmp_name, $mob_dir."/".$xMediaItem->Location); } } // copy whole directory ilUtil::rCopy($this->packageFolder . "/objects/" . $OriginId, $mob_dir); // alex: fixed media import: these lines have been // behind the next curly bracket which makes it fail // when no medianode is given. (id=0 -> fatal error) ilUtil::renameExecutables($mob_dir); $media_object->update(true); $ttnode[OriginId] = "il__mob_" . $media_object->getId(); } } include_once "./Modules/File/classes/class.ilObjFile.php"; include_once "./Services/Utilities/classes/class.ilFileUtils.php"; include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; $intlinks = $page_xml->xpath("//IntLink"); foreach ($intlinks as $intlink) { if ($intlink[Type] != "File") { continue; } $path = $this->packageFolder . "/objects/" . str_replace('dfile', 'file', $intlink[Target]); if (!is_dir($path)) { continue; } $ffiles = array(); ilFileUtils::recursive_dirscan($path, $ffiles); $filename = $ffiles[file][0]; $fileObj = new ilObjFile(); $fileObj->setType("file"); $fileObj->setTitle(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); $fileObj->setFileName(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); // better use this, mime_content_type is deprecated $fileObj->setFileType(ilObjMediaObject::getMimeType($path . "/" . $filename)); $fileObj->setFileSize(filesize($path . "/" . $filename)); $fileObj->create(); $fileObj->createReference(); //$fileObj->putInTree($_GET["ref_id"]); //$fileObj->setPermissions($slm->getId ()); $fileObj->createDirectory(); $fileObj->storeUnzipedFile($path . "/" . $filename, ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); $intlink[Target] = "il__dfile_" . $fileObj->getId(); } $fileitems = $page_xml->xpath("//FileItem/Identifier"); foreach ($fileitems as $fileitem) { $path = $this->packageFolder . "/objects/" . $fileitem[Entry]; if (!is_dir($path)) { continue; } $ffiles = array(); ilFileUtils::recursive_dirscan($path, $ffiles); $filename = $ffiles[file][0]; $fileObj = new ilObjFile(); $fileObj->setType("file"); $fileObj->setTitle(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); $fileObj->setFileName(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); // better use this, mime_content_type is deprecated $fileObj->setFileType(ilObjMediaObject::getMimeType($path . "/" . $filename)); $fileObj->setFileSize(filesize($path . "/" . $filename)); $fileObj->create(); $fileObj->createReference(); //$fileObj->putInTree($_GET["ref_id"]); //$fileObj->setPermissions($slm->getId ()); $fileObj->createDirectory(); $fileObj->storeUnzipedFile($path . "/" . $filename, ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); $fileitem[Entry] = "il__file_" . $fileObj->getId(); } $pagex = new ilSCORM2004Page($page->getId()); $ddoc = new DOMDocument(); $ddoc->async = false; $ddoc->preserveWhiteSpace = false; $ddoc->formatOutput = false; $ddoc->loadXML($page_xml->asXML()); $xpath = new DOMXPath($ddoc); $tnode = $xpath->query('PageContent'); $t = "<PageObject>"; foreach ($tnode as $ttnode) { $t .= $ddoc->saveXML($ttnode); } $t .= "</PageObject>"; foreach ($qtis as $old => $q) { $t = str_replace($old, 'il__qst_' . $q['pool'], $t); } $pagex->setXMLContent($t); $pagex->updateFromXML(); } }