41 : array {
42
44
46 $questionimage = [];
47 $answers = [];
48 foreach ($presentation->order as $entry) {
49 switch ($entry["type"]) {
50 case "response":
51 $response = $presentation->response[$entry[
"index"]];
53 switch (strtolower(get_class($rendertype))) {
54 case "ilqtirenderhotspot":
55 foreach ($rendertype->material as $mat) {
56 for ($i = 0; $i < $mat->getMaterialCount(); $i++) {
57 $m = $mat->getMaterial($i);
58 if (strcmp($m["type"], "matimage") == 0) {
59 $questionimage = [
60 "imagetype" => $m["material"]->getImageType(),
61 "label" => $m["material"]->getLabel(),
62 "content" => $m["material"]->getContent()
63 ];
64 }
65 }
66 }
67 foreach ($rendertype->response_labels as $response_label) {
68 $ident = $response_label->getIdent();
69 $answerhint = "";
70 foreach ($response_label->material as $mat) {
72 }
73 $answers[$ident] = [
74 "answerhint" => $answerhint,
75 "areatype" => $response_label->getRarea(),
76 "coordinates" => $response_label->getContent(),
77 "points" => 0,
78 "answerorder" => $response_label->getIdent(),
79 "correctness" => "1",
80 "action" => "",
81 "points_unchecked" => 0
82 ];
83 }
84 break;
85 }
86 break;
87 }
88 }
89 $responses = [];
90 $feedbacks = [];
91 $feedbacksgeneric = [];
92 foreach ($item->resprocessing as $resprocessing) {
93 foreach ($resprocessing->respcondition as $respcondition) {
94 $coordinates = "";
95 $correctness = 1;
96 $conditionvar = $respcondition->getConditionvar();
97 foreach ($conditionvar->order as $order) {
98 switch ($order["field"]) {
99 case "arr_not":
100 $correctness = 0;
101 break;
102 case "varinside":
103 $coordinates = $conditionvar->varinside[$order["index"]]->getContent();
104 break;
105 case "varequal":
106 $coordinates = $conditionvar->varequal[$order["index"]]->getContent();
107 break;
108 }
109 }
110 foreach ($respcondition->setvar as $setvar) {
111 foreach ($answers as $ident => $answer) {
112 if (strcmp($answer["coordinates"], $coordinates) == 0) {
113 if ($correctness) {
114 $answers[$ident]["action"] = $setvar->getAction();
115 $answers[$ident]["points"] = $setvar->getContent();
116 if (count($respcondition->displayfeedback)) {
117 foreach ($respcondition->displayfeedback as $feedbackpointer) {
118 if (strlen($feedbackpointer->getLinkrefid())) {
119 foreach ($item->itemfeedback as $ifb) {
120 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
121
122 if (count($ifb->material)) {
123 foreach ($ifb->material as $material) {
124 $feedbacksgeneric[1] = $material;
125 }
126 }
127 if ((count($ifb->flow_mat) > 0)) {
128 foreach ($ifb->flow_mat as $fmat) {
129 if (count($fmat->material)) {
130 foreach ($fmat->material as $material) {
131 $feedbacksgeneric[1] = $material;
132 }
133 }
134 }
135 }
136 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
137
138 if (count($ifb->material)) {
139 foreach ($ifb->material as $material) {
140 $feedbacksgeneric[0] = $material;
141 }
142 }
143 if ((count($ifb->flow_mat) > 0)) {
144 foreach ($ifb->flow_mat as $fmat) {
145 if (count($fmat->material)) {
146 foreach ($fmat->material as $material) {
147 $feedbacksgeneric[0] = $material;
148 }
149 }
150 }
151 }
152 }
153 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
154
155 if (count($ifb->material)) {
156 foreach ($ifb->material as $material) {
157 $feedbacks[$ident] = $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 $feedbacks[$ident] = $material;
165 }
166 }
167 }
168 }
169 }
170 }
171 }
172 }
173 }
174 } else {
175 $answers[$ident]["action"] = $setvar->getAction();
176 $answers[$ident]["points_unchecked"] = $setvar->getContent();
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->setIsMultipleChoice($item->
getMetadataEntry(
"IS_MULTIPLE_CHOICE"));
193 $areas = ["2" => "rect", "1" => "circle", "3" => "poly"];
194 $this->object->setImageFilename($questionimage["label"]);
195 foreach ($answers as $answer) {
196 $this->object->addAnswer($answer["answerhint"], $answer["points"], $answer["answerorder"], $answer["coordinates"], $areas[$answer["areatype"]], $answer["points_unchecked"]);
197 }
198
199 $this->object->setAdditionalContentEditingMode(
201 );
202 $this->object->saveToDb();
204 $image = base64_decode($questionimage["content"]);
205 $imagepath = $this->object->getImagePath();
206 if (!file_exists($imagepath)) {
208 }
209 $imagepath .= $questionimage["label"];
210 $fh = fopen($imagepath, "wb");
211 if ($fh == true) {
212 $imagefile = fwrite($fh, $image);
213 fclose($fh);
214 }
215
216 foreach ($feedbacks as $ident => $material) {
218 $feedbacks[$ident] = $m;
219 }
220 foreach ($feedbacksgeneric as $correctness => $material) {
222 $feedbacksgeneric[$correctness] = $m;
223 }
224 $questiontext = $this->object->getQuestion();
227 $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob["uri"];
228
230 $DIC[
'ilLog']->info(
'import mob from dir: ' . $importfile);
231
234 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
235 foreach ($feedbacks as $ident => $material) {
236 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
237 }
238 foreach ($feedbacksgeneric as $correctness => $material) {
239 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
240 }
241 }
242 }
244 foreach ($feedbacks as $ident => $material) {
245 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
247 0,
248 $ident,
250 );
251 }
252 foreach ($feedbacksgeneric as $correctness => $material) {
253 $this->object->feedbackOBJ->importGenericFeedback(
255 $correctness,
257 );
258 }
259 $this->object->saveToDb();
261 $questionpool_id,
262 $tst_id,
263 $question_counter,
264 $tst_object
265 );
266 return $import_mapping;
267 }
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)
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)