24 include_once
"./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
50 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
56 $presentation = $item->getPresentation();
57 $duration = $item->getDuration();
60 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
62 foreach ($presentation->order as $entry)
64 switch ($entry[
"type"])
67 $response = $presentation->response[$entry[
"index"]];
68 $rendertype = $response->getRenderType();
69 switch (strtolower(get_class($response->getRenderType())))
71 case "ilqtirenderchoice":
72 $shuffle = $rendertype->getShuffle();
75 foreach ($rendertype->response_labels as $response_label)
77 $ident = $response_label->getIdent();
79 $answerimage = array();
80 foreach ($response_label->material as $mat)
83 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
85 $foundmat = $mat->getMaterial($m);
86 if (strcmp($foundmat[
"type"],
"mattext") == 0)
89 if (strcmp($foundmat[
"type"],
"matimage") == 0)
91 if (strlen($foundmat[
"material"]->getEmbedded()))
99 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
101 $foundmat = $mat->getMaterial($m);
102 if (strcmp($foundmat[
"type"],
"mattext") == 0)
104 $answertext .= $foundmat[
"material"]->getContent();
106 if (strcmp($foundmat[
"type"],
"matimage") == 0)
109 $answerimage = array(
110 "imagetype" => $foundmat[
"material"]->getImageType(),
111 "label" => $foundmat[
"material"]->getLabel(),
112 "content" => $foundmat[
"material"]->getContent()
119 $answertext = $this->
object->QTIMaterialToString($mat);
122 $answers[$ident] = array(
123 "answertext" => $answertext,
124 "imagefile" => $answerimage,
126 "answerorder" => $answerorder++,
127 "points_unchecked" => 0,
136 $responses = array();
137 $feedbacks = array();
138 $feedbacksgeneric = array();
139 foreach ($item->resprocessing as $resprocessing)
141 foreach ($resprocessing->respcondition as $respcondition)
145 $conditionvar = $respcondition->getConditionvar();
146 foreach ($conditionvar->order as $order)
148 switch ($order[
"field"])
154 $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
158 foreach ($respcondition->setvar as $setvar)
160 if (strcmp($ident,
"") != 0)
164 $answers[$ident][
"action"] = $setvar->getAction();
165 $answers[$ident][
"points"] = $setvar->getContent();
166 if (count($respcondition->displayfeedback))
168 foreach ($respcondition->displayfeedback as $feedbackpointer)
170 if (strlen($feedbackpointer->getLinkrefid()))
172 foreach ($item->itemfeedback as $ifb)
174 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0)
177 if (count($ifb->material))
179 foreach ($ifb->material as $material)
181 $feedbacksgeneric[1] = $material;
184 if ((count($ifb->flow_mat) > 0))
186 foreach ($ifb->flow_mat as $fmat)
188 if (count($fmat->material))
190 foreach ($fmat->material as $material)
192 $feedbacksgeneric[1] = $material;
198 else if (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0)
201 if (count($ifb->material))
203 foreach ($ifb->material as $material)
205 $feedbacksgeneric[0] = $material;
208 if ((count($ifb->flow_mat) > 0))
210 foreach ($ifb->flow_mat as $fmat)
212 if (count($fmat->material))
214 foreach ($fmat->material as $material)
216 $feedbacksgeneric[0] = $material;
222 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0)
225 if (count($ifb->material))
227 foreach ($ifb->material as $material)
229 $feedbacks[$ident] = $material;
232 if ((count($ifb->flow_mat) > 0))
234 foreach ($ifb->flow_mat as $fmat)
236 if (count($fmat->material))
238 foreach ($fmat->material as $material)
240 $feedbacks[$ident] = $material;
253 $answers[$ident][
"action"] = $setvar->getAction();
254 $answers[$ident][
"points_unchecked"] = $setvar->getContent();
260 $this->
object->setTitle($item->getTitle());
261 $this->
object->setNrOfTries($item->getMaxattempts());
262 $this->
object->setComment($item->getComment());
263 $this->
object->setAuthor($item->getAuthor());
264 $this->
object->setOwner($ilUser->getId());
265 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
266 $this->
object->setObjId($questionpool_id);
267 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
268 $this->
object->setShuffle($shuffle);
269 $this->
object->setThumbSize($item->getMetadataEntry(
"thumb_size"));
270 foreach ($answers as $answer)
272 if (is_array($answer[
"imagefile"]) && (count($answer[
"imagefile"]) > 0))
274 $this->
object->isSingleline =
true;
276 $this->
object->addAnswer($answer[
"answertext"], $answer[
"points"], $answer[
"answerorder"], $answer[
"imagefile"][
"label"]);
278 $this->
object->saveToDb();
279 foreach ($answers as $answer)
281 if (is_array($answer[
"imagefile"]) && (count($answer[
"imagefile"]) > 0))
283 $image =& base64_decode($answer[
"imagefile"][
"content"]);
284 $imagepath = $this->
object->getImagePath();
285 include_once
"./Services/Utilities/classes/class.ilUtil.php";
286 if (!file_exists($imagepath))
290 $imagepath .= $answer[
"imagefile"][
"label"];
291 $fh = fopen($imagepath,
"wb");
297 $imagefile = fwrite($fh, $image);
302 foreach ($feedbacks as $ident => $material)
304 $m = $this->
object->QTIMaterialToString($material);
305 $feedbacks[$ident] = $m;
307 foreach ($feedbacksgeneric as $correctness => $material)
309 $m = $this->
object->QTIMaterialToString($material);
310 $feedbacksgeneric[$correctness] = $m;
313 $questiontext = $this->
object->getQuestion();
314 $answers =& $this->
object->getAnswers();
315 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
317 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
318 include_once
"./Services/RTE/classes/class.ilRTE.php";
319 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
330 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
334 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
335 foreach ($answers as $key => $value)
337 $answer_obj = $answers[$key];
338 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
340 foreach ($feedbacks as $ident => $material)
342 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
344 foreach ($feedbacksgeneric as $correctness => $material)
346 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
351 foreach ($answers as $key => $value)
353 $answer_obj =& $answers[$key];
356 foreach ($feedbacks as $ident => $material)
360 foreach ($feedbacksgeneric as $correctness => $material)
364 $this->
object->saveToDb();
365 if (count($item->suggested_solutions))
367 foreach ($item->suggested_solutions as $suggested_solution)
369 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
371 $this->
object->saveToDb();
375 $q_1_id = $this->
object->getId();
376 $question_id = $this->
object->duplicate(
true, null, null, null, $tst_id);
377 $tst_object->questions[$question_counter++] = $question_id;
378 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
382 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);