ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.assErrorTextImport.php
Go to the documentation of this file.
1<?php
2
27{
41 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping): array
42 {
43 global $DIC;
44 $ilUser = $DIC['ilUser'];
45
46 // empty session variable for imported xhtml mobs
47 ilSession::clear('import_mob_xhtml');
48
49 $presentation = $item->getPresentation();
50 $now = getdate();
51 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
52
53 $feedbacksgeneric = array();
54
55 $this->addGeneralMetadata($item);
56 $this->object->setTitle($item->getTitle());
57 $this->object->setNrOfTries((int) $item->getMaxattempts());
58 $this->object->setComment($item->getComment());
59 $this->object->setAuthor($item->getAuthor());
60 $this->object->setOwner($ilUser->getId());
61 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
62 $this->object->setObjId($questionpool_id);
63 $this->object->setPointsWrong($item->getMetadataEntry("points_wrong"));
64 $this->object->setErrorText($item->getMetadataEntry("errortext"));
65 $parsed_error_text = $item->getMetadataEntry("parsederrortext");
66 if ($parsed_error_text !== null) {
67 $this->object->setParsedErrorText(unserialize($parsed_error_text, ['allowed_classes' => false]));
68 }
69 $this->object->setTextSize($item->getMetadataEntry("textsize"));
70 $errordata = unserialize($item->getMetadataEntry("errordata"), ["allowed_classes" => false]);
71 if (is_array($errordata)) {
72 $errordata_answers_array = [];
73 foreach ($errordata as $data) {
74 $errordata_answers_array[] = new assAnswerErrorText($data[1], $data[0] ?? '', $data[2], $data[3] ?? null);
75 }
76 $this->object->setErrorData($errordata_answers_array);
77 }
78 // additional content editing mode information
79 $this->object->setAdditionalContentEditingMode(
81 );
82 $this->object->saveToDb();
83
84 $feedbacks = $this->getFeedbackAnswerSpecific($item);
85 $feedbacksgeneric = $this->getFeedbackGeneric($item);
86
87 // handle the import of media objects in XHTML code
88 $questiontext = $this->object->getQuestion();
89 if (is_array(ilSession::get("import_mob_xhtml"))) {
90 foreach (ilSession::get("import_mob_xhtml") as $mob) {
91 if ($tst_id > 0) {
92 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
93 } else {
94 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
95 }
96
97 global $DIC; /* @var ILIAS\DI\Container $DIC */
98 $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
99
100 $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
101 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
102 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
103 foreach ($feedbacks as $ident => $material) {
104 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
105 }
106 foreach ($feedbacksgeneric as $correctness => $material) {
107 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
108 }
109 }
110 }
111 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
112
113 foreach ($feedbacks as $ident => $material) {
114 $index = $this->fetchIndexFromFeedbackIdent($ident);
115
116 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
117 $this->object->getId(),
118 0,
119 $index,
121 );
122 }
123 foreach ($feedbacksgeneric as $correctness => $material) {
124 $this->object->feedbackOBJ->importGenericFeedback(
125 $this->object->getId(),
126 $correctness,
128 );
129 }
130
131 $this->object->saveToDb();
132 if (count($item->suggested_solutions)) {
133 foreach ($item->suggested_solutions as $suggested_solution) {
134 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
135 }
136 $this->object->saveToDb();
137 }
138 if ($tst_id > 0) {
139 $q_1_id = $this->object->getId();
140 $question_id = $this->object->duplicate(true, "", "", "", $tst_id);
141 $tst_object->questions[$question_counter++] = $question_id;
142 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
143 } else {
144 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
145 }
146 return $import_mapping;
147 }
148}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
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)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')
static _saveTempFileAsMediaObject(string $name, string $tmp_name, bool $upload=true)
Create new media object and update page in db and return new media object.
static _saveUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Save usage of mob within another container (e.g.
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)
static clear(string $a_var)
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
$index
Definition: metadata.php:145
int $created
Timestamp for when the object was created.
Definition: System.php:151