4 include_once
"./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
30 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
36 $presentation = $item->getPresentation();
37 $duration = $item->getDuration();
38 $questiontext = array();
41 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
43 foreach ($presentation->order as $entry)
45 switch ($entry[
"type"])
49 $material = $presentation->material[$entry[
"index"]];
50 array_push($questiontext, $this->object->QTIMaterialToString($material));
53 $response = $presentation->response[$entry[
"index"]];
54 $rendertype = $response->getRenderType();
55 array_push($questiontext,
"<<" . $response->getIdent() .
">>");
56 switch (strtolower(get_class($response->getRenderType())))
58 case "ilqtirenderfib":
59 switch ($response->getRenderType()->getFibtype())
65 "ident" => $response->getIdent(),
68 "minnumber" => $response->getRenderType()->getMinnumber(),
69 "maxnumber" => $response->getRenderType()->getMaxnumber()
75 array_push($gaps, array(
"ident" => $response->getIdent(),
"type" =>
CLOZE_TEXT,
"answers" => array()));
79 case "ilqtirenderchoice":
81 $shuffle = $rendertype->getShuffle();
83 foreach ($rendertype->response_labels as $response_label)
85 $ident = $response_label->getIdent();
87 foreach ($response_label->material as $mat)
89 $answertext .= $this->
object->QTIMaterialToString($mat);
91 $answers[$ident] = array(
92 "answertext" => $answertext,
94 "answerorder" => $answerorder++,
96 "shuffle" => $rendertype->getShuffle()
99 array_push($gaps, array(
"ident" => $response->getIdent(),
"type" =>
CLOZE_SELECT,
"shuffle" => $rendertype->getShuffle(),
"answers" => $answers));
105 $responses = array();
106 $feedbacks = array();
107 $feedbacksgeneric = array();
108 foreach ($item->resprocessing as $resprocessing)
110 foreach ($resprocessing->respcondition as $respcondition)
114 $conditionvar = $respcondition->getConditionvar();
115 foreach ($conditionvar->order as $order)
117 switch ($order[
"field"])
120 $equals = $conditionvar->varequal[$order[
"index"]]->getContent();
121 $gapident = $conditionvar->varequal[$order[
"index"]]->getRespident();
125 foreach ($respcondition->setvar as $setvar)
127 if (strcmp($gapident,
"") != 0)
129 foreach ($gaps as $gi => $g)
131 if (strcmp($g[
"ident"], $gapident) == 0)
135 foreach ($gaps[$gi][
"answers"] as $ai => $answer)
137 if (strcmp($answer[
"answertext"], $equals) == 0)
139 $gaps[$gi][
"answers"][$ai][
"action"] = $setvar->getAction();
140 $gaps[$gi][
"answers"][$ai][
"points"] = $setvar->getContent();
146 array_push($gaps[$gi][
"answers"], array(
147 "answertext" => $equals,
148 "points" => $setvar->getContent(),
149 "answerorder" => count($gaps[$gi][
"answers"]),
150 "action" => $setvar->getAction()
155 array_push($gaps[$gi][
"answers"], array(
156 "answertext" => $equals,
157 "points" => $setvar->getContent(),
158 "answerorder" => count($gaps[$gi][
"answers"]),
159 "action" => $setvar->getAction()
167 if (count($respcondition->displayfeedback))
169 foreach ($respcondition->displayfeedback as $feedbackpointer)
171 if (strlen($feedbackpointer->getLinkrefid()))
173 foreach ($item->itemfeedback as $ifb)
175 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0)
178 if (count($ifb->material))
180 foreach ($ifb->material as $material)
182 $feedbacksgeneric[1] = $material;
185 if ((count($ifb->flow_mat) > 0))
187 foreach ($ifb->flow_mat as $fmat)
189 if (count($fmat->material))
191 foreach ($fmat->material as $material)
193 $feedbacksgeneric[1] = $material;
199 else if (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0)
202 if (count($ifb->material))
204 foreach ($ifb->material as $material)
206 $feedbacksgeneric[0] = $material;
209 if ((count($ifb->flow_mat) > 0))
211 foreach ($ifb->flow_mat as $fmat)
213 if (count($fmat->material))
215 foreach ($fmat->material as $material)
217 $feedbacksgeneric[0] = $material;
226 if (count($ifb->material))
228 foreach ($ifb->material as $material)
230 $feedbacks[$ifb->getIdent()] = $material;
233 if ((count($ifb->flow_mat) > 0))
235 foreach ($ifb->flow_mat as $fmat)
237 if (count($fmat->material))
239 foreach ($fmat->material as $material)
241 $feedbacks[$ifb->getIdent()] = $material;
257 $this->
object->setTitle($item->getTitle());
258 $this->
object->setNrOfTries($item->getMaxattempts());
259 $this->
object->setComment($item->getComment());
260 $this->
object->setAuthor($item->getAuthor());
261 $this->
object->setOwner($ilUser->getId());
262 $this->
object->setObjId($questionpool_id);
263 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
264 $textgap_rating = $item->getMetadataEntry(
"textgaprating");
265 $this->
object->setFixedTextLength($item->getMetadataEntry(
"fixedTextLength"));
266 $this->
object->setIdenticalScoring($item->getMetadataEntry(
"identicalScoring"));
267 if (strlen($textgap_rating) == 0) $textgap_rating =
"ci";
268 $this->
object->setTextgapRating($textgap_rating);
270 foreach ($gaps as $gapidx => $gap)
272 $gapcontent = array();
273 include_once
"./Modules/TestQuestionPool/classes/class.assClozeGap.php";
275 foreach ($gap[
"answers"] as $index => $answer)
277 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerCloze.php";
278 $gapanswer =
new assAnswerCloze($answer[
"answertext"], $answer[
"points"], $answer[
"answerorder"]);
279 switch ($clozegap->getType())
282 $clozegap->setShuffle($answer[
"shuffle"]);
285 $gapanswer->setLowerBound($gap[
"minnumber"]);
286 $gapanswer->setUpperBound($gap[
"maxnumber"]);
289 $clozegap->addItem($gapanswer);
290 array_push($gapcontent, $answer[
"answertext"]);
292 $this->
object->addGapAtIndex($clozegap, $gapidx);
293 $gaptext[$gap[
"ident"]] =
"[gap]" . join(
",", $gapcontent).
"[/gap]";
295 $clozetext = join(
"", $questiontext);
296 foreach ($gaptext as $idx => $val)
298 $clozetext = str_replace(
"<<" . $idx .
">>", $val, $clozetext);
300 $this->
object->setQuestion($clozetext);
302 $this->
object->setAdditionalContentEditingMode(
305 $this->
object->saveToDb();
308 foreach ($feedbacks as $ident => $material)
310 $m = $this->
object->QTIMaterialToString($material);
311 $feedbacks[$ident] = $m;
313 foreach ($feedbacksgeneric as $correctness => $material)
315 $m = $this->
object->QTIMaterialToString($material);
316 $feedbacksgeneric[$correctness] = $m;
318 $questiontext = $this->
object->getQuestion();
319 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
321 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
322 include_once
"./Services/RTE/classes/class.ilRTE.php";
323 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
334 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
337 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
338 foreach ($feedbacks as $ident => $material)
340 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
342 foreach ($feedbacksgeneric as $correctness => $material)
344 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
349 foreach ($feedbacks as $ident => $material)
351 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
355 foreach ($feedbacksgeneric as $correctness => $material)
357 $this->
object->feedbackOBJ->importGenericFeedback(
361 $this->
object->saveToDb();
362 if (count($item->suggested_solutions))
364 foreach ($item->suggested_solutions as $suggested_solution)
366 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
368 $this->
object->saveToDb();
372 $q_1_id = $this->
object->getId();
373 $question_id = $this->
object->duplicate(
true, null, null, null, $tst_id);
374 $tst_object->questions[$question_counter++] = $question_id;
375 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
379 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);
Class for cloze question numeric answers.
addGeneralMetadata(ilQTIItem $item)
const CLOZE_TEXT
Cloze question constants.
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir) ...
Class for cloze question gaps.
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0)
replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
Class for cloze question imports.
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
Class for question imports.