/**
  * 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)
 {
     // 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()
 {
     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");
     }
 }
예제 #4
0
 /**
  * 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;
 }