Creates a question from a QTI file.
31 {
34
35
37 $presentation = $item->getPresentation();
38 $duration = $item->getDuration();
39
40 $packageIliasVersion = $item->getIliasSourceVersion('ILIAS_VERSION');
41 $seperate_question_field = $item->getMetadataEntry("question");
42
43 $questiontext = null;
44 if (!$packageIliasVersion || version_compare($packageIliasVersion, '5.0.0', '<')) {
45 $questiontext = ' ';
46 } elseif ($seperate_question_field) {
48 $seperate_question_field,
49 $item->getIliasSourceNic()
50 );
51 }
52
53 $clozetext = array();
54 $shuffle = 0;
55 $now = getdate();
56 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
57 $gaps = array();
58 foreach ($presentation->order as $entry) {
59 switch ($entry["type"]) {
60 case "material":
61
62 $materialString = $this->object->QTIMaterialToString(
63 $presentation->material[$entry["index"]]
64 );
65
66 if ($questiontext === ' ') {
67 $questiontext = $materialString;
68 } else {
69 array_push($clozetext, $materialString);
70 }
71
72 break;
73 case "response":
74 $response = $presentation->response[$entry[
"index"]];
76 array_push($clozetext,
"<<" .
$response->getIdent() .
">>");
77
78 switch (strtolower(get_class(
$response->getRenderType()))) {
79 case "ilqtirenderfib":
80 switch (
$response->getRenderType()->getFibtype()) {
83 array_push(
84 $gaps,
85 array(
88 "answers" => array(),
89 "minnumber" =>
$response->getRenderType()->getMinnumber(),
90 "maxnumber" =>
$response->getRenderType()->getMaxnumber(),
91 'gap_size' =>
$response->getRenderType()->getMaxchars()
92 )
93 );
94 break;
95 default:
97 array_push(
98 $gaps,
101 "answers" => array(),
102 'gap_size' =>
$response->getRenderType()->getMaxchars()
103 )
104 );
105 break;
106 }
107 break;
108 case "ilqtirenderchoice":
109 $answers = array();
110 $shuffle = $rendertype->getShuffle();
111 $answerorder = 0;
112 foreach ($rendertype->response_labels as $response_label) {
113 $ident = $response_label->getIdent();
114 $answertext = "";
115 foreach ($response_label->material as $mat) {
116 $answertext .= $this->object->QTIMaterialToString($mat);
117 }
118 $answers[$ident] = array(
119 "answertext" => $answertext,
120 "points" => 0,
121 "answerorder" => $answerorder++,
122 "action" => "",
123 "shuffle" => $rendertype->getShuffle()
124 );
125 }
126 array_push($gaps, array(
"ident" =>
$response->getIdent(),
"type" =>
CLOZE_SELECT,
"shuffle" => $rendertype->getShuffle(),
"answers" => $answers));
127 break;
128 }
129 break;
130 }
131 }
132 $responses = array();
133 $feedbacks = array();
134 $feedbacksgeneric = array();
135 foreach ($item->resprocessing as $resprocessing) {
136 foreach ($resprocessing->respcondition as $respcondition) {
137 $ident = "";
138 $correctness = 1;
139 $conditionvar = $respcondition->getConditionvar();
140 foreach ($conditionvar->order as $order) {
141 switch ($order["field"]) {
142 case "varequal":
143 $equals = $conditionvar->varequal[$order["index"]]->getContent();
144 $gapident = $conditionvar->varequal[$order["index"]]->getRespident();
145 break;
146 }
147 }
148 foreach ($respcondition->setvar as $setvar) {
149 if (strcmp($gapident, "") != 0) {
150 foreach ($gaps as $gi => $g) {
151 if (strcmp($g["ident"], $gapident) == 0) {
153 foreach ($gaps[$gi]["answers"] as $ai => $answer) {
154 if (strcmp($answer["answertext"], $equals) == 0) {
155 $gaps[$gi]["answers"][$ai]["action"] = $setvar->getAction();
156 $gaps[$gi]["answers"][$ai]["points"] = $setvar->getContent();
157 }
158 }
160 array_push($gaps[$gi]["answers"], array(
161 "answertext" => $equals,
162 "points" => $setvar->getContent(),
163 "answerorder" => count($gaps[$gi]["answers"]),
164 "action" => $setvar->getAction()
165
166 ));
168 array_push($gaps[$gi]["answers"], array(
169 "answertext" => $equals,
170 "points" => $setvar->getContent(),
171 "answerorder" => count($gaps[$gi]["answers"]),
172 "action" => $setvar->getAction()
173 ));
174 }
175 }
176 }
177 }
178 }
179
180 if (count($respcondition->displayfeedback)) {
181 foreach ($respcondition->displayfeedback as $feedbackpointer) {
182 if (strlen($feedbackpointer->getLinkrefid())) {
183 foreach ($item->itemfeedback as $ifb) {
184 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
185
186 if (count($ifb->material)) {
187 foreach ($ifb->material as $material) {
188 $feedbacksgeneric[1] = $material;
189 }
190 }
191 if ((count($ifb->flow_mat) > 0)) {
192 foreach ($ifb->flow_mat as $fmat) {
193 if (count($fmat->material)) {
194 foreach ($fmat->material as $material) {
195 $feedbacksgeneric[1] = $material;
196 }
197 }
198 }
199 }
200 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
201
202 if (count($ifb->material)) {
203 foreach ($ifb->material as $material) {
204 $feedbacksgeneric[0] = $material;
205 }
206 }
207 if ((count($ifb->flow_mat) > 0)) {
208 foreach ($ifb->flow_mat as $fmat) {
209 if (count($fmat->material)) {
210 foreach ($fmat->material as $material) {
211 $feedbacksgeneric[0] = $material;
212 }
213 }
214 }
215 }
216 } else {
217
218 if (count($ifb->material)) {
219 foreach ($ifb->material as $material) {
220 $feedbacks[$ifb->getIdent()] = $material;
221 }
222 }
223 if ((count($ifb->flow_mat) > 0)) {
224 foreach ($ifb->flow_mat as $fmat) {
225 if (count($fmat->material)) {
226 foreach ($fmat->material as $material) {
227 $feedbacks[$ifb->getIdent()] = $material;
228 }
229 }
230 }
231 }
232 }
233 }
234 }
235 }
236 }
237 }
238 }
239
241 $this->object->setTitle($item->getTitle());
242 $this->object->setNrOfTries($item->getMaxattempts());
243 $this->object->setComment($item->getComment());
244 $this->object->setAuthor($item->getAuthor());
245 $this->
object->setOwner(
$ilUser->getId());
246 $this->object->setObjId($questionpool_id);
247 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
248 $textgap_rating = $item->getMetadataEntry("textgaprating");
249 $this->object->setFixedTextLength($item->getMetadataEntry("fixedTextLength"));
250 $this->object->setIdenticalScoring($item->getMetadataEntry("identicalScoring"));
251 $this->object->setFeedbackMode(
252 strlen($item->getMetadataEntry("feedback_mode")) ?
254 );
255 $combination = json_decode(base64_decode($item->getMetadataEntry("combinations")));
256 if (strlen($textgap_rating) == 0) {
257 $textgap_rating = "ci";
258 }
259 $this->object->setTextgapRating($textgap_rating);
260 $gaptext = array();
261 foreach ($gaps as $gapidx => $gap) {
262 $gapcontent = array();
263 include_once "./Modules/TestQuestionPool/classes/class.assClozeGap.php";
265 foreach ($gap[
"answers"] as
$index => $answer) {
266 include_once "./Modules/TestQuestionPool/classes/class.assAnswerCloze.php";
267 $gapanswer =
new assAnswerCloze($answer[
"answertext"], $answer[
"points"], $answer[
"answerorder"]);
268 $gapanswer->setGapSize($gap["gap_size"]);
269 switch ($clozegap->getType()) {
271 $clozegap->setShuffle($answer["shuffle"]);
272 break;
274 $gapanswer->setLowerBound($gap["minnumber"]);
275 $gapanswer->setUpperBound($gap["maxnumber"]);
276 break;
277 }
278 $clozegap->setGapSize($gap["gap_size"]);
279 $clozegap->addItem($gapanswer);
280 array_push($gapcontent, $answer["answertext"]);
281 }
282 $this->object->addGapAtIndex($clozegap, $gapidx);
283 $gaptext[$gap["ident"]] = "[gap]" . join(",", $gapcontent) . "[/gap]";
284 }
285
286 $this->object->setQuestion($questiontext);
287 $clozetext = join("", $clozetext);
288
289 foreach ($gaptext as $idx => $val) {
290 $clozetext = str_replace("<<" . $idx . ">>", $val, $clozetext);
291 }
292 $this->object->setClozeTextValue($clozetext);
293
294
295 $this->object->setAdditionalContentEditingMode(
297 );
298 $this->object->saveToDb();
299
300
301 foreach ($feedbacks as $ident => $material) {
302 $m = $this->object->QTIMaterialToString($material);
303 $feedbacks[$ident] = $m;
304 }
305 foreach ($feedbacksgeneric as $correctness => $material) {
306 $m = $this->object->QTIMaterialToString($material);
307 $feedbacksgeneric[$correctness] = $m;
308 }
309 $questiontext = $this->object->getQuestion();
310 $clozetext = $this->object->getClozeText();
311 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
312 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
313 include_once "./Services/RTE/classes/class.ilRTE.php";
314 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
315 if ($tst_id > 0) {
317 } else {
319 }
321 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
322
324 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
325 $clozetext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $clozetext);
326 foreach ($feedbacks as $ident => $material) {
327 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
328 }
329 foreach ($feedbacksgeneric as $correctness => $material) {
330 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
331 }
332 }
333 }
336 foreach ($feedbacks as $ident => $material) {
338 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
339 $this->object->getId(),
340 $fbIdentifier->getQuestionIndex(),
341 $fbIdentifier->getAnswerIndex(),
343 );
344 }
345 foreach ($feedbacksgeneric as $correctness => $material) {
346 $this->object->feedbackOBJ->importGenericFeedback(
347 $this->object->getId(),
348 $correctness,
350 );
351 }
352 $this->object->saveToDb();
353 if (count($item->suggested_solutions)) {
354 foreach ($item->suggested_solutions as $suggested_solution) {
355 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
356 }
357 $this->object->saveToDb();
358 }
359 if ($tst_id > 0) {
360 $q_1_id = $this->object->getId();
361 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
362 $tst_object->questions[$question_counter++] = $question_id;
363 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
364 } else {
365 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
366 }
367 $this->object->saveToDb();
368 if (is_array($combination) && count($combination) > 0) {
369 require_once './Modules/TestQuestionPool/classes/class.assClozeGapCombination.php';
372 }
373 $this->object->saveToDb();
374 }
Class for cloze question numeric answers.
static clearGapCombinationsFromDb($question_id)
static importGapCombinationToDb($question_id, $gap_combinations)
Class for cloze question gaps.
buildFeedbackIdentifier($ident)
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir)
processNonAbstractedImageReferences($text, $sourceNic)
addGeneralMetadata(ilQTIItem $item)
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir)
const FB_MODE_GAP_QUESTION
constants for different feedback modes (per gap or per gap-answers/options)
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
const CLOZE_TEXT
Cloze question constants.