39 : array {
40
42
44 $shuffle = 0;
45 $selectionLimit = null;
46 $now = getdate();
47 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
48 $answers = [];
49 foreach ($presentation->order as $entry) {
50 switch ($entry["type"]) {
51 case "response":
52 $response = $presentation->response[$entry[
"index"]];
54 switch (strtolower(get_class(
$response->getRenderType()))) {
55 case "ilqtirenderchoice":
56 $shuffle = $rendertype->getShuffle();
57 if ($rendertype->getMaxnumber()) {
58 $selectionLimit = $rendertype->getMaxnumber();
59 }
60 $answerorder = 0;
61 $foundimage = false;
62 foreach ($rendertype->response_labels as $response_label) {
63 $ident = $response_label->getIdent();
64 $answertext = "";
65 $answerimage = [];
66 foreach ($response_label->material as $mat) {
67 $embedded = false;
68 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
69 $foundmat = $mat->getMaterial($m);
70 if (strcmp($foundmat["type"], "mattext") == 0) {
71 }
72 if (strcmp($foundmat["type"], "matimage") == 0) {
73 if (strlen($foundmat["material"]->getEmbedded())) {
74 $embedded = true;
75 }
76 }
77 }
78 if ($embedded) {
79 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
80 $foundmat = $mat->getMaterial($m);
81 if (strcmp($foundmat["type"], "mattext") == 0) {
82 $answertext .= $foundmat["material"]->getContent();
83 }
84 if (strcmp($foundmat["type"], "matimage") == 0) {
85 $foundimage = true;
86 $answerimage = [
87 "imagetype" => $foundmat["material"]->getImageType(),
88 "label" => $foundmat["material"]->getLabel(),
89 "content" => $foundmat["material"]->getContent()
90 ];
91 }
92 }
93 } else {
95 }
96 }
97 $answers[$ident] = [
98 "answertext" => $answertext,
99 "imagefile" => $answerimage,
100 "points" => 0,
101 "answerorder" => $answerorder++,
102 "points_unchecked" => 0,
103 "action" => ""
104 ];
105 }
106 break;
107 }
108 break;
109 }
110 }
111 $feedbacks = [];
112 $feedbacksgeneric = [];
113 foreach ($item->resprocessing as $resprocessing) {
114 foreach ($resprocessing->respcondition as $respcondition) {
115 $ident = "";
116 $correctness = 1;
117 $conditionvar = $respcondition->getConditionvar();
118 foreach ($conditionvar->order as $order) {
119 switch ($order["field"]) {
120 case "arr_not":
121 $correctness = 0;
122 break;
123 case "varequal":
124 $ident = $conditionvar->varequal[$order["index"]]->getContent();
125 break;
126 }
127 }
128 foreach ($respcondition->setvar as $setvar) {
129 if (strcmp($ident, "") != 0) {
130 if ($correctness) {
131 $answers[$ident]["action"] = $setvar->getAction();
132 $answers[$ident]["points"] = $setvar->getContent();
133 if (count($respcondition->displayfeedback)) {
134 foreach ($respcondition->displayfeedback as $feedbackpointer) {
135 if (strlen($feedbackpointer->getLinkrefid())) {
136 foreach ($item->itemfeedback as $ifb) {
137 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
138
139 if (count($ifb->material)) {
140 foreach ($ifb->material as $material) {
141 $feedbacksgeneric[1] = $material;
142 }
143 }
144 if ((count($ifb->flow_mat) > 0)) {
145 foreach ($ifb->flow_mat as $fmat) {
146 if (count($fmat->material)) {
147 foreach ($fmat->material as $material) {
148 $feedbacksgeneric[1] = $material;
149 }
150 }
151 }
152 }
153 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
154
155 if (count($ifb->material)) {
156 foreach ($ifb->material as $material) {
157 $feedbacksgeneric[0] = $material;
158 }
159 }
160 if ((count($ifb->flow_mat) > 0)) {
161 foreach ($ifb->flow_mat as $fmat) {
162 if (count($fmat->material)) {
163 foreach ($fmat->material as $material) {
164 $feedbacksgeneric[0] = $material;
165 }
166 }
167 }
168 }
169 }
170 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
171
172 if (count($ifb->material)) {
173 foreach ($ifb->material as $material) {
174 $feedbacks[$ident] = $material;
175 }
176 }
177 if ((count($ifb->flow_mat) > 0)) {
178 foreach ($ifb->flow_mat as $fmat) {
179 if (count($fmat->material)) {
180 foreach ($fmat->material as $material) {
181 $feedbacks[$ident] = $material;
182 }
183 }
184 }
185 }
186 }
187 }
188 }
189 }
190 }
191 } else {
192 $answers[$ident]["action"] = $setvar->getAction();
193 $answers[$ident]["points_unchecked"] = $setvar->getContent();
194 }
195 }
196 }
197 }
198 }
200 $this->
object->setTitle($item->
getTitle());
202 $this->
object->setComment($item->
getComment());
203 $this->
object->setAuthor($item->
getAuthor());
206 $this->object->setObjId($questionpool_id);
207 $this->object->setShuffle($shuffle);
208 $this->object->setSelectionLimit($selectionLimit);
209 $this->object->setIsSingleline(false);
210 $this->object->setThumbSize(
212 );
213
214 foreach ($answers as $answer) {
215 if ($item->
getMetadataEntry(
'singleline') || (is_array($answer[
"imagefile"]) && count($answer[
"imagefile"]) > 0)) {
216 $this->object->setIsSingleline(true);
217 }
218 $this->object->addAnswer(
219 $answer["answertext"],
220 (float) $answer["points"],
221 (float) $answer["points_unchecked"],
222 $answer["answerorder"],
223 $answer["imagefile"]["label"] ?? null
224 );
225 }
226
227 $this->object->setAdditionalContentEditingMode(
229 );
230 $this->object->saveToDb();
231 foreach ($answers as $answer) {
232 if (is_array($answer["imagefile"]) && (count($answer["imagefile"]) > 0)) {
233 $image = base64_decode($answer["imagefile"]["content"]);
234 $imagepath = $this->object->getImagePath();
235 if (!file_exists($imagepath)) {
237 }
238 $imagepath .= $answer["imagefile"]["label"];
239 $fh = fopen($imagepath, "wb");
240 if ($fh !== false) {
241 $imagefile = fwrite($fh, $image);
242 fclose($fh);
243 $this->object->generateThumbForFile(
244 $answer["imagefile"]["label"],
245 $this->
object->getImagePath(),
246 $this->object->getThumbSize()
247 );
248 }
249 }
250 }
251
253 if (!is_null($feedbackSetting)) {
254 $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->
object->getId(), $feedbackSetting);
255 }
256
257
258 foreach ($feedbacks as $ident => $material) {
260 $feedbacks[$ident] = $m;
261 }
262 foreach ($feedbacksgeneric as $correctness => $material) {
264 $feedbacksgeneric[$correctness] = $m;
265 }
266 $questiontext = $this->object->getQuestion();
267 $answers = $this->object->getAnswers();
270 $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob["uri"];
271
273 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
274
277 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
278 foreach ($answers as $key => $value) {
279 $answer_obj = &$answers[$key];
280 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
281 }
282 foreach ($feedbacks as $ident => $material) {
283 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
284 }
285 foreach ($feedbacksgeneric as $correctness => $material) {
286 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
287 }
288 }
289 }
291 foreach ($answers as $key => $value) {
292 $answer_obj = &$answers[$key];
294 }
295 foreach ($feedbacks as $ident => $material) {
296 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
298 0,
299 $ident,
301 );
302 }
303 foreach ($feedbacksgeneric as $correctness => $material) {
304 $this->object->feedbackOBJ->importGenericFeedback(
306 $correctness,
308 );
309 }
310 $this->object->saveToDb();
313 $questionpool_id,
314 $tst_id,
315 $question_counter,
316 $tst_object
317 );
318 return $import_mapping;
319 }
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)