ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
assSingleChoiceImport Class Reference

Class for single choice question imports. More...

+ Inheritance diagram for assSingleChoiceImport:
+ Collaboration diagram for assSingleChoiceImport:

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
 __construct ($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
 fetchIndexFromFeedbackIdent ($feedbackIdent, $prefix='response_')
 
 getFeedbackAnswerSpecific (ilQTIItem $item, $prefix='response_')
 
 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 single choice question imports.

assSingleChoiceImport is a class for single 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.assSingleChoiceImport.php.

Member Function Documentation

◆ fromXML()

assSingleChoiceImport::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

Reimplemented from assQuestionImport.

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

31 {
32 global $ilUser;
33
34 // empty session variable for imported xhtml mobs
35 unset($_SESSION["import_mob_xhtml"]);
36 $presentation = $item->getPresentation();
37 $duration = $item->getDuration();
38 $shuffle = 0;
39 $now = getdate();
40 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
41 $answers = array();
42 foreach ($presentation->order as $entry) {
43 switch ($entry["type"]) {
44 case "response":
45 $response = $presentation->response[$entry["index"]];
46 $rendertype = $response->getRenderType();
47 switch (strtolower(get_class($response->getRenderType()))) {
48 case "ilqtirenderchoice":
49 $shuffle = $rendertype->getShuffle();
50 $answerorder = 0;
51 $foundimage = false;
52 foreach ($rendertype->response_labels as $response_label) {
53 $ident = $response_label->getIdent();
54 $answertext = "";
55 $answerimage = array();
56 foreach ($response_label->material as $mat) {
57 $embedded = false;
58 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
59 $foundmat = $mat->getMaterial($m);
60 if (strcmp($foundmat["type"], "mattext") == 0) {
61 }
62 if (strcmp($foundmat["type"], "matimage") == 0) {
63 if (strlen($foundmat["material"]->getEmbedded())) {
64 $embedded = true;
65 }
66 }
67 }
68 if ($embedded) {
69 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
70 $foundmat = $mat->getMaterial($m);
71 if (strcmp($foundmat["type"], "mattext") == 0) {
72 $answertext .= $foundmat["material"]->getContent();
73 }
74 if (strcmp($foundmat["type"], "matimage") == 0) {
75 $foundimage = true;
76 $answerimage = array(
77 "imagetype" => $foundmat["material"]->getImageType(),
78 "label" => $foundmat["material"]->getLabel(),
79 "content" => $foundmat["material"]->getContent()
80 );
81 }
82 }
83 } else {
84 $answertext = $this->object->QTIMaterialToString($mat);
85 }
86 }
87 $answers[$ident] = array(
88 "answertext" => $answertext,
89 "imagefile" => $answerimage,
90 "points" => 0,
91 "answerorder" => $answerorder++,
92 "points_unchecked" => 0,
93 "action" => ""
94 );
95 }
96 break;
97 }
98 break;
99 }
100 }
101 $responses = array();
102 $feedbacks = array();
103 $feedbacksgeneric = array();
104 foreach ($item->resprocessing as $resprocessing) {
105 foreach ($resprocessing->respcondition as $respcondition) {
106 $ident = "";
107 $correctness = 1;
108 $conditionvar = $respcondition->getConditionvar();
109 foreach ($conditionvar->order as $order) {
110 switch ($order["field"]) {
111 case "arr_not":
112 $correctness = 0;
113 break;
114 case "varequal":
115 $ident = $conditionvar->varequal[$order["index"]]->getContent();
116 break;
117 }
118 }
119 foreach ($respcondition->setvar as $setvar) {
120 if (strcmp($ident, "") != 0) {
121 if ($correctness) {
122 $answers[$ident]["action"] = $setvar->getAction();
123 $answers[$ident]["points"] = $setvar->getContent();
124 if (count($respcondition->displayfeedback)) {
125 foreach ($respcondition->displayfeedback as $feedbackpointer) {
126 if (strlen($feedbackpointer->getLinkrefid())) {
127 foreach ($item->itemfeedback as $ifb) {
128 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
129 // found a feedback for the identifier
130 if (count($ifb->material)) {
131 foreach ($ifb->material as $material) {
132 $feedbacksgeneric[1] = $material;
133 }
134 }
135 if ((count($ifb->flow_mat) > 0)) {
136 foreach ($ifb->flow_mat as $fmat) {
137 if (count($fmat->material)) {
138 foreach ($fmat->material as $material) {
139 $feedbacksgeneric[1] = $material;
140 }
141 }
142 }
143 }
144 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
145 // found a feedback for the identifier
146 if (count($ifb->material)) {
147 foreach ($ifb->material as $material) {
148 $feedbacksgeneric[0] = $material;
149 }
150 }
151 if ((count($ifb->flow_mat) > 0)) {
152 foreach ($ifb->flow_mat as $fmat) {
153 if (count($fmat->material)) {
154 foreach ($fmat->material as $material) {
155 $feedbacksgeneric[0] = $material;
156 }
157 }
158 }
159 }
160 }
161 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
162 // found a feedback for the identifier
163 if (count($ifb->material)) {
164 foreach ($ifb->material as $material) {
165 $feedbacks[$ident] = $material;
166 }
167 }
168 if ((count($ifb->flow_mat) > 0)) {
169 foreach ($ifb->flow_mat as $fmat) {
170 if (count($fmat->material)) {
171 foreach ($fmat->material as $material) {
172 $feedbacks[$ident] = $material;
173 }
174 }
175 }
176 }
177 }
178 }
179 }
180 }
181 }
182 } else {
183 $answers[$ident]["action"] = $setvar->getAction();
184 $answers[$ident]["points_unchecked"] = $setvar->getContent();
185 }
186 }
187 }
188 }
189 }
190 $this->addGeneralMetadata($item);
191 $this->object->setTitle($item->getTitle());
192 $this->object->setNrOfTries($item->getMaxattempts());
193 $this->object->setComment($item->getComment());
194 $this->object->setAuthor($item->getAuthor());
195 $this->object->setOwner($ilUser->getId());
196 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
197 $this->object->setObjId($questionpool_id);
198 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
199 $this->object->setShuffle($shuffle);
200 $this->object->setThumbSize($item->getMetadataEntry("thumb_size"));
201 foreach ($answers as $answer) {
202 if ($item->getMetadataEntry('singleline') || (is_array($answer["imagefile"]) && count($answer["imagefile"]) > 0)) {
203 $this->object->isSingleline = true;
204 }
205 $this->object->addAnswer($answer["answertext"], $answer["points"], $answer["answerorder"], $answer["imagefile"]["label"]);
206 }
207 // additional content editing mode information
208 $this->object->setAdditionalContentEditingMode(
210 );
211 $this->object->saveToDb();
212 foreach ($answers as $answer) {
213 if (is_array($answer["imagefile"]) && (count($answer["imagefile"]) > 0)) {
214 $image =&base64_decode($answer["imagefile"]["content"]);
215 $imagepath = $this->object->getImagePath();
216 include_once "./Services/Utilities/classes/class.ilUtil.php";
217 if (!file_exists($imagepath)) {
218 ilUtil::makeDirParents($imagepath);
219 }
220 $imagepath .= $answer["imagefile"]["label"];
221 $fh = fopen($imagepath, "wb");
222 if ($fh == false) {
223 } else {
224 $imagefile = fwrite($fh, $image);
225 fclose($fh);
226 }
227 }
228 }
229
230 $feedbackSetting = $item->getMetadataEntry('feedback_setting');
231 if (!is_null($feedbackSetting)) {
232 $this->object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting);
233 }
234
235 foreach ($feedbacks as $ident => $material) {
236 $m = $this->object->QTIMaterialToString($material);
237 $feedbacks[$ident] = $m;
238 }
239 foreach ($feedbacksgeneric as $correctness => $material) {
240 $m = $this->object->QTIMaterialToString($material);
241 $feedbacksgeneric[$correctness] = $m;
242 }
243 // handle the import of media objects in XHTML code
244 $questiontext = $this->object->getQuestion();
245 $answers =&$this->object->getAnswers();
246 if (is_array($_SESSION["import_mob_xhtml"])) {
247 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
248 include_once "./Services/RTE/classes/class.ilRTE.php";
249 foreach ($_SESSION["import_mob_xhtml"] as $mob) {
250 if ($tst_id > 0) {
251 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
252 } else {
253 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
254 }
255
256 $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
257
258 $media_object =&ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
259 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
260 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
261 foreach ($answers as $key => $value) {
262 $answer_obj = $answers[$key];
263 $answer_obj->setAnswertext(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $answer_obj->getAnswertext()));
264 }
265 foreach ($feedbacks as $ident => $material) {
266 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
267 }
268 foreach ($feedbacksgeneric as $correctness => $material) {
269 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
270 }
271 }
272 }
273 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
274 foreach ($answers as $key => $value) {
275 $answer_obj =&$answers[$key];
276 $answer_obj->setAnswertext(ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 1));
277 }
278 foreach ($feedbacks as $ident => $material) {
279 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
280 $this->object->getId(),
281 $ident,
283 );
284 }
285 foreach ($feedbacksgeneric as $correctness => $material) {
286 $this->object->feedbackOBJ->importGenericFeedback(
287 $this->object->getId(),
288 $correctness,
290 );
291 }
292 $this->object->saveToDb();
293 if (count($item->suggested_solutions)) {
294 foreach ($item->suggested_solutions as $suggested_solution) {
295 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
296 }
297 $this->object->saveToDb();
298 }
299 if ($tst_id > 0) {
300 $q_1_id = $this->object->getId();
301 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
302 $tst_object->questions[$question_counter++] = $question_id;
303 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
304 } else {
305 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
306 }
307 }
sprintf('%.4f', $callTime)
$_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)
static _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.
$key
Definition: croninfo.php:18
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$response
$ilUser
Definition: imgupload.php:18

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

+ Here is the call graph for this function:

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