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