21 {
23
25
26 $duration = $item->getDuration();
27 $shuffle = 0;
28 $answers = array();
29
30 $presentation = $item->getPresentation();
31 foreach ($presentation->order as $entry)
32 {
33 switch ($entry["type"])
34 {
35 case "response":
36 $response = $presentation->response[$entry["index"]];
37 $rendertype = $response->getRenderType();
38 switch (strtolower(get_class($response->getRenderType())))
39 {
40 case "ilqtirenderchoice":
41 $shuffle = $rendertype->getShuffle();
42 $answerorder = 0;
43 $foundimage = FALSE;
44 foreach ($rendertype->response_labels as $response_label)
45 {
46 $ident = $response_label->getIdent();
47 $answertext = "";
48 $answerimage = array();
49 foreach ($response_label->material as $mat)
50 {
51 $embedded = false;
52 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
53 {
54 $foundmat = $mat->getMaterial($m);
55 if (strcmp($foundmat["type"], "mattext") == 0)
56 {
57 }
58 if (strcmp($foundmat["type"], "matimage") == 0)
59 {
60 if (strlen($foundmat["material"]->getEmbedded()))
61 {
62 $embedded = true;
63 }
64 }
65 }
66 if ($embedded)
67 {
68 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
69 {
70 $foundmat = $mat->getMaterial($m);
71 if (strcmp($foundmat["type"], "mattext") == 0)
72 {
73 $answertext .= $foundmat["material"]->getContent();
74 }
75 if (strcmp($foundmat["type"], "matimage") == 0)
76 {
77 $foundimage = TRUE;
78 $answerimage = array(
79 "imagetype" => $foundmat["material"]->getImageType(),
80 "label" => $foundmat["material"]->getLabel(),
81 "content" => $foundmat["material"]->getContent()
82 );
83 }
84 }
85 }
86 else
87 {
88 $answertext = $this->object->QTIMaterialToString($mat);
89 }
90 }
91
92 $answers[$ident] = array(
93 "answertext" => $answertext,
94 "imagefile" => $answerimage,
95 "answerorder" => $ident
96 );
97 }
98 break;
99 }
100 break;
101 }
102 }
103
104 $feedbacks = array();
105 $feedbacksgeneric = array();
106
107 foreach ($item->resprocessing as $resprocessing)
108 {
109 foreach($resprocessing->outcomes->decvar as $decvar)
110 {
111 if( $decvar->getVarname() == 'SCORE' )
112 {
113 $this->object->setPoints($decvar->getMaxvalue());
114
115 if( $decvar->getMinvalue() > 0 )
116 {
117 $this->object->setScorePartialSolutionEnabled(true);
118 }
119 }
120 }
121
122 foreach ($resprocessing->respcondition as $respcondition)
123 {
124 if( !count($respcondition->setvar) )
125 {
126 foreach($respcondition->getConditionvar()->varequal as $varequal)
127 {
128 $ident = $varequal->respident;
129 $answers[$ident]['correctness'] = (bool)$varequal->getContent();
130
131 break;
132 }
133
134 foreach ($respcondition->displayfeedback as $feedbackpointer)
135 {
136 if (strlen($feedbackpointer->getLinkrefid()))
137 {
138 foreach ($item->itemfeedback as $ifb)
139 {
140 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0)
141 {
142
143 if (count($ifb->material))
144 {
145 foreach ($ifb->material as $material)
146 {
147 $feedbacks[$ident] = $material;
148 }
149 }
150 if ((count($ifb->flow_mat) > 0))
151 {
152 foreach ($ifb->flow_mat as $fmat)
153 {
154 if (count($fmat->material))
155 {
156 foreach ($fmat->material as $material)
157 {
158 $feedbacks[$ident] = $material;
159 }
160 }
161 }
162 }
163 }
164 }
165 }
166 }
167 }
168 else
169 {
170 foreach ($respcondition->displayfeedback as $feedbackpointer)
171 {
172 if (strlen($feedbackpointer->getLinkrefid()))
173 {
174 foreach ($item->itemfeedback as $ifb)
175 {
176 if( $ifb->getIdent() == "response_allcorrect" )
177 {
178
179 if (count($ifb->material))
180 {
181 foreach ($ifb->material as $material)
182 {
183 $feedbacksgeneric[1] = $material;
184 }
185 }
186 if ((count($ifb->flow_mat) > 0))
187 {
188 foreach ($ifb->flow_mat as $fmat)
189 {
190 if (count($fmat->material))
191 {
192 foreach ($fmat->material as $material)
193 {
194 $feedbacksgeneric[1] = $material;
195 }
196 }
197 }
198 }
199 }
200 else if ( $ifb->getIdent() == "response_onenotcorrect" )
201 {
202
203 if (count($ifb->material))
204 {
205 foreach ($ifb->material as $material)
206 {
207 $feedbacksgeneric[0] = $material;
208 }
209 }
210 if ((count($ifb->flow_mat) > 0))
211 {
212 foreach ($ifb->flow_mat as $fmat)
213 {
214 if (count($fmat->material))
215 {
216 foreach ($fmat->material as $material)
217 {
218 $feedbacksgeneric[0] = $material;
219 }
220 }
221 }
222 }
223 }
224 }
225 }
226 }
227 }
228 }
229 }
230
232
233 $this->object->setTitle($item->getTitle());
234 $this->object->setNrOfTries($item->getMaxattempts());
235 $this->object->setComment($item->getComment());
236 $this->object->setAuthor($item->getAuthor());
237 $this->object->setOwner($ilUser->getId());
238 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
239 $this->object->setObjId($questionpool_id);
240 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
241 $this->object->setShuffleAnswersEnabled($shuffle);
242 $this->object->setAnswerType($item->getMetadataEntry("answer_type"));
243 $this->object->setOptionLabel($item->getMetadataEntry("option_label_setting"));
244 $this->object->setCustomTrueOptionLabel($item->getMetadataEntry("custom_true_option_label"));
245 $this->object->setCustomFalseOptionLabel($item->getMetadataEntry("custom_false_option_label"));
246 $this->object->setThumbSize($item->getMetadataEntry("thumb_size"));
247
248 $this->object->saveToDb();
249
250 foreach ($answers as $answerData)
251 {
253 $answer->setImageFsDir($this->object->getImagePath());
254 $answer->setImageWebDir($this->object->getImagePathWeb());
255
256 $answer->setPosition($answerData['answerorder']);
257 $answer->setAnswertext($answerData['answertext']);
258 $answer->setCorrectness($answerData['correctness']);
259
260 if( isset($answerData['imagefile']['label']) )
261 {
262 $answer->setImageFile($answerData['imagefile']['label']);
263 }
264
265 $this->object->addAnswer($answer);
266 }
267
268 $this->object->setAdditionalContentEditingMode(
270 );
271
272 $this->object->saveToDb();
273
274 foreach ($answers as $answer)
275 {
276 if (is_array($answer["imagefile"]) && (count($answer["imagefile"]) > 0))
277 {
278 $image =& base64_decode($answer["imagefile"]["content"]);
279 $imagepath = $this->object->getImagePath();
280 include_once "./Services/Utilities/classes/class.ilUtil.php";
281 if (!file_exists($imagepath))
282 {
284 }
285 $imagepath .= $answer["imagefile"]["label"];
286 if($fh = fopen($imagepath, "wb"))
287 {
288 $imagefile = fwrite($fh, $image);
289 fclose($fh);
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 }
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.