4include_once
"./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
30 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
35 $presentation = $item->getPresentation();
38 $selectionLimit =
null;
40 $created =
sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
42 foreach ($presentation->order as $entry)
44 switch ($entry[
"type"])
47 $response = $presentation->response[$entry[
"index"]];
48 $rendertype = $response->getRenderType();
49 switch (strtolower(get_class($response->getRenderType())))
51 case "ilqtirenderchoice":
52 $shuffle = $rendertype->getShuffle();
53 if($rendertype->getMaxnumber())
55 $selectionLimit = $rendertype->getMaxnumber();
59 foreach ($rendertype->response_labels as $response_label)
61 $ident = $response_label->getIdent();
63 $answerimage = array();
64 foreach ($response_label->material as $mat)
67 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
69 $foundmat = $mat->getMaterial($m);
70 if (strcmp($foundmat[
"type"],
"mattext") == 0)
73 if (strcmp($foundmat[
"type"],
"matimage") == 0)
75 if (strlen($foundmat[
"material"]->getEmbedded()))
83 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
85 $foundmat = $mat->getMaterial($m);
86 if (strcmp($foundmat[
"type"],
"mattext") == 0)
88 $answertext .= $foundmat[
"material"]->getContent();
90 if (strcmp($foundmat[
"type"],
"matimage") == 0)
94 "imagetype" => $foundmat[
"material"]->getImageType(),
95 "label" => $foundmat[
"material"]->getLabel(),
96 "content" => $foundmat[
"material"]->getContent()
103 $answertext = $this->
object->QTIMaterialToString($mat);
106 $answers[$ident] = array(
107 "answertext" => $answertext,
108 "imagefile" => $answerimage,
110 "answerorder" => $answerorder++,
111 "points_unchecked" => 0,
120 $responses = array();
121 $feedbacks = array();
122 $feedbacksgeneric = array();
123 foreach ($item->resprocessing as $resprocessing)
125 foreach ($resprocessing->respcondition as $respcondition)
129 $conditionvar = $respcondition->getConditionvar();
130 foreach ($conditionvar->order as $order)
132 switch ($order[
"field"])
138 $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
142 foreach ($respcondition->setvar as $setvar)
144 if (strcmp($ident,
"") != 0)
148 $answers[$ident][
"action"] = $setvar->getAction();
149 $answers[$ident][
"points"] = $setvar->getContent();
150 if (count($respcondition->displayfeedback))
152 foreach ($respcondition->displayfeedback as $feedbackpointer)
154 if (strlen($feedbackpointer->getLinkrefid()))
156 foreach ($item->itemfeedback as $ifb)
158 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0)
161 if (count($ifb->material))
163 foreach ($ifb->material as $material)
165 $feedbacksgeneric[1] = $material;
168 if ((count($ifb->flow_mat) > 0))
170 foreach ($ifb->flow_mat as $fmat)
172 if (count($fmat->material))
174 foreach ($fmat->material as $material)
176 $feedbacksgeneric[1] = $material;
182 else if (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0)
185 if (count($ifb->material))
187 foreach ($ifb->material as $material)
189 $feedbacksgeneric[0] = $material;
192 if ((count($ifb->flow_mat) > 0))
194 foreach ($ifb->flow_mat as $fmat)
196 if (count($fmat->material))
198 foreach ($fmat->material as $material)
200 $feedbacksgeneric[0] = $material;
206 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0)
209 if (count($ifb->material))
211 foreach ($ifb->material as $material)
213 $feedbacks[$ident] = $material;
216 if ((count($ifb->flow_mat) > 0))
218 foreach ($ifb->flow_mat as $fmat)
220 if (count($fmat->material))
222 foreach ($fmat->material as $material)
224 $feedbacks[$ident] = $material;
237 $answers[$ident][
"action"] = $setvar->getAction();
238 $answers[$ident][
"points_unchecked"] = $setvar->getContent();
245 $this->
object->setTitle($item->getTitle());
246 $this->
object->setNrOfTries($item->getMaxattempts());
247 $this->
object->setComment($item->getComment());
248 $this->
object->setAuthor($item->getAuthor());
249 $this->
object->setOwner($ilUser->getId());
250 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
251 $this->
object->setObjId($questionpool_id);
253 $this->
object->setShuffle($shuffle);
254 $this->
object->setSelectionLimit($selectionLimit);
255 $this->
object->setThumbSize($item->getMetadataEntry(
"thumb_size"));
257 foreach ($answers as $answer)
259 if ($item->getMetadataEntry(
'singleline') || (is_array($answer[
"imagefile"]) && count($answer[
"imagefile"]) > 0))
261 $this->
object->isSingleline =
true;
263 $this->
object->addAnswer($answer[
"answertext"], $answer[
"points"], $answer[
"points_unchecked"], $answer[
"answerorder"], $answer[
"imagefile"][
"label"]);
266 $this->
object->setAdditionalContentEditingMode(
269 $this->
object->saveToDb();
270 foreach ($answers as $answer)
272 if (is_array($answer[
"imagefile"]) && (count($answer[
"imagefile"]) > 0))
274 $image =& base64_decode($answer[
"imagefile"][
"content"]);
275 $imagepath = $this->
object->getImagePath();
276 include_once
"./Services/Utilities/classes/class.ilUtil.php";
277 if (!file_exists($imagepath))
281 $imagepath .= $answer[
"imagefile"][
"label"];
282 $fh = fopen($imagepath,
"wb");
288 $imagefile = fwrite(
$fh, $image);
294 $feedbackSetting = $item->getMetadataEntry(
'feedback_setting');
295 if( !is_null($feedbackSetting) )
297 $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting);
301 foreach ($feedbacks as $ident => $material)
303 $m = $this->
object->QTIMaterialToString($material);
304 $feedbacks[$ident] = $m;
306 foreach ($feedbacksgeneric as $correctness => $material)
308 $m = $this->
object->QTIMaterialToString($material);
309 $feedbacksgeneric[$correctness] = $m;
311 $questiontext = $this->
object->getQuestion();
312 $answers =& $this->
object->getAnswers();
313 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
315 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
316 include_once
"./Services/RTE/classes/class.ilRTE.php";
317 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
328 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
332 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
333 foreach ($answers as $key => $value)
335 $answer_obj =& $answers[$key];
336 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
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 ($answers as $key => $value)
351 $answer_obj =& $answers[$key];
354 foreach ($feedbacks as $ident => $material)
356 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
360 foreach ($feedbacksgeneric as $correctness => $material)
362 $this->
object->feedbackOBJ->importGenericFeedback(
366 $this->
object->saveToDb();
367 if (count($item->suggested_solutions))
369 foreach ($item->suggested_solutions as $suggested_solution)
371 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
373 $this->
object->saveToDb();
377 $q_1_id = $this->
object->getId();
378 $question_id = $this->
object->duplicate(
true,
null,
null,
null, $tst_id);
379 $tst_object->questions[$question_counter++] = $question_id;
380 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
384 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
Class for multiple choice question imports.
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
Class for question imports.
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir)
addGeneralMetadata(ilQTIItem $item)
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir)
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.