ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.assFormulaQuestionImport.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once "./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
5
16{
30 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
31 {
32 global $DIC;
33 $ilUser = $DIC['ilUser'];
34
35 // empty session variable for imported xhtml mobs
36 unset($_SESSION["import_mob_xhtml"]);
37 $presentation = $item->getPresentation();
38 $duration = $item->getDuration();
39 $now = getdate();
40 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
41
42 $feedbacksgeneric = array();
43
44 $this->object->setTitle($item->getTitle());
45 $this->object->setComment($item->getComment());
46 $this->object->setAuthor($item->getAuthor());
47 $this->object->setOwner($ilUser->getId());
48 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
49 $this->object->setObjId($questionpool_id);
50 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
51 if (preg_match_all("/(\\\$v\\d+)/ims", $this->object->getQuestion(), $matches)) {
52 foreach ($matches[1] as $variable) {
53 $data = unserialize($item->getMetadataEntry($variable));
54 $unit = $this->object->getUnitRepository()->getUnit($data["unitvalue"]);
55 require_once 'Modules/TestQuestionPool/classes/class.assFormulaQuestionVariable.php';
56 $varObj = new assFormulaQuestionVariable($variable, $data["rangemin"], $data["rangemax"], $unit, $data["precision"], $data["intprecision"]);
57 $this->object->addVariable($varObj);
58 }
59 }
60 if (preg_match_all("/(\\\$r\\d+)/ims", $this->object->getQuestion(), $rmatches)) {
61 foreach ($rmatches[1] as $result) {
62 $data = unserialize($item->getMetadataEntry($result));
63 $unit = $this->object->getUnitRepository()->getUnit($data["unitvalue"]);
64 require_once 'Modules/TestQuestionPool/classes/class.assFormulaQuestionResult.php';
65 if (!is_array($data["rating"])) {
66 $resObj = new assFormulaQuestionResult($result, $data["rangemin"], $data["rangemax"], $data["tolerance"], $unit, $data["formula"], $data["points"], $data["precision"], true);
67 } else {
68 $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"]);
69 }
70 $this->object->addResult($resObj);
71 if (is_array($data["resultunits"])) {
72 foreach ($data["resultunits"] as $resu) {
73 $ru = $this->object->getUnitRepository()->getUnit($resu["unitvalue"]);
74 if (is_object($ru)) {
75 $this->object->addResultUnit($resObj, $ru);
76 }
77 }
78 }
79 }
80 }
81 $this->object->setPoints($item->getMetadataEntry("points"));
82 $this->addGeneralMetadata($item);
83 // additional content editing mode information
84 $this->object->setAdditionalContentEditingMode(
86 );
87 $this->object->saveToDb();
88 // handle the import of media objects in XHTML code
89 $questiontext = $this->object->getQuestion();
90 $feedbacksgeneric = $this->getFeedbackGeneric($item);
91
92 if (is_array($_SESSION["import_mob_xhtml"])) {
93 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
94 include_once "./Services/RTE/classes/class.ilRTE.php";
95 foreach ($_SESSION["import_mob_xhtml"] as $mob) {
96 if ($tst_id > 0) {
97 include_once "./Modules/Test/classes/class.ilObjTest.php";
98 $importfile = ilObjTest::_getImportDirectory() . "/" . $_SESSION["tst_import_subdir"] . "/" . $mob["uri"];
99 } else {
100 include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
101 $importfile = ilObjQuestionPool::_getImportDirectory() . "/" . $_SESSION["qpl_import_subdir"] . "/" . $mob["uri"];
102 }
103 $media_object = &ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
104 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
105 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
106
107 foreach ($feedbacksgeneric as $correctness => $material) {
108 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
109 }
110 }
111 }
112 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
113
114 foreach ($feedbacksgeneric as $correctness => $material) {
115 $this->object->feedbackOBJ->importGenericFeedback(
116 $this->object->getId(),
117 $correctness,
119 );
120 }
121
122 // additional content editing mode information
123 $this->object->setAdditionalContentEditingMode(
125 );
126
127 $this->object->saveToDb();
128 if (count($item->suggested_solutions)) {
129 foreach ($item->suggested_solutions as $suggested_solution) {
130 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
131 }
132 $this->object->saveToDb();
133 }
134 if ($tst_id > 0) {
135 $q_1_id = $this->object->getId();
136 $question_id = $this->object->duplicate(true);
137 $tst_object->questions[$question_counter++] = $question_id;
138 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
139 } else {
140 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
141 }
142 }
143}
$result
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
Class for formula question imports.
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
Class for question imports.
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
addGeneralMetadata(ilQTIItem $item)
static _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
static _saveTempFileAsMediaObject($name, $tmp_name, $upload=true)
Create new media object and update page in db and return new media object.
static _getImportDirectory()
get import directory of lm
static _getImportDirectory()
Get the import directory location of the test.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
$data
Definition: storeScorm.php:23
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46