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();
58 $questiontext = array();
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"])
69 $material = $presentation->material[$entry[
"index"]];
70 array_push($questiontext, $this->object->QTIMaterialToString($material));
73 $response = $presentation->response[$entry[
"index"]];
74 $rendertype = $response->getRenderType();
75 array_push($questiontext,
"<<" . $response->getIdent() .
">>");
76 switch (strtolower(get_class($response->getRenderType())))
78 case "ilqtirenderfib":
79 switch ($response->getRenderType()->getFibtype())
85 "ident" => $response->getIdent(),
88 "minnumber" => $response->getRenderType()->getMinnumber(),
89 "maxnumber" => $response->getRenderType()->getMaxnumber()
95 array_push($gaps, array(
"ident" => $response->getIdent(),
"type" =>
CLOZE_TEXT,
"answers" => array()));
99 case "ilqtirenderchoice":
101 $shuffle = $rendertype->getShuffle();
103 foreach ($rendertype->response_labels as $response_label)
105 $ident = $response_label->getIdent();
107 foreach ($response_label->material as $mat)
109 $answertext .= $this->
object->QTIMaterialToString($mat);
111 $answers[$ident] = array(
112 "answertext" => $answertext,
114 "answerorder" => $answerorder++,
116 "shuffle" => $rendertype->getShuffle()
119 array_push($gaps, array(
"ident" => $response->getIdent(),
"type" =>
CLOZE_SELECT,
"shuffle" => $rendertype->getShuffle(),
"answers" => $answers));
125 $responses = array();
126 $feedbacks = array();
127 $feedbacksgeneric = array();
128 foreach ($item->resprocessing as $resprocessing)
130 foreach ($resprocessing->respcondition as $respcondition)
134 $conditionvar = $respcondition->getConditionvar();
135 foreach ($conditionvar->order as $order)
137 switch ($order[
"field"])
140 $equals = $conditionvar->varequal[$order[
"index"]]->getContent();
141 $gapident = $conditionvar->varequal[$order[
"index"]]->getRespident();
145 foreach ($respcondition->setvar as $setvar)
147 if (strcmp($gapident,
"") != 0)
149 foreach ($gaps as $gi => $g)
151 if (strcmp($g[
"ident"], $gapident) == 0)
155 foreach ($gaps[$gi][
"answers"] as $ai => $answer)
157 if (strcmp($answer[
"answertext"], $equals) == 0)
159 $gaps[$gi][
"answers"][$ai][
"action"] = $setvar->getAction();
160 $gaps[$gi][
"answers"][$ai][
"points"] = $setvar->getContent();
166 array_push($gaps[$gi][
"answers"], array(
167 "answertext" => $equals,
168 "points" => $setvar->getContent(),
169 "answerorder" => count($gaps[$gi][
"answers"]),
170 "action" => $setvar->getAction()
175 array_push($gaps[$gi][
"answers"], array(
176 "answertext" => $equals,
177 "points" => $setvar->getContent(),
178 "answerorder" => count($gaps[$gi][
"answers"]),
179 "action" => $setvar->getAction()
187 if (count($respcondition->displayfeedback))
189 foreach ($respcondition->displayfeedback as $feedbackpointer)
191 if (strlen($feedbackpointer->getLinkrefid()))
193 foreach ($item->itemfeedback as $ifb)
195 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0)
198 if (count($ifb->material))
200 foreach ($ifb->material as $material)
202 $feedbacksgeneric[1] = $material;
205 if ((count($ifb->flow_mat) > 0))
207 foreach ($ifb->flow_mat as $fmat)
209 if (count($fmat->material))
211 foreach ($fmat->material as $material)
213 $feedbacksgeneric[1] = $material;
219 else if (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0)
222 if (count($ifb->material))
224 foreach ($ifb->material as $material)
226 $feedbacksgeneric[0] = $material;
229 if ((count($ifb->flow_mat) > 0))
231 foreach ($ifb->flow_mat as $fmat)
233 if (count($fmat->material))
235 foreach ($fmat->material as $material)
237 $feedbacksgeneric[0] = $material;
251 $this->
object->setTitle($item->getTitle());
252 $this->
object->setNrOfTries($item->getMaxattempts());
253 $this->
object->setComment($item->getComment());
254 $this->
object->setAuthor($item->getAuthor());
255 $this->
object->setOwner($ilUser->getId());
256 $this->
object->setObjId($questionpool_id);
257 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
258 $textgap_rating = $item->getMetadataEntry(
"textgaprating");
259 $this->
object->setFixedTextLength($item->getMetadataEntry(
"fixedTextLength"));
260 $this->
object->setIdenticalScoring($item->getMetadataEntry(
"identicalScoring"));
261 if (strlen($textgap_rating) == 0) $textgap_rating =
"ci";
262 $this->
object->setTextgapRating($textgap_rating);
264 foreach ($gaps as $gapidx => $gap)
266 $gapcontent = array();
267 include_once
"./Modules/TestQuestionPool/classes/class.assClozeGap.php";
269 foreach ($gap[
"answers"] as $index => $answer)
271 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerCloze.php";
272 $gapanswer =
new assAnswerCloze($answer[
"answertext"], $answer[
"points"], $answer[
"answerorder"]);
273 switch ($clozegap->getType())
276 $clozegap->setShuffle($answer[
"shuffle"]);
279 $gapanswer->setLowerBound($gap[
"minnumber"]);
280 $gapanswer->setUpperBound($gap[
"maxnumber"]);
283 $clozegap->addItem($gapanswer);
284 array_push($gapcontent, $answer[
"answertext"]);
286 $this->
object->addGapAtIndex($clozegap, $gapidx);
287 $gaptext[$gap[
"ident"]] =
"[gap]" . join(
",", $gapcontent).
"[/gap]";
289 $clozetext = join(
"", $questiontext);
290 foreach ($gaptext as $idx => $val)
292 $clozetext = str_replace(
"<<" . $idx .
">>", $val, $clozetext);
294 $this->
object->setQuestion($clozetext);
295 $this->
object->saveToDb();
298 foreach ($feedbacks as $ident => $material)
300 $m = $this->
object->QTIMaterialToString($material);
301 $feedbacks[$ident] = $m;
303 foreach ($feedbacksgeneric as $correctness => $material)
305 $m = $this->
object->QTIMaterialToString($material);
306 $feedbacksgeneric[$correctness] = $m;
308 $questiontext = $this->
object->getQuestion();
309 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
311 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
312 include_once
"./Services/RTE/classes/class.ilRTE.php";
313 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
324 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
327 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
328 foreach ($feedbacks as $ident => $material)
330 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
332 foreach ($feedbacksgeneric as $correctness => $material)
334 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
339 foreach ($feedbacks as $ident => $material)
343 foreach ($feedbacksgeneric as $correctness => $material)
347 $this->
object->saveToDb();
348 if (count($item->suggested_solutions))
350 foreach ($item->suggested_solutions as $suggested_solution)
352 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
354 $this->
object->saveToDb();
358 $q_1_id = $this->
object->getId();
359 $question_id = $this->
object->duplicate(
true, null, null, null, $tst_id);
360 $tst_object->questions[$question_counter++] = $question_id;
361 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
365 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);