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();
59 $questionimage = array();
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($rendertype)))
71 case "ilqtirenderhotspot":
72 foreach ($rendertype->material as $mat)
74 for ($i = 0; $i < $mat->getMaterialCount(); $i++)
76 $m = $mat->getMaterial($i);
77 if (strcmp($m[
"type"],
"matimage") == 0)
79 $questionimage = array(
80 "imagetype" => $m[
"material"]->getImageType(),
81 "label" => $m[
"material"]->getLabel(),
82 "content" => $m[
"material"]->getContent()
87 foreach ($rendertype->response_labels as $response_label)
89 $ident = $response_label->getIdent();
91 foreach ($response_label->material as $mat)
93 $answerhint .= $this->
object->QTIMaterialToString($mat);
95 $answers[$ident] = array(
96 "answerhint" => $answerhint,
97 "areatype" => $response_label->getRarea(),
98 "coordinates" => $response_label->getContent(),
100 "answerorder" => $response_label->getIdent(),
101 "correctness" =>
"1",
110 $responses = array();
111 $feedbacks = array();
112 $feedbacksgeneric = array();
113 foreach ($item->resprocessing as $resprocessing)
115 foreach ($resprocessing->respcondition as $respcondition)
118 $conditionvar = $respcondition->getConditionvar();
119 foreach ($conditionvar->order as $order)
121 switch ($order[
"field"])
124 $coordinates = $conditionvar->varinside[$order[
"index"]]->getContent();
128 foreach ($respcondition->setvar as $setvar)
130 foreach ($answers as $ident => $answer)
132 if (strcmp($answer[
"coordinates"], $coordinates) == 0)
134 $answers[$ident][
"action"] = $setvar->getAction();
135 $answers[$ident][
"points"] = $setvar->getContent();
136 if (count($respcondition->displayfeedback))
138 foreach ($respcondition->displayfeedback as $feedbackpointer)
140 if (strlen($feedbackpointer->getLinkrefid()))
142 foreach ($item->itemfeedback as $ifb)
144 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0)
147 if (count($ifb->material))
149 foreach ($ifb->material as $material)
151 $feedbacksgeneric[1] = $material;
154 if ((count($ifb->flow_mat) > 0))
156 foreach ($ifb->flow_mat as $fmat)
158 if (count($fmat->material))
160 foreach ($fmat->material as $material)
162 $feedbacksgeneric[1] = $material;
168 else if (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0)
171 if (count($ifb->material))
173 foreach ($ifb->material as $material)
175 $feedbacksgeneric[0] = $material;
178 if ((count($ifb->flow_mat) > 0))
180 foreach ($ifb->flow_mat as $fmat)
182 if (count($fmat->material))
184 foreach ($fmat->material as $material)
186 $feedbacksgeneric[0] = $material;
192 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0)
195 if (count($ifb->material))
197 foreach ($ifb->material as $material)
199 $feedbacks[$ident] = $material;
202 if ((count($ifb->flow_mat) > 0))
204 foreach ($ifb->flow_mat as $fmat)
206 if (count($fmat->material))
208 foreach ($fmat->material as $material)
210 $feedbacks[$ident] = $material;
226 $this->
object->setTitle($item->getTitle());
227 $this->
object->setExternalID($item->getMetadataEntry(
"externalID"));
228 $this->
object->setNrOfTries($item->getMaxattempts());
229 $this->
object->setComment($item->getComment());
230 $this->
object->setAuthor($item->getAuthor());
231 $this->
object->setOwner($ilUser->getId());
232 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
233 $this->
object->setObjId($questionpool_id);
234 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
235 $areas = array(
"2" =>
"rect",
"1" =>
"circle",
"3" =>
"poly");
236 $this->
object->setImageFilename($questionimage[
"label"]);
237 foreach ($answers as $answer)
239 $this->
object->addAnswer($answer[
"answerhint"], $answer[
"points"], $answer[
"answerorder"], $answer[
"coordinates"], $areas[$answer[
"areatype"]]);
241 $this->
object->saveToDb();
242 if (count($item->suggested_solutions))
244 foreach ($item->suggested_solutions as $suggested_solution)
246 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
248 $this->
object->saveToDb();
250 $image =& base64_decode($questionimage[
"content"]);
251 $imagepath = $this->
object->getImagePath();
252 if (!file_exists($imagepath))
254 include_once
"./Services/Utilities/classes/class.ilUtil.php";
257 $imagepath .= $questionimage[
"label"];
258 $fh = fopen($imagepath,
"wb");
267 $imagefile = fwrite($fh, $image);
271 foreach ($feedbacks as $ident => $material)
273 $m = $this->
object->QTIMaterialToString($material);
274 $feedbacks[$ident] = $m;
276 foreach ($feedbacksgeneric as $correctness => $material)
278 $m = $this->
object->QTIMaterialToString($material);
279 $feedbacksgeneric[$correctness] = $m;
281 $questiontext = $this->
object->getQuestion();
282 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
284 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
285 include_once
"./Services/RTE/classes/class.ilRTE.php";
286 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
290 include_once
"./Modules/Test/classes/class.ilObjTest.php";
295 include_once
"./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
300 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
301 foreach ($feedbacks as $ident => $material)
303 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
305 foreach ($feedbacksgeneric as $correctness => $material)
307 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
312 foreach ($feedbacks as $ident => $material)
316 foreach ($feedbacksgeneric as $correctness => $material)
320 $this->
object->saveToDb();
323 $q_1_id = $this->
object->getId();
324 $question_id = $this->
object->duplicate(
true);
325 $tst_object->questions[$question_counter++] = $question_id;
326 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
330 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);