function getImportDirectory()
 {
     return ilObjQuestionPool::_getImportDirectory();
 }
 /**
  * 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");
     }
 }
Ejemplo n.º 3
0
 /**
  * returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir)
  */
 protected function getQplImportArchivDirectory()
 {
     include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
     return ilObjQuestionPool::_getImportDirectory() . '/' . $_SESSION["qpl_import_subdir"];
 }
Ejemplo n.º 4
0
 /**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $now = getdate();
     $maxchars = 0;
     $maxpoints = 0;
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     foreach ($presentation->order as $entry) {
         switch ($entry["type"]) {
             case "response":
                 $response = $presentation->response[$entry["index"]];
                 $rendertype = $response->getRenderType();
                 switch (strtolower(get_class($rendertype))) {
                     case "ilqtirenderfib":
                         $maxchars = $rendertype->getMaxchars();
                         break;
                 }
                 break;
         }
     }
     $feedbacksgeneric = array();
     foreach ($item->resprocessing as $resprocessing) {
         $outcomes = $resprocessing->getOutcomes();
         foreach ($outcomes->decvar as $decvar) {
             $maxpoints = $decvar->getMaxvalue();
         }
         foreach ($resprocessing->respcondition as $respcondition) {
             foreach ($respcondition->displayfeedback as $feedbackpointer) {
                 if (strlen($feedbackpointer->getLinkrefid())) {
                     foreach ($item->itemfeedback as $ifb) {
                         if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
                             // found a feedback for the identifier
                             if (count($ifb->material)) {
                                 foreach ($ifb->material as $material) {
                                     $feedbacksgeneric[1] = $material;
                                 }
                             }
                             if (count($ifb->flow_mat) > 0) {
                                 foreach ($ifb->flow_mat as $fmat) {
                                     if (count($fmat->material)) {
                                         foreach ($fmat->material as $material) {
                                             $feedbacksgeneric[1] = $material;
                                         }
                                     }
                                 }
                             }
                         } else {
                             if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
                                 // found a feedback for the identifier
                                 if (count($ifb->material)) {
                                     foreach ($ifb->material as $material) {
                                         $feedbacksgeneric[0] = $material;
                                     }
                                 }
                                 if (count($ifb->flow_mat) > 0) {
                                     foreach ($ifb->flow_mat as $fmat) {
                                         if (count($fmat->material)) {
                                             foreach ($fmat->material as $material) {
                                                 $feedbacksgeneric[0] = $material;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->object->setTitle($item->getTitle());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $this->object->setPoints($maxpoints);
     $this->object->setMaxNumOfChars($maxchars);
     $textrating = $item->getMetadataEntry("textrating");
     if (strlen($textrating)) {
         $this->object->setTextRating($textrating);
     }
     $keywords = $item->getMetadataEntry("keywords");
     if (strlen($keywords)) {
         $this->object->setKeywords($keywords);
     }
     $this->object->saveToDb();
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
         $this->object->saveToDb();
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacksgeneric[$correctness] = $m;
     }
     // handle the import of media objects in XHTML code
     $questiontext = $this->object->getQuestion();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 include_once "./Modules/Test/classes/class.ilObjTest.php";
                 $importfile = ilObjTest::_getImportDirectory() . "/" . $_SESSION["tst_import_subdir"] . "/" . $mob["uri"];
             } else {
                 include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
                 $importfile = ilObjQuestionPool::_getImportDirectory() . "/" . $_SESSION["qpl_import_subdir"] . "/" . $mob["uri"];
             }
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
             foreach ($feedbacksgeneric as $correctness => $material) {
                 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     foreach ($feedbacksgeneric as $correctness => $material) {
         $this->object->saveFeedbackGeneric($correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     $this->object->saveToDb();
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
 }
 /**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $now = getdate();
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     $feedbacksgeneric = array();
     $this->object->setTitle($item->getTitle());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     if (preg_match_all("/(\\\$v\\d+)/ims", $this->object->getQuestion(), $matches)) {
         foreach ($matches[1] as $variable) {
             $data = unserialize($item->getMetadataEntry($variable));
             $unit = $this->object->getUnitRepository()->getUnit($data["unitvalue"]);
             require_once 'Modules/TestQuestionPool/classes/class.assFormulaQuestionVariable.php';
             $varObj = new assFormulaQuestionVariable($variable, $data["rangemin"], $data["rangemax"], $unit, $data["precision"], $data["intprecision"]);
             $this->object->addVariable($varObj);
         }
     }
     if (preg_match_all("/(\\\$r\\d+)/ims", $this->object->getQuestion(), $rmatches)) {
         foreach ($rmatches[1] as $result) {
             $data = unserialize($item->getMetadataEntry($result));
             $unit = $this->object->getUnitRepository()->getUnit($data["unitvalue"]);
             require_once 'Modules/TestQuestionPool/classes/class.assFormulaQuestionResult.php';
             if (!is_array($data["rating"])) {
                 $resObj = new assFormulaQuestionResult($result, $data["rangemin"], $data["rangemax"], $data["tolerance"], $unit, $data["formula"], $data["points"], $data["precision"], TRUE);
             } else {
                 $resObj = new assFormulaQuestionResult($result, $data["rangemin"], $data["rangemax"], $data["tolerance"], $unit, $data["formula"], $data["points"], $data["precision"], FALSE, $data["rating"]["sign"], $data["rating"]["value"], $data["rating"]["unit"]);
             }
             $this->object->addResult($resObj);
             if (is_array($data["resultunits"])) {
                 foreach ($data["resultunits"] as $resu) {
                     $ru = $this->object->getUnitRepository()->getUnit($resu["unitvalue"]);
                     if (is_object($ru)) {
                         $this->object->addResultUnit($resObj, $ru);
                     }
                 }
             }
         }
     }
     $this->object->setPoints($item->getMetadataEntry("points"));
     $this->addGeneralMetadata($item);
     // additional content editing mode information
     $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item));
     $this->object->saveToDb();
     // handle the import of media objects in XHTML code
     $questiontext = $this->object->getQuestion();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 include_once "./Modules/Test/classes/class.ilObjTest.php";
                 $importfile = ilObjTest::_getImportDirectory() . "/" . $_SESSION["tst_import_subdir"] . "/" . $mob["uri"];
             } else {
                 include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
                 $importfile = ilObjQuestionPool::_getImportDirectory() . "/" . $_SESSION["qpl_import_subdir"] . "/" . $mob["uri"];
             }
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     // additional content editing mode information
     $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item));
     $this->object->saveToDb();
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
         $this->object->saveToDb();
     }
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
 }
 /**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $now = getdate();
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     $feedbacksgeneric = array();
     $this->object->setTitle($item->getTitle());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $this->object->setPoints($item->getMetadataEntry("points"));
     $this->object->setOptionString($item->getMetadataEntry("option_string"));
     $this->object->setSampleSolution($item->getMetadataEntry("sample_solution"));
     $this->object->saveToDb('', false);
     // handle the import of media objects in XHTML code
     $questiontext = $this->object->getQuestion();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 include_once "./Modules/Test/classes/class.ilObjTest.php";
                 $importfile = ilObjTest::_getImportDirectory() . '/' . $mob["uri"];
             } else {
                 include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
                 $importfile = ilObjQuestionPool::_getImportDirectory() . '/' . $mob["uri"];
             }
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     // feedback
     $feedbacksgeneric = array();
     foreach ($item->itemfeedback as $ifb) {
         if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
             // found a feedback for the identifier
             if (count($ifb->material)) {
                 foreach ($ifb->material as $material) {
                     $feedbacksgeneric[1] = $material;
                 }
             }
             if (count($ifb->flow_mat) > 0) {
                 foreach ($ifb->flow_mat as $fmat) {
                     if (count($fmat->material)) {
                         foreach ($fmat->material as $material) {
                             $feedbacksgeneric[1] = $material;
                         }
                     }
                 }
             }
         } else {
             if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
                 // found a feedback for the identifier
                 if (count($ifb->material)) {
                     foreach ($ifb->material as $material) {
                         $feedbacksgeneric[0] = $material;
                     }
                 }
                 if (count($ifb->flow_mat) > 0) {
                     foreach ($ifb->flow_mat as $fmat) {
                         if (count($fmat->material)) {
                             foreach ($fmat->material as $material) {
                                 $feedbacksgeneric[0] = $material;
                             }
                         }
                     }
                 }
             }
         }
     }
     // genericFeedback
     foreach ($feedbacksgeneric as $correctness => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacksgeneric[$correctness] = $m;
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         //$this->object->saveFeedbackGeneric($correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
         $this->object->feedbackOBJ->importGenericFeedback($this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     $this->object->saveToDb();
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
 }