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