コード例 #1
0
 /**
  * Import XML
  *
  * @param
  * @return
  */
 function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
 {
     include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
     ilObjQuestionPool::_setImportDirectory($this->getImportDirectory());
     // Container import => test object already created
     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;
     }
     include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
     ilObjQuestionPool::_setImportDirectory($this->getImportDirectory());
     // FIXME: Copied from ilObjQuestionPoolGUI::importVerifiedFileObject
     // TODO: move all logic to ilObjQuestionPoolGUI::importVerifiedFile and call
     // this method from ilObjQuestionPoolGUI and ilTestImporter
     $GLOBALS['ilLog']->write(__METHOD__ . ': xml file: ' . $xml_file . ", qti file:" . $qti_file);
     $newObj->setOnline(true);
     $newObj->saveToDb();
     // start parsing of QTI files
     include_once "./Services/QTI/classes/class.ilQTIParser.php";
     $qtiParser = new ilQTIParser($qti_file, IL_MO_PARSE_QTI, $newObj->getId(), null);
     $result = $qtiParser->startParsing();
     // import page data
     if (strlen($xml_file)) {
         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/TestQuestionPool", "qpl", $a_id, $newObj->getId());
     ilObjQuestionPool::_setImportDirectory(null);
 }
コード例 #2
0
 /**
  * Import XML
  *
  * @param
  * @return
  */
 function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
 {
     if ($a_entity == "glo") {
         // case i container
         if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
             $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
             $xml_file = $this->getImportDirectory() . '/' . basename($this->getImportDirectory()) . '.xml';
             $GLOBALS['ilLog']->write(__METHOD__ . ': Using XML file ' . $xml_file);
         } else {
             if ($new_id = $a_mapping->getMapping('Modules/Glossary', 'glo', "new_id")) {
                 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
                 $xml_file = $this->getImportDirectory() . '/' . basename($this->getImportDirectory()) . '.xml';
                 $GLOBALS['ilLog']->write(__METHOD__ . ': Using XML file ' . $xml_file);
             } else {
                 // Shouldn't happen
                 $GLOBALS['ilLog']->write(__METHOD__ . ': Called in non container mode');
                 $GLOBALS['ilLog']->logStack();
                 return false;
             }
         }
         if (!file_exists($xml_file)) {
             $GLOBALS['ilLog']->write(__METHOD__ . ': ERROR Cannot find ' . $xml_file);
             return false;
         }
         include_once './Modules/LearningModule/classes/class.ilContObjParser.php';
         $contParser = new ilContObjParser($newObj, $xml_file, basename($this->getImportDirectory()));
         $contParser->startParsing();
         ilObject::_writeImportId($newObj->getId(), $newObj->getImportId());
         // write term map for taxonomies to mapping object
         $term_map = $contParser->getGlossaryTermMap();
         foreach ($term_map as $k => $v) {
             $a_mapping->addMapping("Services/Taxonomy", "tax_item", "glo:term:" . $k, $v);
             // this is since 4.3 does not export these ids but 4.4 tax node assignment needs it
             $a_mapping->addMapping("Services/Taxonomy", "tax_item_obj_id", "glo:term:" . $k, $newObj->getId());
             $a_mapping->addMapping("Services/AdvancedMetaData", "advmd_sub_item", "advmd:term:" . $k, $v);
         }
         // ???
         $a_mapping->addMapping("Services/Taxonomy", "tax_item", "glo:term:" . $k, $v);
         $a_mapping->addMapping("Modules/Glossary", "glo", $a_id, $newObj->getId());
         $a_mapping->addMapping("Services/AdvancedMetaData", "parent", $a_id, $newObj->getId());
         $this->current_glo = $newObj;
     }
 }
コード例 #3
0
 /**
  * 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();
 }
コード例 #4
0
 /**
  * imports question(s) into the questionpool (after verification)
  */
 function importVerifiedFileObject()
 {
     if ($_POST["questions_only"] == 1) {
         $newObj =& $this->object;
     } else {
         include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
         // create new questionpool object
         $newObj = new ilObjQuestionPool(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("questionpool 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());
     }
     // start parsing of QTI files
     include_once "./Services/QTI/classes/class.ilQTIParser.php";
     $qtiParser = new ilQTIParser($_SESSION["qpl_import_qti_file"], IL_MO_PARSE_QTI, $newObj->getId(), $_POST["ident"]);
     $result = $qtiParser->startParsing();
     // import page data
     if (strlen($_SESSION["qpl_import_xml_file"])) {
         include_once "./Modules/LearningModule/classes/class.ilContObjParser.php";
         $contParser = new ilContObjParser($newObj, $_SESSION["qpl_import_xml_file"], $_SESSION["qpl_import_subdir"]);
         $contParser->setQuestionMapping($qtiParser->getImportMapping());
         $contParser->startParsing();
     }
     // set another question pool name (if possible)
     $qpl_name = $_POST["qpl_new"];
     if (strcmp($qpl_name, $newObj->getTitle()) != 0 && strlen($qpl_name) > 0) {
         $newObj->setTitle($qpl_name);
         $newObj->update();
     }
     // delete import directory
     include_once "./Services/Utilities/classes/class.ilUtil.php";
     ilUtil::delDir(dirname(ilObjQuestionPool::_getImportDirectory()));
     if ($_POST["questions_only"] == 1) {
         $this->ctrl->redirect($this, "questions");
     } else {
         ilUtil::sendSuccess($this->lng->txt("object_imported"), true);
         ilUtil::redirect("ilias.php?ref_id=" . $newObj->getRefId() . "&baseClass=ilObjQuestionPoolGUI");
     }
 }
コード例 #5
0
ファイル: class.ilObjTestGUI.php プロジェクト: bheyser/qplskl
 /**
  * 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");
 }
コード例 #6
0
 /**
  * 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;
 }
コード例 #7
0
 /**
  * display status information or report errors messages
  * in case of error
  *
  * @access	public
  */
 function importFileObject()
 {
     $new_type = $_REQUEST["new_type"];
     // create permission is already checked in createObject. This check here is done to prevent hacking attempts
     if (!$this->checkPermissionBool("create", "", $new_type)) {
         $ilErr->raiseError($this->lng->txt("no_create_permission"));
     }
     $this->lng->loadLanguageModule($new_type);
     $this->ctrl->setParameter($this, "new_type", $new_type);
     $form = $this->initImportForm($new_type);
     if ($form->checkInput()) {
         $this->ctrl->setParameter($this, "new_type", "");
         $upload = $_FILES["importfile"];
         // create and insert object in objecttree
         include_once "./Modules/Glossary/classes/class.ilObjGlossary.php";
         $newObj = new ilObjGlossary();
         $newObj->setType($new_type);
         $newObj->setTitle($upload["name"]);
         $newObj->create(true);
         $this->putObjectInTree($newObj);
         // create import directory
         $newObj->createImportDirectory();
         // copy uploaded file to import directory
         $file = pathinfo($upload["name"]);
         $full_path = $newObj->getImportDirectory() . "/" . $upload["name"];
         ilUtil::moveUploadedFile($upload["tmp_name"], $upload["name"], $full_path);
         // unzip file
         ilUtil::unzip($full_path);
         // determine filename of xml file
         $subdir = basename($file["basename"], "." . $file["extension"]);
         $xml_file = $newObj->getImportDirectory() . "/" . $subdir . "/" . $subdir . ".xml";
         // check whether this is a new export file.
         // this is the case if manifest.xml exits
         //echo "1-".$newObj->getImportDirectory()."/".$subdir."/manifest.xml"."-";
         if (is_file($newObj->getImportDirectory() . "/" . $subdir . "/manifest.xml")) {
             include_once "./Services/Export/classes/class.ilImport.php";
             $imp = new ilImport((int) $_GET["ref_id"]);
             $map = $imp->getMapping();
             $map->addMapping("Modules/Glossary", "glo", "new_id", $newObj->getId());
             $imp->importObject($newObj, $full_path, $upload["name"], "glo", "Modules/Glossary", true);
             ilUtil::sendSuccess($this->lng->txt("glo_added"), true);
             ilUtil::redirect("ilias.php?baseClass=ilGlossaryEditorGUI&ref_id=" . $newObj->getRefId());
         }
         // check whether subdirectory exists within zip file
         if (!is_dir($newObj->getImportDirectory() . "/" . $subdir)) {
             $this->ilias->raiseError(sprintf($this->lng->txt("cont_no_subdir_in_zip"), $subdir), $this->ilias->error_obj->MESSAGE);
         }
         // check whether xml file exists within zip file
         if (!is_file($xml_file)) {
             $this->ilias->raiseError(sprintf($this->lng->txt("cont_zip_file_invalid"), $subdir . "/" . $subdir . ".xml"), $this->ilias->error_obj->MESSAGE);
         }
         include_once "./Modules/LearningModule/classes/class.ilContObjParser.php";
         $contParser = new ilContObjParser($newObj, $xml_file, $subdir);
         $contParser->startParsing();
         ilObject::_writeImportId($newObj->getId(), $newObj->getImportId());
         // delete import directory
         ilUtil::delDir($newObj->getImportDirectory());
         ilUtil::sendSuccess($this->lng->txt("glo_added"), true);
         ilUtil::redirect("ilias.php?baseClass=ilGlossaryEditorGUI&ref_id=" . $newObj->getRefId());
     }
     // display form to correct errors
     $form->setValuesByPost();
     $tpl->setContent($form->getHtml());
 }
コード例 #8
0
 function importGlossary($slm, $packageFolder)
 {
     global $ilias;
     // create and insert object in objecttree
     include_once "./Modules/Glossary/classes/class.ilObjGlossary.php";
     $newObj = new ilObjGlossary();
     $newObj->setType('glo');
     $newObj->setTitle('');
     $newObj->create(true);
     $newObj->createReference();
     $newObj->putInTree($_GET["ref_id"]);
     $newObj->setPermissions($_GET["ref_id"]);
     $newObj->notify("new", $_GET["ref_id"], $_GET["parent_non_rbac_id"], $_GET["ref_id"], $newObj->getRefId());
     $xml_file = $packageFolder . "/glossary.xml";
     // check whether xml file exists within zip file
     if (!is_file($xml_file)) {
         return;
     }
     include_once "./Modules/LearningModule/classes/class.ilContObjParser.php";
     $contParser = new ilContObjParser($newObj, $xml_file, $packageFolder);
     $contParser->startParsing();
     $newObj->update();
     //ilObject::_writeImportId($newObj->getId(), $newObj->getImportId());
     $slm->setAssignedGlossary($newObj->getId());
     $slm->update();
 }