43 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping): array
50 $presentation = $item->getPresentation();
52 $selectionLimit = null;
54 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
56 foreach ($presentation->order as $entry) {
57 switch ($entry[
"type"]) {
59 $response = $presentation->response[$entry[
"index"]];
61 switch (strtolower(get_class(
$response->getRenderType()))) {
62 case "ilqtirenderchoice":
63 $shuffle = $rendertype->getShuffle();
64 if ($rendertype->getMaxnumber()) {
65 $selectionLimit = $rendertype->getMaxnumber();
69 foreach ($rendertype->response_labels as $response_label) {
70 $ident = $response_label->getIdent();
72 $answerimage = array();
73 foreach ($response_label->material as $mat) {
75 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
76 $foundmat = $mat->getMaterial($m);
77 if (strcmp($foundmat[
"type"],
"mattext") == 0) {
79 if (strcmp($foundmat[
"type"],
"matimage") == 0) {
80 if (strlen($foundmat[
"material"]->getEmbedded())) {
86 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
87 $foundmat = $mat->getMaterial($m);
88 if (strcmp($foundmat[
"type"],
"mattext") == 0) {
89 $answertext .= $foundmat[
"material"]->getContent();
91 if (strcmp($foundmat[
"type"],
"matimage") == 0) {
94 "imagetype" => $foundmat[
"material"]->getImageType(),
95 "label" => $foundmat[
"material"]->getLabel(),
96 "content" => $foundmat[
"material"]->
getContent()
101 $answertext = $this->
object->QTIMaterialToString($mat);
104 $answers[$ident] = array(
105 "answertext" => $answertext,
106 "imagefile" => $answerimage,
108 "answerorder" => $answerorder++,
109 "points_unchecked" => 0,
118 $responses = array();
119 $feedbacks = array();
120 $feedbacksgeneric = array();
121 foreach ($item->resprocessing as $resprocessing) {
122 foreach ($resprocessing->respcondition as $respcondition) {
125 $conditionvar = $respcondition->getConditionvar();
126 foreach ($conditionvar->order as $order) {
127 switch ($order[
"field"]) {
132 $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
136 foreach ($respcondition->setvar as $setvar) {
137 if (strcmp($ident,
"") != 0) {
139 $answers[$ident][
"action"] = $setvar->getAction();
140 $answers[$ident][
"points"] = $setvar->getContent();
141 if (count($respcondition->displayfeedback)) {
142 foreach ($respcondition->displayfeedback as $feedbackpointer) {
143 if (strlen($feedbackpointer->getLinkrefid())) {
144 foreach ($item->itemfeedback as $ifb) {
145 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0) {
147 if (count($ifb->material)) {
148 foreach ($ifb->material as $material) {
149 $feedbacksgeneric[1] = $material;
152 if ((count($ifb->flow_mat) > 0)) {
153 foreach ($ifb->flow_mat as $fmat) {
154 if (count($fmat->material)) {
155 foreach ($fmat->material as $material) {
156 $feedbacksgeneric[1] = $material;
161 } elseif (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0) {
163 if (count($ifb->material)) {
164 foreach ($ifb->material as $material) {
165 $feedbacksgeneric[0] = $material;
168 if ((count($ifb->flow_mat) > 0)) {
169 foreach ($ifb->flow_mat as $fmat) {
170 if (count($fmat->material)) {
171 foreach ($fmat->material as $material) {
172 $feedbacksgeneric[0] = $material;
178 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
180 if (count($ifb->material)) {
181 foreach ($ifb->material as $material) {
182 $feedbacks[$ident] = $material;
185 if ((count($ifb->flow_mat) > 0)) {
186 foreach ($ifb->flow_mat as $fmat) {
187 if (count($fmat->material)) {
188 foreach ($fmat->material as $material) {
189 $feedbacks[$ident] = $material;
200 $answers[$ident][
"action"] = $setvar->getAction();
201 $answers[$ident][
"points_unchecked"] = $setvar->getContent();
208 $this->
object->setTitle($item->getTitle());
209 $this->
object->setNrOfTries((
int) $item->getMaxattempts());
210 $this->
object->setComment($item->getComment());
211 $this->
object->setAuthor($item->getAuthor());
212 $this->
object->setOwner(
$ilUser->getId());
213 $this->
object->setQuestion($this->
object->QTIMaterialToString($item->getQuestiontext()));
214 $this->
object->setObjId($questionpool_id);
215 $this->
object->setShuffle($shuffle);
216 $this->
object->setSelectionLimit($selectionLimit);
217 $this->
object->setThumbSize(
221 foreach ($answers as $answer) {
222 if ($item->getMetadataEntry(
'singleline') || (is_array($answer[
"imagefile"]) && count($answer[
"imagefile"]) > 0)) {
223 $this->
object->setIsSingleline(
true);
225 $this->
object->addAnswer($answer[
"answertext"], $answer[
"points"], $answer[
"points_unchecked"], $answer[
"answerorder"], $answer[
"imagefile"][
"label"] ??
'');
228 $this->
object->setAdditionalContentEditingMode(
231 $this->
object->saveToDb();
232 foreach ($answers as $answer) {
233 if (is_array($answer[
"imagefile"]) && (count($answer[
"imagefile"]) > 0)) {
234 $image = base64_decode($answer[
"imagefile"][
"content"]);
235 $imagepath = $this->
object->getImagePath();
236 if (!file_exists($imagepath)) {
239 $imagepath .= $answer[
"imagefile"][
"label"];
240 $fh = fopen($imagepath,
"wb");
243 $imagefile = fwrite($fh, $image);
249 $feedbackSetting = $item->getMetadataEntry(
'feedback_setting');
250 if (!is_null($feedbackSetting)) {
251 $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->
object->getId(), $feedbackSetting);
255 foreach ($feedbacks as $ident => $material) {
256 $m = $this->
object->QTIMaterialToString($material);
257 $feedbacks[$ident] = $m;
259 foreach ($feedbacksgeneric as $correctness => $material) {
260 $m = $this->
object->QTIMaterialToString($material);
261 $feedbacksgeneric[$correctness] = $m;
263 $questiontext = $this->
object->getQuestion();
264 $answers = &$this->
object->getAnswers();
274 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
278 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
279 foreach ($answers as
$key => $value) {
280 $answer_obj = &$answers[
$key];
281 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
283 foreach ($feedbacks as $ident => $material) {
284 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
286 foreach ($feedbacksgeneric as $correctness => $material) {
287 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
292 foreach ($answers as
$key => $value) {
293 $answer_obj = &$answers[
$key];
296 foreach ($feedbacks as $ident => $material) {
297 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
304 foreach ($feedbacksgeneric as $correctness => $material) {
305 $this->
object->feedbackOBJ->importGenericFeedback(
311 $this->
object->saveToDb();
312 if (count($item->suggested_solutions)) {
313 foreach ($item->suggested_solutions as $suggested_solution) {
314 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->
getContent(), $suggested_solution[
"gap_index"],
true);
316 $this->
object->saveToDb();
319 $q_1_id = $this->
object->getId();
320 $question_id = $this->
object->duplicate(
true,
"",
"",
"", $tst_id);
321 $tst_object->questions[$question_counter++] = $question_id;
322 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
324 $import_mapping[$item->getIdent()] = array(
"pool" => $this->
object->getId(),
"test" => 0);
326 return $import_mapping;
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static get(string $a_var)
deduceThumbSizeFromImportValue(?int $size)
addGeneralMetadata(ilQTIItem $item)
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) ...
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping)
Creates a question from a QTI file.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static clear(string $a_var)