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->setNrOfTries($item->getMaxattempts());
228 $this->
object->setComment($item->getComment());
229 $this->
object->setAuthor($item->getAuthor());
230 $this->
object->setOwner($ilUser->getId());
231 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
232 $this->
object->setObjId($questionpool_id);
233 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
234 $areas = array(
"2" =>
"rect",
"1" =>
"circle",
"3" =>
"poly");
235 $this->
object->setImageFilename($questionimage[
"label"]);
236 foreach ($answers as $answer)
238 $this->
object->addAnswer($answer[
"answerhint"], $answer[
"points"], $answer[
"answerorder"], $answer[
"coordinates"], $areas[$answer[
"areatype"]]);
240 $this->
object->saveToDb();
241 if (count($item->suggested_solutions))
243 foreach ($item->suggested_solutions as $suggested_solution)
245 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
247 $this->
object->saveToDb();
249 $image =& base64_decode($questionimage[
"content"]);
250 $imagepath = $this->
object->getImagePath();
251 if (!file_exists($imagepath))
253 include_once
"./Services/Utilities/classes/class.ilUtil.php";
256 $imagepath .= $questionimage[
"label"];
257 $fh = fopen($imagepath,
"wb");
266 $imagefile = fwrite($fh, $image);
270 foreach ($feedbacks as $ident => $material)
272 $m = $this->
object->QTIMaterialToString($material);
273 $feedbacks[$ident] = $m;
275 foreach ($feedbacksgeneric as $correctness => $material)
277 $m = $this->
object->QTIMaterialToString($material);
278 $feedbacksgeneric[$correctness] = $m;
280 $questiontext = $this->
object->getQuestion();
281 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
283 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
284 include_once
"./Services/RTE/classes/class.ilRTE.php";
285 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
296 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
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, null, null, null, $tst_id);
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);