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