Creates a question from a QTI file.
31 {
33
34
36 $presentation = $item->getPresentation();
37 $duration = $item->getDuration();
38 $shuffle = 0;
39 $now = getdate();
40 $foundimage = FALSE;
41 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
42 $answers = array();
44
45 foreach ($presentation->order as $entry)
46 {
47 switch ($entry["type"])
48 {
49 case "response":
50 $response = $presentation->response[$entry["index"]];
51 $type = $response->getIdent();
52 if($response->getIdent() == 'OQP' )
54 else if($response->getIdent() == 'OQNP')
56 else if($response->getIdent() == 'OQNT')
58 else if($response->getIdent() == 'OQT')
60
61 $rendertype = $response->getRenderType();
62 switch (strtolower(get_class($rendertype)))
63 {
64 case "ilqtirenderchoice":
65 $shuffle = $rendertype->getShuffle();
66 $answerorder = 0;
67 foreach ($rendertype->response_labels as $response_label)
68 {
69 $ident = $response_label->getIdent();
70 $answertext = "";
71 foreach ($response_label->material as $mat)
72 {
73 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
74 {
75 $foundmat = $mat->getMaterial($m);
76
77 if (strcmp($foundmat["material"]->getLabel(), "answerdepth") == 0)
78 {
79 $answerdepth = $foundmat["material"]->getContent();
80 }
81 if (strcmp($foundmat["type"], "mattext") == 0
82 && strcmp($foundmat["material"]->getLabel(), "answerdepth") != 0)
83 {
84 $answertext .= $foundmat["material"]->getContent();
85 }
86 if (strcmp($foundmat["type"], "matimage") == 0
87 && strcmp($foundmat["material"]->getLabel(), "answerdepth") != 0)
88 {
89 $foundimage = TRUE;
90 $answerimage = array(
91 "imagetype" => $foundmat["material"]->getImageType(),
92 "label" => $foundmat["material"]->getLabel(),
93 "content" => $foundmat["material"]->getContent()
94 );
95 }
96 }
97 }
98 $answers[$ident] = array(
99 "answertext" => $answertext,
100 "answerimage" => $answerimage,
101 "points" => 0,
102 "answerorder" => $answerorder++,
103 "answerdepth" => $answerdepth,
104 "correctness" => "",
105 "action" => ""
106 );
107 }
108 break;
109 }
110 break;
111 }
112 }
113 $responses = array();
114 $feedbacksgeneric = array();
115 foreach ($item->resprocessing as $resprocessing)
116 {
117 foreach ($resprocessing->respcondition as $respcondition)
118 {
119 $ident = "";
120 $correctness = 1;
121 $conditionvar = $respcondition->getConditionvar();
122 foreach ($conditionvar->order as $order)
123 {
124 switch ($order["field"])
125 {
126 case "arr_not":
127 $correctness = 0;
128 break;
129 case "varequal":
130 $ident = $conditionvar->varequal[$order["index"]]->getContent();
131 $orderindex = $conditionvar->varequal[$order["index"]]->getIndex();
132 break;
133 }
134 }
135 foreach ($respcondition->setvar as $setvar)
136 {
137 if (strcmp($ident, "") != 0)
138 {
139 $answers[$ident]["solutionorder"] = $orderindex;
140 $answers[$ident]["action"] = $setvar->getAction();
141 $answers[$ident]["points"] = $setvar->getContent();
142 }
143 }
144 if (count($respcondition->displayfeedback))
145 {
146 foreach ($respcondition->displayfeedback as $feedbackpointer)
147 {
148 if (strlen($feedbackpointer->getLinkrefid()))
149 {
150 foreach ($item->itemfeedback as $ifb)
151 {
152 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0)
153 {
154
155 if (count($ifb->material))
156 {
157 foreach ($ifb->material as $material)
158 {
159 $feedbacksgeneric[1] = $material;
160 }
161 }
162 if ((count($ifb->flow_mat) > 0))
163 {
164 foreach ($ifb->flow_mat as $fmat)
165 {
166 if (count($fmat->material))
167 {
168 foreach ($fmat->material as $material)
169 {
170 $feedbacksgeneric[1] = $material;
171 }
172 }
173 }
174 }
175 }
176 else if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0)
177 {
178
179 if (count($ifb->material))
180 {
181 foreach ($ifb->material as $material)
182 {
183 $feedbacksgeneric[0] = $material;
184 }
185 }
186 if ((count($ifb->flow_mat) > 0))
187 {
188 foreach ($ifb->flow_mat as $fmat)
189 {
190 if (count($fmat->material))
191 {
192 foreach ($fmat->material as $material)
193 {
194 $feedbacksgeneric[0] = $material;
195 }
196 }
197 }
198 }
199 }
200 }
201 }
202 }
203 }
204 }
205 }
206
208 $this->object->setTitle($item->getTitle());
209 $this->object->setNrOfTries($item->getMaxattempts());
210 $this->object->setComment($item->getComment());
211 $this->object->setAuthor($item->getAuthor());
212 $this->object->setOwner($ilUser->getId());
213 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
214 $this->object->setOrderingType($type);
215 $this->object->setObjId($questionpool_id);
216 $this->object->setThumbGeometry($item->getMetadataEntry("thumb_geometry"));
217 $this->object->setElementHeight($item->getMetadataEntry("element_height"));
218 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
219 $this->object->setShuffle($shuffle);
220 $points = 0;
221 $solanswers = array();
222
223 foreach ($answers as $answer)
224 {
225 $solanswers[$answer["solutionorder"]] = $answer;
226 }
227 ksort($solanswers);
228 foreach ($solanswers as $answer)
229 {
230 $points += $answer["points"];
232 {
233 $this->object->addAnswer($answer["answertext"], -1, $answer['answerdepth']);
234 }
236 {
237 $this->object->addAnswer($answer["answerimage"]["label"], -1, $answer['answerdepth']);
238 }
239 }
240 $points = ($item->getMetadataEntry("points") > 0) ? $item->getMetadataEntry("points") : $points;
241 $this->object->setPoints($points);
242
243 $this->object->setAdditionalContentEditingMode(
245 );
246 $this->object->saveToDb();
247 if (count($item->suggested_solutions))
248 {
249 foreach ($item->suggested_solutions as $suggested_solution)
250 {
251 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
252 }
253 $this->object->saveToDb();
254 }
255 foreach ($answers as $answer)
256 {
258 {
259 include_once "./Services/Utilities/classes/class.ilUtil.php";
260 if( strlen($answer['answerimage']['label']) && strlen($answer['answerimage']['content']) )
261 {
262 $image =& base64_decode($answer["answerimage"]["content"]);
263 $imagepath = $this->object->getImagePath();
264 if (!file_exists($imagepath))
265 {
267 }
268 $imagepath .= $answer["answerimage"]["label"];
269 $fh = fopen($imagepath, "wb");
270 if ($fh == false)
271 {
272
273
274
275 }
276 else
277 {
278 $imagefile = fwrite($fh, $image);
279 fclose($fh);
280 }
281
282 $thumbpath = $imagepath . "." . "thumb.jpg";
284 }
285 }
286 }
287 foreach ($feedbacksgeneric as $correctness => $material)
288 {
289 $m = $this->object->QTIMaterialToString($material);
290 $feedbacksgeneric[$correctness] = $m;
291 }
292 $questiontext = $this->object->getQuestion();
293 $answers =& $this->object->getAnswers();
294
295 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
296 {
297 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
298 include_once "./Services/RTE/classes/class.ilRTE.php";
299 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
300 {
301 if ($tst_id > 0)
302 {
304 }
305 else
306 {
308 }
309
310 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
311
314 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
315 foreach ($answers as $key => $value)
316 {
317 $answer_obj =& $answers[$key];
318 $answer_obj->setAnswertext(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $answer_obj->getAnswertext()));
319 }
320 foreach ($feedbacksgeneric as $correctness => $material)
321 {
322 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
323 }
324 }
325 }
327 foreach ($answers as $key => $value)
328 {
329 $answer_obj =& $answers[$key];
331 }
332 foreach ($feedbacksgeneric as $correctness => $material)
333 {
334 $this->object->feedbackOBJ->importGenericFeedback(
336 );
337 }
338 $this->object->saveToDb();
339 if ($tst_id > 0)
340 {
341 $q_1_id = $this->object->getId();
342 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
343 $tst_object->questions[$question_counter++] = $question_id;
344 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
345 }
346 else
347 {
348 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
349 }
350 }
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)
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...
static convertImage($a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
const OQ_PICTURES
Ordering question constants.