Creates a question from a QTI file.
31 {
33
34
36 $presentation = $item->getPresentation();
37 $duration = $item->getDuration();
38 $shuffle = 0;
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 $answers = array();
42 foreach ($presentation->order as $entry)
43 {
44 switch ($entry["type"])
45 {
46 case "response":
47 $response = $presentation->response[$entry["index"]];
48 $rendertype = $response->getRenderType();
49 switch (strtolower(get_class($response->getRenderType())))
50 {
51 case "ilqtirenderchoice":
52 $shuffle = $rendertype->getShuffle();
53 $answerorder = 0;
54 $foundimage = FALSE;
55 foreach ($rendertype->response_labels as $response_label)
56 {
57 $ident = $response_label->getIdent();
58 $answertext = "";
59 $answerimage = array();
60 foreach ($response_label->material as $mat)
61 {
62 $embedded = false;
63 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
64 {
65 $foundmat = $mat->getMaterial($m);
66 if (strcmp($foundmat["type"], "mattext") == 0)
67 {
68 }
69 if (strcmp($foundmat["type"], "matimage") == 0)
70 {
71 if (strlen($foundmat["material"]->getEmbedded()))
72 {
73 $embedded = true;
74 }
75 }
76 }
77 if ($embedded)
78 {
79 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
80 {
81 $foundmat = $mat->getMaterial($m);
82 if (strcmp($foundmat["type"], "mattext") == 0)
83 {
84 $answertext .= $foundmat["material"]->getContent();
85 }
86 if (strcmp($foundmat["type"], "matimage") == 0)
87 {
88 $foundimage = TRUE;
89 $answerimage = array(
90 "imagetype" => $foundmat["material"]->getImageType(),
91 "label" => $foundmat["material"]->getLabel(),
92 "content" => $foundmat["material"]->getContent()
93 );
94 }
95 }
96 }
97 else
98 {
99 $answertext = $this->object->QTIMaterialToString($mat);
100 }
101 }
102 $answers[$ident] = array(
103 "answertext" => $answertext,
104 "imagefile" => $answerimage,
105 "points" => 0,
106 "answerorder" => $answerorder++,
107 "points_unchecked" => 0,
108 "action" => ""
109 );
110 }
111 break;
112 }
113 break;
114 }
115 }
116 $responses = array();
117 $feedbacks = array();
118 $feedbacksgeneric = array();
119 foreach ($item->resprocessing as $resprocessing)
120 {
121 foreach ($resprocessing->respcondition as $respcondition)
122 {
123 $ident = "";
124 $correctness = 1;
125 $conditionvar = $respcondition->getConditionvar();
126 foreach ($conditionvar->order as $order)
127 {
128 switch ($order["field"])
129 {
130 case "arr_not":
131 $correctness = 0;
132 break;
133 case "varequal":
134 $ident = $conditionvar->varequal[$order["index"]]->getContent();
135 break;
136 }
137 }
138 foreach ($respcondition->setvar as $setvar)
139 {
140 if (strcmp($ident, "") != 0)
141 {
142 if ($correctness)
143 {
144 $answers[$ident]["action"] = $setvar->getAction();
145 $answers[$ident]["points"] = $setvar->getContent();
146 if (count($respcondition->displayfeedback))
147 {
148 foreach ($respcondition->displayfeedback as $feedbackpointer)
149 {
150 if (strlen($feedbackpointer->getLinkrefid()))
151 {
152 foreach ($item->itemfeedback as $ifb)
153 {
154 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0)
155 {
156
157 if (count($ifb->material))
158 {
159 foreach ($ifb->material as $material)
160 {
161 $feedbacksgeneric[1] = $material;
162 }
163 }
164 if ((count($ifb->flow_mat) > 0))
165 {
166 foreach ($ifb->flow_mat as $fmat)
167 {
168 if (count($fmat->material))
169 {
170 foreach ($fmat->material as $material)
171 {
172 $feedbacksgeneric[1] = $material;
173 }
174 }
175 }
176 }
177 }
178 else if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0)
179 {
180
181 if (count($ifb->material))
182 {
183 foreach ($ifb->material as $material)
184 {
185 $feedbacksgeneric[0] = $material;
186 }
187 }
188 if ((count($ifb->flow_mat) > 0))
189 {
190 foreach ($ifb->flow_mat as $fmat)
191 {
192 if (count($fmat->material))
193 {
194 foreach ($fmat->material as $material)
195 {
196 $feedbacksgeneric[0] = $material;
197 }
198 }
199 }
200 }
201 }
202 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0)
203 {
204
205 if (count($ifb->material))
206 {
207 foreach ($ifb->material as $material)
208 {
209 $feedbacks[$ident] = $material;
210 }
211 }
212 if ((count($ifb->flow_mat) > 0))
213 {
214 foreach ($ifb->flow_mat as $fmat)
215 {
216 if (count($fmat->material))
217 {
218 foreach ($fmat->material as $material)
219 {
220 $feedbacks[$ident] = $material;
221 }
222 }
223 }
224 }
225 }
226 }
227 }
228 }
229 }
230 }
231 else
232 {
233 $answers[$ident]["action"] = $setvar->getAction();
234 $answers[$ident]["points_unchecked"] = $setvar->getContent();
235 }
236 }
237 }
238 }
239 }
241 $this->object->setTitle($item->getTitle());
242 $this->object->setNrOfTries($item->getMaxattempts());
243 $this->object->setComment($item->getComment());
244 $this->object->setAuthor($item->getAuthor());
245 $this->object->setOwner($ilUser->getId());
246 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
247 $this->object->setObjId($questionpool_id);
248 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
249 $this->object->setShuffle($shuffle);
250 $this->object->setThumbSize($item->getMetadataEntry("thumb_size"));
251 foreach ($answers as $answer)
252 {
253 if (is_array($answer["imagefile"]) && (count($answer["imagefile"]) > 0))
254 {
255 $this->object->isSingleline = true;
256 }
257 $this->object->addAnswer($answer["answertext"], $answer["points"], $answer["answerorder"], $answer["imagefile"]["label"]);
258 }
259
260 $this->object->setAdditionalContentEditingMode(
262 );
263 $this->object->saveToDb();
264 foreach ($answers as $answer)
265 {
266 if (is_array($answer["imagefile"]) && (count($answer["imagefile"]) > 0))
267 {
268 $image =& base64_decode($answer["imagefile"]["content"]);
269 $imagepath = $this->object->getImagePath();
270 include_once "./Services/Utilities/classes/class.ilUtil.php";
271 if (!file_exists($imagepath))
272 {
274 }
275 $imagepath .= $answer["imagefile"]["label"];
276 $fh = fopen($imagepath, "wb");
277 if ($fh == false)
278 {
279 }
280 else
281 {
282 $imagefile = fwrite($fh, $image);
283 fclose($fh);
284 }
285 }
286 }
287
288 $feedbackSetting = $item->getMetadataEntry('feedback_setting');
289 if( !is_null($feedbackSetting) )
290 {
291 $this->object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting);
292 }
293
294 foreach ($feedbacks as $ident => $material)
295 {
296 $m = $this->object->QTIMaterialToString($material);
297 $feedbacks[$ident] = $m;
298 }
299 foreach ($feedbacksgeneric as $correctness => $material)
300 {
301 $m = $this->object->QTIMaterialToString($material);
302 $feedbacksgeneric[$correctness] = $m;
303 }
304
305 $questiontext = $this->object->getQuestion();
306 $answers =& $this->object->getAnswers();
307 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
308 {
309 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
310 include_once "./Services/RTE/classes/class.ilRTE.php";
311 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
312 {
313 if ($tst_id > 0)
314 {
316 }
317 else
318 {
320 }
321
322 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
323
326 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
327 foreach ($answers as $key => $value)
328 {
329 $answer_obj = $answers[$key];
330 $answer_obj->setAnswertext(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $answer_obj->getAnswertext()));
331 }
332 foreach ($feedbacks as $ident => $material)
333 {
334 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
335 }
336 foreach ($feedbacksgeneric as $correctness => $material)
337 {
338 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
339 }
340 }
341 }
343 foreach ($answers as $key => $value)
344 {
345 $answer_obj =& $answers[$key];
347 }
348 foreach ($feedbacks as $ident => $material)
349 {
350 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
352 );
353 }
354 foreach ($feedbacksgeneric as $correctness => $material)
355 {
356 $this->object->feedbackOBJ->importGenericFeedback(
358 );
359 }
360 $this->object->saveToDb();
361 if (count($item->suggested_solutions))
362 {
363 foreach ($item->suggested_solutions as $suggested_solution)
364 {
365 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
366 }
367 $this->object->saveToDb();
368 }
369 if ($tst_id > 0)
370 {
371 $q_1_id = $this->object->getId();
372 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
373 $tst_object->questions[$question_counter++] = $question_id;
374 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
375 }
376 else
377 {
378 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
379 }
380 }
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 _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.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.