ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.assImagemapQuestionImport.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 $questionimage = array();
41 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
42 $answers = array();
43 foreach ($presentation->order as $entry) {
44 switch ($entry["type"]) {
45 case "response":
46 $response = $presentation->response[$entry["index"]];
47 $rendertype = $response->getRenderType();
48 switch (strtolower(get_class($rendertype))) {
49 case "ilqtirenderhotspot":
50 foreach ($rendertype->material as $mat) {
51 for ($i = 0; $i < $mat->getMaterialCount(); $i++) {
52 $m = $mat->getMaterial($i);
53 if (strcmp($m["type"], "matimage") == 0) {
54 $questionimage = array(
55 "imagetype" => $m["material"]->getImageType(),
56 "label" => $m["material"]->getLabel(),
57 "content" => $m["material"]->getContent()
58 );
59 }
60 }
61 }
62 foreach ($rendertype->response_labels as $response_label) {
63 $ident = $response_label->getIdent();
64 $answerhint = "";
65 foreach ($response_label->material as $mat) {
66 $answerhint .= $this->object->QTIMaterialToString($mat);
67 }
68 $answers[$ident] = array(
69 "answerhint" => $answerhint,
70 "areatype" => $response_label->getRarea(),
71 "coordinates" => $response_label->getContent(),
72 "points" => 0,
73 "answerorder" => $response_label->getIdent(),
74 "correctness" => "1",
75 "action" => "",
76 "points_unchecked" => 0
77 );
78 }
79 break;
80 }
81 break;
82 }
83 }
84 $responses = array();
85 $feedbacks = array();
86 $feedbacksgeneric = array();
87 foreach ($item->resprocessing as $resprocessing) {
88 foreach ($resprocessing->respcondition as $respcondition) {
89 $coordinates = "";
90 $correctness = 1;
91 $conditionvar = $respcondition->getConditionvar();
92 foreach ($conditionvar->order as $order) {
93 switch ($order["field"]) {
94 case "arr_not":
95 $correctness = 0;
96 break;
97 case "varinside":
98 $coordinates = $conditionvar->varinside[$order["index"]]->getContent();
99 break;
100 case "varequal":
101 $coordinates = $conditionvar->varequal[$order["index"]]->getContent();
102 break;
103 }
104 }
105 foreach ($respcondition->setvar as $setvar) {
106 foreach ($answers as $ident => $answer) {
107 if (strcmp($answer["coordinates"], $coordinates) == 0) {
108 if ($correctness) {
109 $answers[$ident]["action"] = $setvar->getAction();
110 $answers[$ident]["points"] = $setvar->getContent();
111 if (count($respcondition->displayfeedback)) {
112 foreach ($respcondition->displayfeedback as $feedbackpointer) {
113 if (strlen($feedbackpointer->getLinkrefid())) {
114 foreach ($item->itemfeedback as $ifb) {
115 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
116 // found a feedback for the identifier
117 if (count($ifb->material)) {
118 foreach ($ifb->material as $material) {
119 $feedbacksgeneric[1] = $material;
120 }
121 }
122 if ((count($ifb->flow_mat) > 0)) {
123 foreach ($ifb->flow_mat as $fmat) {
124 if (count($fmat->material)) {
125 foreach ($fmat->material as $material) {
126 $feedbacksgeneric[1] = $material;
127 }
128 }
129 }
130 }
131 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
132 // found a feedback for the identifier
133 if (count($ifb->material)) {
134 foreach ($ifb->material as $material) {
135 $feedbacksgeneric[0] = $material;
136 }
137 }
138 if ((count($ifb->flow_mat) > 0)) {
139 foreach ($ifb->flow_mat as $fmat) {
140 if (count($fmat->material)) {
141 foreach ($fmat->material as $material) {
142 $feedbacksgeneric[0] = $material;
143 }
144 }
145 }
146 }
147 }
148 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
149 // found a feedback for the identifier
150 if (count($ifb->material)) {
151 foreach ($ifb->material as $material) {
152 $feedbacks[$ident] = $material;
153 }
154 }
155 if ((count($ifb->flow_mat) > 0)) {
156 foreach ($ifb->flow_mat as $fmat) {
157 if (count($fmat->material)) {
158 foreach ($fmat->material as $material) {
159 $feedbacks[$ident] = $material;
160 }
161 }
162 }
163 }
164 }
165 }
166 }
167 }
168 }
169 } else {
170 $answers[$ident]["action"] = $setvar->getAction();
171 $answers[$ident]["points_unchecked"] = $setvar->getContent();
172 }
173 }
174 }
175 }
176 }
177 }
178
179 $this->addGeneralMetadata($item);
180 $this->object->setTitle($item->getTitle());
181 $this->object->setNrOfTries($item->getMaxattempts());
182 $this->object->setComment($item->getComment());
183 $this->object->setAuthor($item->getAuthor());
184 $this->object->setOwner($ilUser->getId());
185 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
186 $this->object->setObjId($questionpool_id);
187 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
188 $this->object->setIsMultipleChoice($item->getMetadataEntry("IS_MULTIPLE_CHOICE"));
189 $areas = array("2" => "rect", "1" => "circle", "3" => "poly");
190 $this->object->setImageFilename($questionimage["label"]);
191 foreach ($answers as $answer) {
192 $this->object->addAnswer($answer["answerhint"], $answer["points"], $answer["answerorder"], $answer["coordinates"], $areas[$answer["areatype"]], $answer["points_unchecked"]);
193 }
194 // additional content editing mode information
195 $this->object->setAdditionalContentEditingMode(
197 );
198 $this->object->saveToDb();
199 if (count($item->suggested_solutions)) {
200 foreach ($item->suggested_solutions as $suggested_solution) {
201 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
202 }
203 $this->object->saveToDb();
204 }
205 $image = &base64_decode($questionimage["content"]);
206 $imagepath = $this->object->getImagePath();
207 if (!file_exists($imagepath)) {
208 include_once "./Services/Utilities/classes/class.ilUtil.php";
209 ilUtil::makeDirParents($imagepath);
210 }
211 $imagepath .= $questionimage["label"];
212 $fh = fopen($imagepath, "wb");
213 if ($fh == false) {
214 // global $DIC;
215// $ilErr = $DIC['ilErr'];
216// $ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE);
217// return;
218 } else {
219 $imagefile = fwrite($fh, $image);
220 fclose($fh);
221 }
222 // handle the import of media objects in XHTML code
223 foreach ($feedbacks as $ident => $material) {
224 $m = $this->object->QTIMaterialToString($material);
225 $feedbacks[$ident] = $m;
226 }
227 foreach ($feedbacksgeneric as $correctness => $material) {
228 $m = $this->object->QTIMaterialToString($material);
229 $feedbacksgeneric[$correctness] = $m;
230 }
231 $questiontext = $this->object->getQuestion();
232 if (is_array($_SESSION["import_mob_xhtml"])) {
233 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
234 include_once "./Services/RTE/classes/class.ilRTE.php";
235 foreach ($_SESSION["import_mob_xhtml"] as $mob) {
236 if ($tst_id > 0) {
237 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
238 } else {
239 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
240 }
241
242 global $DIC; /* @var ILIAS\DI\Container $DIC */
243 $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
244
245 $media_object = &ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
246 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
247 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
248 foreach ($feedbacks as $ident => $material) {
249 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
250 }
251 foreach ($feedbacksgeneric as $correctness => $material) {
252 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
253 }
254 }
255 }
256 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
257 foreach ($feedbacks as $ident => $material) {
258 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
259 $this->object->getId(),
260 0,
261 $ident,
263 );
264 }
265 foreach ($feedbacksgeneric as $correctness => $material) {
266 $this->object->feedbackOBJ->importGenericFeedback(
267 $this->object->getId(),
268 $correctness,
270 );
271 }
272 $this->object->saveToDb();
273 if ($tst_id > 0) {
274 $q_1_id = $this->object->getId();
275 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
276 $tst_object->questions[$question_counter++] = $question_id;
277 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
278 } else {
279 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
280 }
281 }
282}
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
Class for imagemap 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_...
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir)
addGeneralMetadata(ilQTIItem $item)
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir)
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 _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...
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$i
Definition: disco.tpl.php:19
$response
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18