ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
assMultipleChoiceImport Class Reference

Class for multiple choice question imports. More...

+ Inheritance diagram for assMultipleChoiceImport:
+ Collaboration diagram for assMultipleChoiceImport:

Public Member Functions

 fromXML (&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 Creates a question from a QTI file. More...
 
- Public Member Functions inherited from assQuestionImport
 assQuestionImport (&$a_object)
 assQuestionImport constructor More...
 
 getFeedbackGeneric ($item)
 
 fromXML (&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 Creates a question from a QTI file. More...
 

Additional Inherited Members

- Data Fields inherited from assQuestionImport
 $object
 
- Protected Member Functions inherited from assQuestionImport
 getFeedbackAnswerSpecific (ilQTIItem $item)
 
 addGeneralMetadata (ilQTIItem $item)
 
 getQplImportArchivDirectory ()
 returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir) More...
 
 getTstImportArchivDirectory ()
 returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) More...
 
 processNonAbstractedImageReferences ($text, $sourceNic)
 
 fetchAdditionalContentEditingModeInformation ($qtiItem)
 fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_CONTENT_EDITING_MODE_DEFAULT when no or invalid information is given More...
 

Detailed Description

Class for multiple choice question imports.

assMultipleChoiceImport is a class for multiple choice question imports

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
$Id$

Definition at line 15 of file class.assMultipleChoiceImport.php.

Member Function Documentation

◆ fromXML()

assMultipleChoiceImport::fromXML ( $item,
$questionpool_id,
$tst_id,
$tst_object,
$question_counter,
$import_mapping 
)

Creates a question from a QTI file.

Receives parameters from a QTI parser and creates a valid ILIAS question object

Parameters
object$itemThe QTI item object
integer$questionpool_idThe id of the parent questionpool
integer$tst_idThe id of the parent test if the question is part of a test
object$tst_objectA reference to the parent test object
integer$question_counterA reference to a question counter to count the questions of an imported question pool
array$import_mappingAn array containing references to included ILIAS objects @access public

Definition at line 30 of file class.assMultipleChoiceImport.php.

31 {
32 global $ilUser;
33 // empty session variable for imported xhtml mobs
34 unset($_SESSION["import_mob_xhtml"]);
35 $presentation = $item->getPresentation();
36 $duration = $item->getDuration();
37 $shuffle = 0;
38 $now = getdate();
39 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
40 $answers = array();
41 foreach ($presentation->order as $entry)
42 {
43 switch ($entry["type"])
44 {
45 case "response":
46 $response = $presentation->response[$entry["index"]];
47 $rendertype = $response->getRenderType();
48 switch (strtolower(get_class($response->getRenderType())))
49 {
50 case "ilqtirenderchoice":
51 $shuffle = $rendertype->getShuffle();
52 $answerorder = 0;
53 $foundimage = FALSE;
54 foreach ($rendertype->response_labels as $response_label)
55 {
56 $ident = $response_label->getIdent();
57 $answertext = "";
58 $answerimage = array();
59 foreach ($response_label->material as $mat)
60 {
61 $embedded = false;
62 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
63 {
64 $foundmat = $mat->getMaterial($m);
65 if (strcmp($foundmat["type"], "mattext") == 0)
66 {
67 }
68 if (strcmp($foundmat["type"], "matimage") == 0)
69 {
70 if (strlen($foundmat["material"]->getEmbedded()))
71 {
72 $embedded = true;
73 }
74 }
75 }
76 if ($embedded)
77 {
78 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
79 {
80 $foundmat = $mat->getMaterial($m);
81 if (strcmp($foundmat["type"], "mattext") == 0)
82 {
83 $answertext .= $foundmat["material"]->getContent();
84 }
85 if (strcmp($foundmat["type"], "matimage") == 0)
86 {
87 $foundimage = TRUE;
88 $answerimage = array(
89 "imagetype" => $foundmat["material"]->getImageType(),
90 "label" => $foundmat["material"]->getLabel(),
91 "content" => $foundmat["material"]->getContent()
92 );
93 }
94 }
95 }
96 else
97 {
98 $answertext = $this->object->QTIMaterialToString($mat);
99 }
100 }
101 $answers[$ident] = array(
102 "answertext" => $answertext,
103 "imagefile" => $answerimage,
104 "points" => 0,
105 "answerorder" => $answerorder++,
106 "points_unchecked" => 0,
107 "action" => ""
108 );
109 }
110 break;
111 }
112 break;
113 }
114 }
115 $responses = array();
116 $feedbacks = array();
117 $feedbacksgeneric = array();
118 foreach ($item->resprocessing as $resprocessing)
119 {
120 foreach ($resprocessing->respcondition as $respcondition)
121 {
122 $ident = "";
123 $correctness = 1;
124 $conditionvar = $respcondition->getConditionvar();
125 foreach ($conditionvar->order as $order)
126 {
127 switch ($order["field"])
128 {
129 case "arr_not":
130 $correctness = 0;
131 break;
132 case "varequal":
133 $ident = $conditionvar->varequal[$order["index"]]->getContent();
134 break;
135 }
136 }
137 foreach ($respcondition->setvar as $setvar)
138 {
139 if (strcmp($ident, "") != 0)
140 {
141 if ($correctness)
142 {
143 $answers[$ident]["action"] = $setvar->getAction();
144 $answers[$ident]["points"] = $setvar->getContent();
145 if (count($respcondition->displayfeedback))
146 {
147 foreach ($respcondition->displayfeedback as $feedbackpointer)
148 {
149 if (strlen($feedbackpointer->getLinkrefid()))
150 {
151 foreach ($item->itemfeedback as $ifb)
152 {
153 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0)
154 {
155 // found a feedback for the identifier
156 if (count($ifb->material))
157 {
158 foreach ($ifb->material as $material)
159 {
160 $feedbacksgeneric[1] = $material;
161 }
162 }
163 if ((count($ifb->flow_mat) > 0))
164 {
165 foreach ($ifb->flow_mat as $fmat)
166 {
167 if (count($fmat->material))
168 {
169 foreach ($fmat->material as $material)
170 {
171 $feedbacksgeneric[1] = $material;
172 }
173 }
174 }
175 }
176 }
177 else if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0)
178 {
179 // found a feedback for the identifier
180 if (count($ifb->material))
181 {
182 foreach ($ifb->material as $material)
183 {
184 $feedbacksgeneric[0] = $material;
185 }
186 }
187 if ((count($ifb->flow_mat) > 0))
188 {
189 foreach ($ifb->flow_mat as $fmat)
190 {
191 if (count($fmat->material))
192 {
193 foreach ($fmat->material as $material)
194 {
195 $feedbacksgeneric[0] = $material;
196 }
197 }
198 }
199 }
200 }
201 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0)
202 {
203 // found a feedback for the identifier
204 if (count($ifb->material))
205 {
206 foreach ($ifb->material as $material)
207 {
208 $feedbacks[$ident] = $material;
209 }
210 }
211 if ((count($ifb->flow_mat) > 0))
212 {
213 foreach ($ifb->flow_mat as $fmat)
214 {
215 if (count($fmat->material))
216 {
217 foreach ($fmat->material as $material)
218 {
219 $feedbacks[$ident] = $material;
220 }
221 }
222 }
223 }
224 }
225 }
226 }
227 }
228 }
229 }
230 else
231 {
232 $answers[$ident]["action"] = $setvar->getAction();
233 $answers[$ident]["points_unchecked"] = $setvar->getContent();
234 }
235 }
236 }
237 }
238 }
239 $this->addGeneralMetadata($item);
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->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
246 $this->object->setObjId($questionpool_id);
247 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
248 $this->object->setShuffle($shuffle);
249 $this->object->setThumbSize($item->getMetadataEntry("thumb_size"));
250
251 foreach ($answers as $answer)
252 {
253 if (is_array($answer["imagefile"]) && (count($answer["imagefile"]) > 0))
254 {
255 $this->object->isSingleline = true;
256 }
257 $this->object->addAnswer($answer["answertext"], $answer["points"], $answer["points_unchecked"], $answer["answerorder"], $answer["imagefile"]["label"]);
258 }
259 // additional content editing mode information
260 $this->object->setAdditionalContentEditingMode(
262 );
263 $this->object->saveToDb();
264 foreach ($answers as $answer)
265 {
266 if (is_array($answer["imagefile"]) && (count($answer["imagefile"]) > 0))
267 {
268 $image =& base64_decode($answer["imagefile"]["content"]);
269 $imagepath = $this->object->getImagePath();
270 include_once "./Services/Utilities/classes/class.ilUtil.php";
271 if (!file_exists($imagepath))
272 {
273 ilUtil::makeDirParents($imagepath);
274 }
275 $imagepath .= $answer["imagefile"]["label"];
276 $fh = fopen($imagepath, "wb");
277 if ($fh == false)
278 {
279 }
280 else
281 {
282 $imagefile = fwrite($fh, $image);
283 fclose($fh);
284 }
285 }
286 }
287
288 $feedbackSetting = $item->getMetadataEntry('feedback_setting');
289 if( !is_null($feedbackSetting) )
290 {
291 $this->object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting);
292 }
293
294 // handle the import of media objects in XHTML code
295 foreach ($feedbacks as $ident => $material)
296 {
297 $m = $this->object->QTIMaterialToString($material);
298 $feedbacks[$ident] = $m;
299 }
300 foreach ($feedbacksgeneric as $correctness => $material)
301 {
302 $m = $this->object->QTIMaterialToString($material);
303 $feedbacksgeneric[$correctness] = $m;
304 }
305 $questiontext = $this->object->getQuestion();
306 $answers =& $this->object->getAnswers();
307 if (is_array($_SESSION["import_mob_xhtml"]))
308 {
309 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
310 include_once "./Services/RTE/classes/class.ilRTE.php";
311 foreach ($_SESSION["import_mob_xhtml"] as $mob)
312 {
313 if ($tst_id > 0)
314 {
315 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
316 }
317 else
318 {
319 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
320 }
321
322 $GLOBALS['ilLog']->write(__METHOD__.': import mob from dir: '. $importfile);
323
324 $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
325 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
326 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
327 foreach ($answers as $key => $value)
328 {
329 $answer_obj =& $answers[$key];
330 $answer_obj->setAnswertext(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $answer_obj->getAnswertext()));
331 }
332 foreach ($feedbacks as $ident => $material)
333 {
334 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
335 }
336 foreach ($feedbacksgeneric as $correctness => $material)
337 {
338 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
339 }
340 }
341 }
342 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
343 foreach ($answers as $key => $value)
344 {
345 $answer_obj =& $answers[$key];
346 $answer_obj->setAnswertext(ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 1));
347 }
348 foreach ($feedbacks as $ident => $material)
349 {
350 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
351 $this->object->getId(), $ident, ilRTE::_replaceMediaObjectImageSrc($material, 1)
352 );
353 }
354 foreach ($feedbacksgeneric as $correctness => $material)
355 {
356 $this->object->feedbackOBJ->importGenericFeedback(
357 $this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)
358 );
359 }
360 $this->object->saveToDb();
361 if (count($item->suggested_solutions))
362 {
363 foreach ($item->suggested_solutions as $suggested_solution)
364 {
365 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
366 }
367 $this->object->saveToDb();
368 }
369 if ($tst_id > 0)
370 {
371 $q_1_id = $this->object->getId();
372 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
373 $tst_object->questions[$question_counter++] = $question_id;
374 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
375 }
376 else
377 {
378 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
379 }
380 //$ilLog->write(strftime("%D %T") . ": finished import multiple choice question (single response)");
381 }
$_SESSION["AccountId"]
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)
_saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
static _saveTempFileAsMediaObject($name, $tmp_name, $upload=TRUE)
Create new media object and update page in db and return new media object.
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 makeDirParents($a_dir)
Create a new directory and all parent directories.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
global $ilUser
Definition: imgupload.php:15

References $_SESSION, $GLOBALS, $ilUser, ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), assQuestionImport\addGeneralMetadata(), assQuestionImport\fetchAdditionalContentEditingModeInformation(), assQuestionImport\getQplImportArchivDirectory(), assQuestionImport\getTstImportArchivDirectory(), and ilUtil\makeDirParents().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: