43 : array {
45
46 $shuffle = 0;
47 $answers = [];
48
50 foreach ($presentation->order as $entry) {
51 if ($entry['type'] !== 'response') {
52 continue;
53 }
54
55 $response = $presentation->response[$entry[
'index']];
57 if (strtolower(get_class(
$response->getRenderType())) !==
'ilqtirenderchoice') {
58 continue;
59 }
60
61 $shuffle = $rendertype->getShuffle();
62 $foundimage = false;
63 foreach ($rendertype->response_labels as $response_label) {
64 $ident = $response_label->getIdent();
65 $answertext = '';
66 $answerimage = [];
67 foreach ($response_label->material as $mat) {
68 $embedded = false;
69 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
70 $foundmat = $mat->getMaterial($m);
71 if ($foundmat['type'] === 'matimage'
72 && $foundmat['material']->getEmbedded() !== '') {
73 $embedded = true;
74 }
75 }
76 if (!$embedded) {
78 continue;
79 }
80
81 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
82 $foundmat = $mat->getMaterial($m);
83 if ($foundmat['type'] === 'mattext') {
84 $answertext .= $foundmat['material']->getContent();
85 }
86 if ($foundmat['type'] === 'matimage') {
87 $foundimage = true;
88 $answerimage = [
89 'imagetype' => $foundmat['material']->getImageType(),
90 'label' => $foundmat['material']->getLabel(),
91 'content' => $foundmat['material']->getContent()
92 ];
93 }
94 }
95 }
96
97 $answers[$ident] = [
98 'answertext' => $answertext,
99 'imagefile' => $answerimage,
100 'answerorder' => $ident
101 ];
102 }
103 }
104
105 $feedbacks = [];
106 $feedbacksgeneric = [];
107
108 foreach ($item->resprocessing as $resprocessing) {
109 foreach ($resprocessing->outcomes->decvar as $decvar) {
110 if ($decvar->getVarname() == 'SCORE') {
111 $this->object->setPoints($decvar->getMaxvalue());
112 $this->object->setScorePartialSolutionEnabled(false);
113 if ($decvar->getMinvalue() > 0) {
114 $this->object->setScorePartialSolutionEnabled(true);
115 }
116 }
117 }
118
119 foreach ($resprocessing->respcondition as $respcondition) {
120 if ($respcondition->setvar === []) {
121 foreach ($respcondition->getConditionvar()->varequal as $varequal) {
122 $ident = $varequal->respident;
123 $answers[$ident]['correctness'] = (bool) $varequal->getContent();
124 break;
125 }
126
127 foreach ($respcondition->displayfeedback as $feedbackpointer) {
128 if ($feedbackpointer->getLinkrefid() === '') {
129 continue;
130 }
131 foreach ($item->itemfeedback as $ifb) {
132 if ($ifb->getIdent() !== $feedbackpointer->getLinkrefid()) {
133 continue;
134 }
135
136 foreach ($ifb->material as $material) {
137 $feedbacks[$ident] = $material;
138 }
139 foreach ($ifb->flow_mat as $fmat) {
140 foreach ($fmat->material as $material) {
141 $feedbacks[$ident] = $material;
142 }
143 }
144 }
145 }
146
147 continue;
148 }
149
150 foreach ($respcondition->displayfeedback as $feedbackpointer) {
151 if ($feedbackpointer->getLinkrefid() === '') {
152 continue;
153 }
154
155 foreach ($item->itemfeedback as $ifb) {
156 if ($ifb->getIdent() === 'response_allcorrect') {
157 foreach ($ifb->material as $material) {
158 $feedbacksgeneric[1] = $material;
159 }
160 foreach ($ifb->flow_mat as $fmat) {
161 foreach ($fmat->material as $material) {
162 $feedbacksgeneric[1] = $material;
163 }
164 }
165 continue;
166 }
167
168 if ($ifb->getIdent() === 'response_onenotcorrect') {
169
170 foreach ($ifb->material as $material) {
171 $feedbacksgeneric[0] = $material;
172 }
173 foreach ($ifb->flow_mat as $fmat) {
174 foreach ($fmat->material as $material) {
175 $feedbacksgeneric[0] = $material;
176 }
177 }
178 }
179 }
180 }
181 }
182 }
183
185 $this->
object->setTitle($item->
getTitle());
187 $this->
object->setComment($item->
getComment());
188 $this->
object->setAuthor($item->
getAuthor());
191 $this->object->setObjId($questionpool_id);
192 $this->object->setShuffleAnswersEnabled($shuffle);
194 $this->
object->setOptionLabel($item->
getMetadataEntry(
'option_label_setting'));
195 $this->
object->setCustomTrueOptionLabel($item->
getMetadataEntry(
'custom_true_option_label'));
196 $this->
object->setCustomFalseOptionLabel($item->
getMetadataEntry(
'custom_false_option_label'));
197 $this->object->setThumbSize(
199 );
200
201 $this->object->saveToDb();
202
203 $answer_objects = [];
204 foreach ($answers as $answer_data) {
206 $answer->setImageFsDir($this->
object->getImagePath());
207 $answer->setImageWebDir($this->
object->getImagePathWeb());
208 $answer->setPosition($answer_data['answerorder']);
209 $answer->setAnswertext($answer_data['answertext']);
210 $answer->setCorrectness($answer_data['correctness']);
211 if (isset($answer_data['imagefile']['label'])) {
212 $answer->setImageFile($answer_data['imagefile']['label']);
213 }
214 $answer_objects[] = $answer;
215 }
216 $this->object->setAnswers($answer_objects);
217
218 $this->object->setAdditionalContentEditingMode(
220 );
221
222 $this->object->saveToDb();
223
224 foreach ($answers as $answer) {
225 if (!is_array($answer['imagefile']) || $answer['imagefile'] === []) {
226 continue;
227 }
228 $image = base64_decode($answer['imagefile']['content']);
229 $imagepath = $this->object->getImagePath();
230 if (!file_exists($imagepath)) {
232 }
233 $imagepath .= $answer['imagefile']['label'];
234 if ($fh = fopen($imagepath, 'wb')) {
235 $imagefile = fwrite($fh, $image);
236 fclose($fh);
237 $this->object->generateThumbForFile(
238 $answer['imagefile']['label'],
239 $this->
object->getImagePath(),
240 $this->object->getThumbSize()
241 );
242 }
243 }
244
246 if (!is_null($feedback_setting)) {
247 $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->
object->getId(), $feedback_setting);
248 $this->object->setSpecificFeedbackSetting($feedback_setting);
249 }
250
251
252 foreach ($feedbacks as $ident => $material) {
254 $feedbacks[$ident] = $m;
255 }
256 foreach ($feedbacksgeneric as $correctness => $material) {
258 $feedbacksgeneric[$correctness] = $m;
259 }
260 $questiontext = $this->object->getQuestion();
261 $answers = $this->object->getAnswers();
264 $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob["uri"];
265
267 $DIC[
'ilLog']->info(
'import mob from dir: ' . $importfile);
268
271 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
272 foreach ($answers as $answer_obj) {
273 if ($answer_obj->getAnswertext() === null) {
274 continue;
275 }
276 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
277 }
278 foreach ($feedbacks as $ident => $material) {
279 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
280 }
281 foreach ($feedbacksgeneric as $correctness => $material) {
282 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
283 }
284 }
285 }
287 foreach ($answers as $answer_obj) {
288 if ($answer_obj->getAnswertext() === null) {
289 continue;
290 }
292 }
293 foreach ($feedbacks as $ident => $material) {
294 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
296 0,
297 $ident,
299 );
300 }
301 foreach ($feedbacksgeneric as $correctness => $material) {
302 $this->object->feedbackOBJ->importGenericFeedback(
304 $correctness,
306 );
307 }
308 $this->object->saveToDb();
311 $questionpool_id,
312 $tst_id,
313 $question_counter,
314 $tst_object
315 );
316 return $import_mapping;
317 }
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
addQuestionToParentObjectAndBuildMappingEntry(int $questionpool_id, ?int $tst_id, int &$question_counter, ?ilObjTest &$tst_object)
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
addGeneralMetadata(ilQTIItem $item)
deduceThumbSizeFromImportValue(?int $size)
importSuggestedSolutions(int $question_id, array $solution_from_import)
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
getMetadataEntry(string $a_label)
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)