Creates a question from a QTI file.
48 : array
49 {
52
53
55
56 $presentation = $item->getPresentation();
57 $shuffle = 0;
58 $now = getdate();
59 $foundimage = false;
60 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
61 $answers = [];
63
64 foreach ($presentation->order as $entry) {
65 switch ($entry["type"]) {
66 case "response":
67 $response = $presentation->response[$entry[
"index"]];
71 } elseif (
$response->getIdent() ==
'OQNP') {
73 } elseif (
$response->getIdent() ==
'OQNT') {
75 } elseif (
$response->getIdent() ==
'OQT') {
77 }
78
80 switch (strtolower(get_class($rendertype))) {
81 case "ilqtirenderchoice":
82 $shuffle = $rendertype->getShuffle();
83 $answerorder = 0;
84 foreach ($rendertype->response_labels as $response_label) {
85 $ident = $response_label->getIdent();
86 $answertext = "";
87 $answerimage = [];
88 $answerdepth = 0;
89 foreach ($response_label->material as $mat) {
90 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
91 $foundmat = $mat->getMaterial($m);
92
93 if (strcmp($foundmat["material"]->getLabel(), "answerdepth") == 0) {
94 $answerdepth = $foundmat["material"]->getContent();
95 }
96 if (strcmp($foundmat["type"], "mattext") == 0
97 && strcmp($foundmat["material"]->getLabel(), "answerdepth") != 0) {
98 $answertext .= $foundmat["material"]->getContent();
99 }
100 if (strcmp($foundmat["type"], "matimage") == 0
101 && strcmp($foundmat["material"]->getLabel(), "answerdepth") != 0) {
102 $foundimage = true;
103 $answerimage = array(
104 "imagetype" => $foundmat["material"]->getImageType(),
105 "label" => $foundmat["material"]->getLabel(),
106 "content" => $foundmat[
"material"]->
getContent()
107 );
108 }
109 }
110 }
111 $answers[$answerorder] = array(
112 'ident' => $ident,
113 "answertext" => $answertext,
114 "answerimage" => $answerimage,
115 "points" => 0,
116 "answerorder" => $answerorder,
117 "answerdepth" => $answerdepth,
118 "correctness" => "",
119 "action" => ""
120 );
121 $answerorder++;
122 }
123 break;
124 }
125 break;
126 }
127 }
128
129 $feedbacksgeneric = array();
130 foreach ($item->resprocessing as $resprocessing) {
131 foreach ($resprocessing->respcondition as $respcondition) {
132 $ident = "";
133 $correctness = 1;
134 $conditionvar = $respcondition->getConditionvar();
135 foreach ($conditionvar->order as $order) {
136 switch ($order["field"]) {
137 case "arr_not":
138 $correctness = 0;
139 break;
140 case "varequal":
141 $ident = $conditionvar->varequal[$order["index"]]->getContent();
142 $orderindex = $conditionvar->varequal[$order["index"]]->getIndex();
143 break;
144 }
145 }
146 foreach ($respcondition->setvar as $setvar) {
147 if (strcmp($ident, "") != 0) {
148 $answers[$ident]["solutionorder"] = $orderindex;
149 $answers[$ident]["action"] = $setvar->getAction();
150 $answers[$ident]["points"] = $setvar->getContent();
151 }
152 }
153 if (count($respcondition->displayfeedback)) {
154 foreach ($respcondition->displayfeedback as $feedbackpointer) {
155 if (strlen($feedbackpointer->getLinkrefid())) {
156 foreach ($item->itemfeedback as $ifb) {
157 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
158
159 if (count($ifb->material)) {
160 foreach ($ifb->material as $material) {
161 $feedbacksgeneric[1] = $material;
162 }
163 }
164 if ((count($ifb->flow_mat) > 0)) {
165 foreach ($ifb->flow_mat as $fmat) {
166 if (count($fmat->material)) {
167 foreach ($fmat->material as $material) {
168 $feedbacksgeneric[1] = $material;
169 }
170 }
171 }
172 }
173 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
174
175 if (count($ifb->material)) {
176 foreach ($ifb->material as $material) {
177 $feedbacksgeneric[0] = $material;
178 }
179 }
180 if ((count($ifb->flow_mat) > 0)) {
181 foreach ($ifb->flow_mat as $fmat) {
182 if (count($fmat->material)) {
183 foreach ($fmat->material as $material) {
184 $feedbacksgeneric[0] = $material;
185 }
186 }
187 }
188 }
189 }
190 }
191 }
192 }
193 }
194 }
195 }
196
198
200 $this->object->setTitle($item->getTitle());
201 $this->object->setNrOfTries((int) $item->getMaxattempts());
202 $this->object->setComment($item->getComment());
203 $this->object->setAuthor($item->getAuthor());
204 $this->
object->setOwner(
$ilUser->getId());
205 $this->
object->setQuestion($this->
object->QTIMaterialToString($item->getQuestiontext()));
206 $this->
object->setOrderingType(
$type);
207 $this->object->setObjId($questionpool_id);
208 $this->object->setThumbSize(
210 );
211 $this->object->setElementHeight($item->getMetadataEntry('element_height')
212 ? (int) $item->getMetadataEntry('element_height')
213 : null);
214 $this->object->setShuffle($shuffle);
215 $this->object->setPoints(0);
216 $this->object->saveQuestionDataToDb();
217 $points = 0;
218 $solanswers = array();
219
220 foreach ($answers as $answer) {
221 $solanswers[$answer["solutionorder"] ?? null] = $answer;
222 }
223 ksort($solanswers);
224 $position = 0;
225 $element_list = $this->object->getOrderingElementList();
226 foreach ($solanswers as $answer) {
227 $points += $answer["points"];
228
230
231 if ($element->isExportIdent($answer['ident'])) {
232 $element->setExportIdent($answer['ident']);
233 } else {
234 $element = $element->withPosition($position++);
235 if (isset($answer['answerdepth'])) {
236 $element = $element->withIndentation((int) $answer['answerdepth']);
237 }
238 }
239
240 if ($this->
object->isImageOrderingType()) {
241 $filename = $this->handleUploadedfile($answer);
243 $element = $element->withContent(
$filename);
244 }
245 } else {
246 $element = $element->withContent($answer["answertext"]);
247 }
248
249 $element_list->addElement($element);
250 }
251 $this->object->setOrderingElementList($element_list);
252 $points = ($item->getMetadataEntry("points") > 0) ? $item->getMetadataEntry("points") : $points;
253 $this->object->setPoints($points);
254
255 $this->object->setAdditionalContentEditingMode(
257 );
258 $this->object->saveToDb();
259 if (count($item->suggested_solutions)) {
260 foreach ($item->suggested_solutions as $suggested_solution) {
261 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->
getContent(), $suggested_solution[
"gap_index"],
true);
262 }
263 $this->object->saveToDb();
264 }
265
266 foreach ($feedbacksgeneric as $correctness => $material) {
267 $m = $this->object->QTIMaterialToString($material);
268 $feedbacksgeneric[$correctness] = $m;
269 }
270 $questiontext = $this->object->getQuestion();
271
272
275 if ($tst_id > 0) {
277 } else {
279 }
280
282 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
283
286 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
287 foreach ($this->
object->getOrderingElementList() as $element) {
288 $element->setContent(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $element->getContent()));
289 }
290 foreach ($feedbacksgeneric as $correctness => $material) {
291 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
292 }
293 foreach ($itemfeedbacks as $ident => $material) {
294 $itemfeedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
295 }
296 }
297 }
299 foreach ($this->
object->getOrderingElementList() as $element) {
301 }
302 foreach ($feedbacksgeneric as $correctness => $material) {
303 $this->object->feedbackOBJ->importGenericFeedback(
305 $correctness,
307 );
308 }
309 foreach ($itemfeedbacks as $ident => $material) {
311
312 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
314 0,
317 );
318 }
319 $this->object->saveToDb();
320 if (isset($tst_id) && $tst_id !== $questionpool_id) {
321 $qplQid = $this->object->getId();
322 $tstQid = $this->object->duplicate(true, '', '', '', $tst_id);
323 $tst_object->questions[$question_counter++] = $tstQid;
324 $import_mapping[$item->getIdent()] = ["pool" => $qplQid, "test" => $tstQid];
325 return $import_mapping;
326 }
327
328 if ($tst_id > 0) {
329 $tst_object->questions[$question_counter++] = $this->object->getId();
330 $import_mapping[$item->getIdent()] = ["pool" => 0, "test" => $this->object->getId()];
331 return $import_mapping;
332 }
333
334 $import_mapping[$item->getIdent()] = ["pool" => $this->object->getId(), "test" => 0];
335 return $import_mapping;
336 }
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)
deduceThumbSizeFromImportValue(?int $size)
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')
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 OQ_PICTURES
Ordering question constants.