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)
55 $presentation = $item->getPresentation();
56 $duration = $item->getDuration();
59 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
61 foreach ($presentation->order as $entry)
63 switch ($entry[
"type"])
66 $response = $presentation->response[$entry[
"index"]];
67 $rendertype = $response->getRenderType();
68 switch (strtolower(get_class($response->getRenderType())))
70 case "ilqtirenderchoice":
71 $shuffle = $rendertype->getShuffle();
74 foreach ($rendertype->response_labels as $response_label)
76 $ident = $response_label->getIdent();
78 $answerimage = array();
79 foreach ($response_label->material as $mat)
82 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
84 $foundmat = $mat->getMaterial($m);
85 if (strcmp($foundmat[
"type"],
"mattext") == 0)
88 if (strcmp($foundmat[
"type"],
"matimage") == 0)
90 if (strlen($foundmat[
"material"]->getEmbedded()))
98 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
100 $foundmat = $mat->getMaterial($m);
101 if (strcmp($foundmat[
"type"],
"mattext") == 0)
103 $answertext .= $foundmat[
"material"]->getContent();
105 if (strcmp($foundmat[
"type"],
"matimage") == 0)
108 $answerimage = array(
109 "imagetype" => $foundmat[
"material"]->getImageType(),
110 "label" => $foundmat[
"material"]->getLabel(),
111 "content" => $foundmat[
"material"]->getContent()
118 $answertext = $this->
object->QTIMaterialToString($mat);
121 $answers[$ident] = array(
122 "answertext" => $answertext,
123 "imagefile" => $answerimage,
125 "answerorder" => $answerorder++,
126 "points_unchecked" => 0,
135 $responses = array();
136 $feedbacks = array();
137 $feedbacksgeneric = array();
138 foreach ($item->resprocessing as $resprocessing)
140 foreach ($resprocessing->respcondition as $respcondition)
144 $conditionvar = $respcondition->getConditionvar();
145 foreach ($conditionvar->order as $order)
147 switch ($order[
"field"])
153 $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
157 foreach ($respcondition->setvar as $setvar)
159 if (strcmp($ident,
"") != 0)
163 $answers[$ident][
"action"] = $setvar->getAction();
164 $answers[$ident][
"points"] = $setvar->getContent();
165 if (count($respcondition->displayfeedback))
167 foreach ($respcondition->displayfeedback as $feedbackpointer)
169 if (strlen($feedbackpointer->getLinkrefid()))
171 foreach ($item->itemfeedback as $ifb)
173 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0)
176 if (count($ifb->material))
178 foreach ($ifb->material as $material)
180 $feedbacksgeneric[1] = $material;
183 if ((count($ifb->flow_mat) > 0))
185 foreach ($ifb->flow_mat as $fmat)
187 if (count($fmat->material))
189 foreach ($fmat->material as $material)
191 $feedbacksgeneric[1] = $material;
197 else if (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0)
200 if (count($ifb->material))
202 foreach ($ifb->material as $material)
204 $feedbacksgeneric[0] = $material;
207 if ((count($ifb->flow_mat) > 0))
209 foreach ($ifb->flow_mat as $fmat)
211 if (count($fmat->material))
213 foreach ($fmat->material as $material)
215 $feedbacksgeneric[0] = $material;
221 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0)
224 if (count($ifb->material))
226 foreach ($ifb->material as $material)
228 $feedbacks[$ident] = $material;
231 if ((count($ifb->flow_mat) > 0))
233 foreach ($ifb->flow_mat as $fmat)
235 if (count($fmat->material))
237 foreach ($fmat->material as $material)
239 $feedbacks[$ident] = $material;
252 $answers[$ident][
"action"] = $setvar->getAction();
253 $answers[$ident][
"points_unchecked"] = $setvar->getContent();
259 $this->
object->setTitle($item->getTitle());
260 $this->
object->setExternalID($item->getMetadataEntry(
"externalID"));
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[
"points_unchecked"], $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);
303 foreach ($feedbacks as $ident => $material)
305 $m = $this->
object->QTIMaterialToString($material);
306 $feedbacks[$ident] = $m;
308 foreach ($feedbacksgeneric as $correctness => $material)
310 $m = $this->
object->QTIMaterialToString($material);
311 $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)
323 include_once
"./Modules/Test/classes/class.ilObjTest.php";
328 include_once
"./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
333 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
334 foreach ($answers as $key => $value)
336 $answer_obj =& $answers[$key];
337 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
339 foreach ($feedbacks as $ident => $material)
341 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
343 foreach ($feedbacksgeneric as $correctness => $material)
345 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
350 foreach ($answers as $key => $value)
352 $answer_obj =& $answers[$key];
355 foreach ($feedbacks as $ident => $material)
359 foreach ($feedbacksgeneric as $correctness => $material)
363 $this->
object->saveToDb();
364 if (count($item->suggested_solutions))
366 foreach ($item->suggested_solutions as $suggested_solution)
368 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
370 $this->
object->saveToDb();
374 $q_1_id = $this->
object->getId();
375 $question_id = $this->
object->duplicate(
true);
376 $tst_object->questions[$question_counter++] = $question_id;
377 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
381 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);