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