47 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping): array
50 $ilUser = $DIC[
'ilUser'];
55 $presentation = $item->getPresentation();
61 foreach ($presentation->order as $entry) {
62 switch ($entry[
"type"]) {
64 $response = $presentation->response[$entry[
"index"]];
68 } elseif (
$response->getIdent() ==
'OQNP') {
70 } elseif (
$response->getIdent() ==
'OQNT') {
72 } elseif (
$response->getIdent() ==
'OQT') {
77 switch (strtolower(get_class($rendertype))) {
78 case "ilqtirenderchoice":
79 $shuffle = $rendertype->getShuffle();
81 foreach ($rendertype->response_labels as $response_label) {
82 $ident = $response_label->getIdent();
86 foreach ($response_label->material as $mat) {
87 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
88 $foundmat = $mat->getMaterial($m);
90 if (strcmp($foundmat[
"material"]->getLabel() ??
'',
"answerdepth") == 0) {
91 $answerdepth = $foundmat[
"material"]->getContent();
93 if (strcmp($foundmat[
"type"],
"mattext") == 0
94 && strcmp($foundmat[
"material"]->getLabel() ??
'',
"answerdepth") != 0) {
95 $answertext .= $foundmat[
"material"]->getContent();
97 if (strcmp($foundmat[
"type"],
"matimage") == 0
98 && strcmp($foundmat[
"material"]->getLabel(),
"answerdepth") != 0) {
101 "imagetype" => $foundmat[
"material"]->getImageType(),
102 "label" => $foundmat[
"material"]->getLabel(),
103 "content" => $foundmat[
"material"]->getContent()
108 $answers[$answerorder] = [
110 "answertext" => $answertext,
111 "answerimage" => $answerimage,
113 "answerorder" => $answerorder,
114 "answerdepth" => $answerdepth,
126 $feedbacksgeneric = [];
127 foreach ($item->resprocessing as $resprocessing) {
128 foreach ($resprocessing->respcondition as $respcondition) {
131 $conditionvar = $respcondition->getConditionvar();
132 foreach ($conditionvar->order as $order) {
133 switch ($order[
"field"]) {
138 $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
139 $orderindex = $conditionvar->varequal[$order[
"index"]]->getIndex();
143 foreach ($respcondition->setvar as $setvar) {
145 $answers[$ident][
'solutionorder'] = $orderindex;
146 $answers[$ident][
'action'] = $setvar->getAction();
147 $answers[$ident][
'points'] = $setvar->getContent();
150 if (!is_array($respcondition->displayfeedback)) {
154 foreach ($respcondition->displayfeedback as $feedbackpointer) {
155 if ($feedbackpointer->getLinkrefid() ===
'') {
159 foreach ($item->itemfeedback as $ifb) {
160 if ($ifb->getIdent() ===
'response_allcorrect') {
162 foreach ($ifb->material as $material) {
163 $feedbacksgeneric[1] = $material;
165 foreach ($ifb->flow_mat as $fmat) {
166 foreach ($fmat->material as $material) {
167 $feedbacksgeneric[1] = $material;
173 if ($ifb->getIdent() ===
'response_onenotcorrect') {
175 foreach ($ifb->material as $material) {
176 $feedbacksgeneric[0] = $material;
178 foreach ($ifb->flow_mat as $fmat) {
179 foreach ($fmat->material as $material) {
180 $feedbacksgeneric[0] = $material;
192 $this->
object->setTitle($item->getTitle());
193 $this->
object->setNrOfTries((
int) $item->getMaxattempts());
194 $this->
object->setComment($item->getComment());
195 $this->
object->setAuthor($item->getAuthor());
196 $this->
object->setOwner($ilUser->getId());
198 $this->
object->setOrderingType($type);
199 $this->
object->setObjId($questionpool_id);
200 $this->
object->setThumbSize(
203 $this->
object->setElementHeight($item->getMetadataEntry(
'element_height')
204 ? (
int) $item->getMetadataEntry(
'element_height')
206 $this->
object->setShuffle($shuffle);
207 $this->
object->setPoints(0);
208 $this->
object->saveQuestionDataToDb();
212 foreach ($answers as $answer) {
213 if (isset($answer[
"solutionorder"])) {
214 $solanswers[$answer[
"solutionorder"]] = $answer;
219 $element_list = $this->
object->getOrderingElementList();
220 foreach ($solanswers as $answer) {
221 $points += $answer[
"points"];
225 if ($element->isExportIdent($answer[
'ident'])) {
226 $element->setExportIdent($answer[
'ident']);
228 $element = $element->withPosition($position++);
229 if (isset($answer[
'answerdepth'])) {
230 $element = $element->withIndentation((
int) $answer[
'answerdepth']);
234 if ($this->
object->isImageOrderingType()) {
235 $filename = $this->handleUploadedfile($answer);
237 $element = $element->withContent(
$filename);
240 $element = $element->withContent($answer[
"answertext"]);
243 $element_list->addElement($element);
245 $this->
object->setOrderingElementList($element_list);
246 $points = ($item->getMetadataEntry(
"points") > 0) ? $item->getMetadataEntry(
'points') : $points;
247 $this->
object->setPoints($points);
249 $this->
object->setAdditionalContentEditingMode(
252 $this->
object->saveToDb();
254 foreach ($feedbacksgeneric as $correctness => $material) {
256 $feedbacksgeneric[$correctness] = $m;
258 $questiontext = $this->
object->getQuestion();
270 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
274 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
275 foreach ($this->
object->getOrderingElementList() as $element) {
276 $element->setContent(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $element->getContent()));
278 foreach ($feedbacksgeneric as $correctness => $material) {
279 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
281 foreach ($itemfeedbacks as $ident => $material) {
282 $itemfeedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
287 foreach ($this->
object->getOrderingElementList() as $element) {
290 foreach ($feedbacksgeneric as $correctness => $material) {
291 $this->
object->feedbackOBJ->importGenericFeedback(
297 foreach ($itemfeedbacks as $ident => $material) {
300 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
307 $this->
object->saveToDb();
308 if (isset($tst_id) && $tst_id !== $questionpool_id) {
309 $qplQid = $this->
object->getId();
310 $tstQid = $this->
object->duplicate(
true,
'',
'', -1, $tst_id);
311 $tst_object->questions[$question_counter++] = $tstQid;
312 $import_mapping[$item->getIdent()] = [
"pool" => $qplQid,
"test" => $tstQid];
313 return $import_mapping;
317 $tst_object->questions[$question_counter++] = $this->
object->getId();
318 $import_mapping[$item->getIdent()] = [
"pool" => 0,
"test" => $this->
object->getId()];
319 return $import_mapping;
322 $import_mapping[$item->getIdent()] = [
"pool" => $this->
object->getId(),
"test" => 0];
323 return $import_mapping;
328 $image = base64_decode($answer[
"answerimage"][
"content"] ??
'');
329 $image_file_name = $answer[
'answerimage'][
'label'] ??
'';
332 $file_handle = fopen($tmp_path,
"wb");
333 if ($file_handle ===
false) {
336 fwrite($file_handle, $image);
337 fclose($file_handle);
339 $filename_path_parts = explode(
".", $image_file_name);
340 $suffix = strtolower(array_pop($filename_path_parts));
346 $target_filename = $this->
object->buildHashedImageFilename($image_file_name,
true);
347 $target_filepath = $this->
object->getImagePath() . $target_filename;
348 if (rename($tmp_path, $target_filepath)) {
349 $thumb_path = $this->
object->getImagePath() . $this->
object->getThumbPrefix() . $target_filename;
351 return $target_filename;
359 if (!file_exists($this->
object->getImagePath())) {
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)
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
deduceThumbSizeFromImportValue(?int $size)
addGeneralMetadata(ilQTIItem $item)
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping)
Creates a question from a QTI file.
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
const VALID_UPLOAD_SUFFIXES
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const OQ_PICTURES
Ordering question constants.
handleUploadedFile(array $answer)
static convertImage(string $a_from, string $a_to, string $a_target_format="", string $a_geometry="", string $a_background_color="")
importSuggestedSolutions(int $question_id, array $solution_from_import)
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
Class for question imports.
static clear(string $a_var)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')