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();
61 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
63 foreach ($presentation->order as $entry)
65 switch ($entry[
"type"])
68 $response = $presentation->response[$entry[
"index"]];
69 $rendertype = $response->getRenderType();
70 switch (strtolower(get_class($rendertype)))
72 case "ilqtirenderchoice":
73 $shuffle = $rendertype->getShuffle();
75 foreach ($rendertype->response_labels as $response_label)
77 $ident = $response_label->getIdent();
79 foreach ($response_label->material as $mat)
81 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
83 $foundmat = $mat->getMaterial($m);
84 if (strcmp($foundmat[
"type"],
"mattext") == 0)
86 $answertext .= $foundmat[
"material"]->getContent();
88 if (strcmp($foundmat[
"type"],
"matimage") == 0)
92 "imagetype" => $foundmat[
"material"]->getImageType(),
93 "label" => $foundmat[
"material"]->getLabel(),
94 "content" => $foundmat[
"material"]->getContent()
99 $answers[$ident] = array(
100 "answertext" => $answertext,
101 "answerimage" => $answerimage,
103 "answerorder" => $answerorder++,
113 $responses = array();
114 $feedbacksgeneric = array();
115 foreach ($item->resprocessing as $resprocessing)
117 foreach ($resprocessing->respcondition as $respcondition)
121 $conditionvar = $respcondition->getConditionvar();
122 foreach ($conditionvar->order as $order)
124 switch ($order[
"field"])
130 $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
131 $orderindex = $conditionvar->varequal[$order[
"index"]]->getIndex();
135 foreach ($respcondition->setvar as $setvar)
137 if (strcmp($ident,
"") != 0)
139 $answers[$ident][
"solutionorder"] = $orderindex;
140 $answers[$ident][
"action"] = $setvar->getAction();
141 $answers[$ident][
"points"] = $setvar->getContent();
144 if (count($respcondition->displayfeedback))
146 foreach ($respcondition->displayfeedback as $feedbackpointer)
148 if (strlen($feedbackpointer->getLinkrefid()))
150 foreach ($item->itemfeedback as $ifb)
152 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0)
155 if (count($ifb->material))
157 foreach ($ifb->material as $material)
159 $feedbacksgeneric[1] = $material;
162 if ((count($ifb->flow_mat) > 0))
164 foreach ($ifb->flow_mat as $fmat)
166 if (count($fmat->material))
168 foreach ($fmat->material as $material)
170 $feedbacksgeneric[1] = $material;
176 else if (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0)
179 if (count($ifb->material))
181 foreach ($ifb->material as $material)
183 $feedbacksgeneric[0] = $material;
186 if ((count($ifb->flow_mat) > 0))
188 foreach ($ifb->flow_mat as $fmat)
190 if (count($fmat->material))
192 foreach ($fmat->material as $material)
194 $feedbacksgeneric[0] = $material;
211 $this->
object->setTitle($item->getTitle());
212 $this->
object->setExternalID($item->getMetadataEntry(
"externalID"));
213 $this->
object->setNrOfTries($item->getMaxattempts());
214 $this->
object->setComment($item->getComment());
215 $this->
object->setAuthor($item->getAuthor());
216 $this->
object->setOwner($ilUser->getId());
217 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
218 $this->
object->setOrderingType(
$type);
219 $this->
object->setObjId($questionpool_id);
220 $this->
object->setThumbGeometry($item->getMetadataEntry(
"thumb_geometry"));
221 $this->
object->setElementHeight($item->getMetadataEntry(
"element_height"));
222 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
223 $this->
object->setShuffle($shuffle);
225 $solanswers = array();
226 foreach ($answers as $answer)
228 $solanswers[$answer[
"solutionorder"]] = $answer;
231 foreach ($solanswers as $answer)
236 $this->
object->addAnswer($answer[
"answertext"]);
240 $this->
object->addAnswer($answer[
"answerimage"][
"label"]);
243 $points = ($item->getMetadataEntry(
"points") > 0) ? $item->getMetadataEntry(
"points") :
$points;
244 $this->
object->setPoints(
$points);
245 $this->
object->saveToDb();
246 if (count($item->suggested_solutions))
248 foreach ($item->suggested_solutions as $suggested_solution)
250 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
252 $this->
object->saveToDb();
254 foreach ($answers as $answer)
258 include_once
"./Services/Utilities/classes/class.ilUtil.php";
259 $image =& base64_decode($answer[
"answerimage"][
"content"]);
260 $imagepath = $this->
object->getImagePath();
261 if (!file_exists($imagepath))
265 $imagepath .= $answer[
"answerimage"][
"label"];
266 $fh = fopen($imagepath,
"wb");
275 $imagefile = fwrite($fh, $image);
279 $thumbpath = $imagepath .
"." .
"thumb.jpg";
283 foreach ($feedbacksgeneric as $correctness => $material)
285 $m = $this->
object->QTIMaterialToString($material);
286 $feedbacksgeneric[$correctness] = $m;
288 $questiontext = $this->
object->getQuestion();
289 $answers =& $this->
object->getAnswers();
291 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
293 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
294 include_once
"./Services/RTE/classes/class.ilRTE.php";
295 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
299 include_once
"./Modules/Test/classes/class.ilObjTest.php";
304 include_once
"./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
309 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
310 foreach ($answers as $key => $value)
312 $answer_obj =& $answers[$key];
313 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
315 foreach ($feedbacksgeneric as $correctness => $material)
317 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
322 foreach ($answers as $key => $value)
324 $answer_obj =& $answers[$key];
327 foreach ($feedbacksgeneric as $correctness => $material)
331 $this->
object->saveToDb();
334 $q_1_id = $this->
object->getId();
335 $question_id = $this->
object->duplicate(
true);
336 $tst_object->questions[$question_counter++] = $question_id;
337 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
341 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);