ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
assMultipleChoiceImport Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

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

Public Member Functions

 fromXML (string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
 
- Public Member Functions inherited from assQuestionImport
 getQuestionId ()
 
 getFeedbackGeneric ($item)
 
 fromXML (string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
 
 importSuggestedSolutions (int $question_id, array $solution_from_import)
 
 QTIMaterialToString (ilQTIMaterial $a_material)
 Reads an QTI material tag and creates a text or XHTML string. 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)
 
 fetchLifecycle (ilQTIItem $item)
 
 processNonAbstractedImageReferences ($text, $sourceNic)
 
 fetchAdditionalContentEditingModeInformation ($qtiItem)
 fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_CONTENT_EDITING_MODE_RTE when no or invalid information is given More...
 
 findSolutionTypeByValue (string $value)
 
 getSuggestedSolutionsRepo ()
 
 deduceThumbSizeFromImportValue (?int $size)
 
 addQuestionToParentObjectAndBuildMappingEntry (int $questionpool_id, ?int $tst_id, int &$question_counter, ?ilObjTest &$tst_object)
 
- Protected Attributes inherited from assQuestionImport
SuggestedSolutionsDatabaseRepository $suggestedsolution_repo = null
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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 28 of file class.assMultipleChoiceImport.php.

Member Function Documentation

◆ fromXML()

assMultipleChoiceImport::fromXML ( string  $importdirectory,
int  $user_id,
ilQTIItem  $item,
int  $questionpool_id,
?int  $tst_id,
?ilObject $tst_object,
int &  $question_counter,
array  $import_mapping 
)

Reimplemented from assQuestionImport.

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

39 : array {
40 // empty session variable for imported xhtml mobs
41 ilSession::clear('import_mob_xhtml');
42
43 $presentation = $item->getPresentation();
44 $shuffle = 0;
45 $selectionLimit = null;
46 $now = getdate();
47 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
48 $answers = [];
49 foreach ($presentation->order as $entry) {
50 switch ($entry["type"]) {
51 case "response":
52 $response = $presentation->response[$entry["index"]];
53 $rendertype = $response->getRenderType();
54 switch (strtolower(get_class($response->getRenderType()))) {
55 case "ilqtirenderchoice":
56 $shuffle = $rendertype->getShuffle();
57 if ($rendertype->getMaxnumber()) {
58 $selectionLimit = $rendertype->getMaxnumber();
59 }
60 $answerorder = 0;
61 $foundimage = false;
62 foreach ($rendertype->response_labels as $response_label) {
63 $ident = $response_label->getIdent();
64 $answertext = "";
65 $answerimage = [];
66 foreach ($response_label->material as $mat) {
67 $embedded = false;
68 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
69 $foundmat = $mat->getMaterial($m);
70 if (strcmp($foundmat["type"], "mattext") == 0) {
71 }
72 if (strcmp($foundmat["type"], "matimage") == 0) {
73 if (strlen($foundmat["material"]->getEmbedded())) {
74 $embedded = true;
75 }
76 }
77 }
78 if ($embedded) {
79 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
80 $foundmat = $mat->getMaterial($m);
81 if (strcmp($foundmat["type"], "mattext") == 0) {
82 $answertext .= $foundmat["material"]->getContent();
83 }
84 if (strcmp($foundmat["type"], "matimage") == 0) {
85 $foundimage = true;
86 $answerimage = [
87 "imagetype" => $foundmat["material"]->getImageType(),
88 "label" => $foundmat["material"]->getLabel(),
89 "content" => $foundmat["material"]->getContent()
90 ];
91 }
92 }
93 } else {
94 $answertext = $this->QTIMaterialToString($mat);
95 }
96 }
97 $answers[$ident] = [
98 "answertext" => $answertext,
99 "imagefile" => $answerimage,
100 "points" => 0,
101 "answerorder" => $answerorder++,
102 "points_unchecked" => 0,
103 "action" => ""
104 ];
105 }
106 break;
107 }
108 break;
109 }
110 }
111 $feedbacks = [];
112 $feedbacksgeneric = [];
113 foreach ($item->resprocessing as $resprocessing) {
114 foreach ($resprocessing->respcondition as $respcondition) {
115 $ident = "";
116 $correctness = 1;
117 $conditionvar = $respcondition->getConditionvar();
118 foreach ($conditionvar->order as $order) {
119 switch ($order["field"]) {
120 case "arr_not":
121 $correctness = 0;
122 break;
123 case "varequal":
124 $ident = $conditionvar->varequal[$order["index"]]->getContent();
125 break;
126 }
127 }
128 foreach ($respcondition->setvar as $setvar) {
129 if (strcmp($ident, "") != 0) {
130 if ($correctness) {
131 $answers[$ident]["action"] = $setvar->getAction();
132 $answers[$ident]["points"] = $setvar->getContent();
133 if (count($respcondition->displayfeedback)) {
134 foreach ($respcondition->displayfeedback as $feedbackpointer) {
135 if (strlen($feedbackpointer->getLinkrefid())) {
136 foreach ($item->itemfeedback as $ifb) {
137 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
138 // found a feedback for the identifier
139 if (count($ifb->material)) {
140 foreach ($ifb->material as $material) {
141 $feedbacksgeneric[1] = $material;
142 }
143 }
144 if ((count($ifb->flow_mat) > 0)) {
145 foreach ($ifb->flow_mat as $fmat) {
146 if (count($fmat->material)) {
147 foreach ($fmat->material as $material) {
148 $feedbacksgeneric[1] = $material;
149 }
150 }
151 }
152 }
153 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
154 // found a feedback for the identifier
155 if (count($ifb->material)) {
156 foreach ($ifb->material as $material) {
157 $feedbacksgeneric[0] = $material;
158 }
159 }
160 if ((count($ifb->flow_mat) > 0)) {
161 foreach ($ifb->flow_mat as $fmat) {
162 if (count($fmat->material)) {
163 foreach ($fmat->material as $material) {
164 $feedbacksgeneric[0] = $material;
165 }
166 }
167 }
168 }
169 }
170 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
171 // found a feedback for the identifier
172 if (count($ifb->material)) {
173 foreach ($ifb->material as $material) {
174 $feedbacks[$ident] = $material;
175 }
176 }
177 if ((count($ifb->flow_mat) > 0)) {
178 foreach ($ifb->flow_mat as $fmat) {
179 if (count($fmat->material)) {
180 foreach ($fmat->material as $material) {
181 $feedbacks[$ident] = $material;
182 }
183 }
184 }
185 }
186 }
187 }
188 }
189 }
190 }
191 } else {
192 $answers[$ident]["action"] = $setvar->getAction();
193 $answers[$ident]["points_unchecked"] = $setvar->getContent();
194 }
195 }
196 }
197 }
198 }
199 $this->addGeneralMetadata($item);
200 $this->object->setTitle($item->getTitle());
201 $this->object->setNrOfTries((int) $item->getMaxattempts());
202 $this->object->setComment($item->getComment());
203 $this->object->setAuthor($item->getAuthor());
204 $this->object->setOwner($user_id);
205 $this->object->setQuestion($this->QTIMaterialToString($item->getQuestiontext()));
206 $this->object->setObjId($questionpool_id);
207 $this->object->setShuffle($shuffle);
208 $this->object->setSelectionLimit($selectionLimit);
209 $this->object->setIsSingleline(false);
210 $this->object->setThumbSize(
211 $this->deduceThumbSizeFromImportValue((int) $item->getMetadataEntry('thumb_size'))
212 );
213
214 foreach ($answers as $answer) {
215 if ($item->getMetadataEntry('singleline') || (is_array($answer["imagefile"]) && count($answer["imagefile"]) > 0)) {
216 $this->object->setIsSingleline(true);
217 }
218 $this->object->addAnswer(
219 $answer["answertext"],
220 (float) $answer["points"],
221 (float) $answer["points_unchecked"],
222 $answer["answerorder"],
223 $answer["imagefile"]["label"] ?? null
224 );
225 }
226 // additional content editing mode information
227 $this->object->setAdditionalContentEditingMode(
229 );
230 $this->object->saveToDb();
231 foreach ($answers as $answer) {
232 if (is_array($answer["imagefile"]) && (count($answer["imagefile"]) > 0)) {
233 $image = base64_decode($answer["imagefile"]["content"]);
234 $imagepath = $this->object->getImagePath();
235 if (!file_exists($imagepath)) {
236 ilFileUtils::makeDirParents($imagepath);
237 }
238 $imagepath .= $answer["imagefile"]["label"];
239 $fh = fopen($imagepath, "wb");
240 if ($fh !== false) {
241 $imagefile = fwrite($fh, $image);
242 fclose($fh);
243 $this->object->generateThumbForFile(
244 $answer["imagefile"]["label"],
245 $this->object->getImagePath(),
246 $this->object->getThumbSize()
247 );
248 }
249 }
250 }
251
252 $feedbackSetting = $item->getMetadataEntry('feedback_setting');
253 if (!is_null($feedbackSetting)) {
254 $this->object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting);
255 }
256
257 // handle the import of media objects in XHTML code
258 foreach ($feedbacks as $ident => $material) {
259 $m = $this->QTIMaterialToString($material);
260 $feedbacks[$ident] = $m;
261 }
262 foreach ($feedbacksgeneric as $correctness => $material) {
263 $m = $this->QTIMaterialToString($material);
264 $feedbacksgeneric[$correctness] = $m;
265 }
266 $questiontext = $this->object->getQuestion();
267 $answers = $this->object->getAnswers();
268 if (is_array(ilSession::get("import_mob_xhtml"))) {
269 foreach (ilSession::get("import_mob_xhtml") as $mob) {
270 $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob["uri"];
271
272 global $DIC; /* @var ILIAS\DI\Container $DIC */
273 $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
274
275 $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
276 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
277 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
278 foreach ($answers as $key => $value) {
279 $answer_obj = &$answers[$key];
280 $answer_obj->setAnswertext(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $answer_obj->getAnswertext()));
281 }
282 foreach ($feedbacks as $ident => $material) {
283 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
284 }
285 foreach ($feedbacksgeneric as $correctness => $material) {
286 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
287 }
288 }
289 }
290 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
291 foreach ($answers as $key => $value) {
292 $answer_obj = &$answers[$key];
293 $answer_obj->setAnswertext(ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 1));
294 }
295 foreach ($feedbacks as $ident => $material) {
296 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
297 $this->object->getId(),
298 0,
299 $ident,
301 );
302 }
303 foreach ($feedbacksgeneric as $correctness => $material) {
304 $this->object->feedbackOBJ->importGenericFeedback(
305 $this->object->getId(),
306 $correctness,
308 );
309 }
310 $this->object->saveToDb();
311 $this->importSuggestedSolutions($this->object->getId(), $item->suggested_solutions);
312 $import_mapping[$item->getIdent()] = $this->addQuestionToParentObjectAndBuildMappingEntry(
313 $questionpool_id,
314 $tst_id,
315 $question_counter,
316 $tst_object
317 );
318 return $import_mapping;
319 }
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
addQuestionToParentObjectAndBuildMappingEntry(int $questionpool_id, ?int $tst_id, int &$question_counter, ?ilObjTest &$tst_object)
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
addGeneralMetadata(ilQTIItem $item)
deduceThumbSizeFromImportValue(?int $size)
importSuggestedSolutions(int $question_id, array $solution_from_import)
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static _saveTempFileAsMediaObject(string $name, string $tmp_name, bool $upload=true)
static _saveUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Save usage of mob within another container (e.g.
getMetadataEntry(string $a_label)
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static get(string $a_var)
static clear(string $a_var)
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: shib_login.php:26
$response
Definition: xapitoken.php:93

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