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

Class for cloze question imports. More...

+ Inheritance diagram for assClozeTestImport:
+ Collaboration diagram for assClozeTestImport:

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 cloze question imports.

assClozeTestImport is a class for cloze 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.assClozeTestImport.php.

Member Function Documentation

◆ fromXML()

assClozeTestImport::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.assClozeTestImport.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
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 = '&nbsp;';
45 } elseif ($seperate_question_field) {
46 $questiontext = $this->processNonAbstractedImageReferences(
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"]];
74 $rendertype = $response->getRenderType();
75 array_push($clozetext, "<<" . $response->getIdent() . ">>");
76
77 switch (strtolower(get_class($response->getRenderType()))) {
78 case "ilqtirenderfib":
79 switch ($response->getRenderType()->getFibtype()) {
80 case FIBTYPE_DECIMAL:
81 case FIBTYPE_INTEGER:
82 array_push(
83 $gaps,
84 array(
85 "ident" => $response->getIdent(),
86 "type" => CLOZE_NUMERIC,
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:
95 case FIBTYPE_STRING:
96 array_push(
97 $gaps,
98 array("ident" => $response->getIdent(),
99 "type" => CLOZE_TEXT,
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) {
151 if ($g["type"] == CLOZE_SELECT) {
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 }
158 } elseif ($g["type"] == CLOZE_TEXT) {
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 ));
166 } elseif ($g["type"] == CLOZE_NUMERIC) {
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 // found a feedback for the identifier
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 // found a feedback for the identifier
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 // found a feedback for the identifier
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
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->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";
259 $clozegap = new assClozeGap($gap["type"]);
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()) {
265 case CLOZE_SELECT:
266 $clozegap->setShuffle($answer["shuffle"]);
267 break;
268 case CLOZE_NUMERIC:
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 // additional content editing mode information
290 $this->object->setAdditionalContentEditingMode(
292 );
293 $this->object->saveToDb();
294
295 // handle the import of media objects in XHTML code
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) {
311 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
312 } else {
313 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
314 }
315
316 $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
317
318 $media_object =&ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
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 }
329 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
330 $this->object->setClozeTextValue(ilRTE::_replaceMediaObjectImageSrc($clozetext, 1));
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';
364 assClozeGapCombination::importGapCombinationToDb($this->object->getId(), $combination);
365 }
366 $this->object->saveToDb();
367 }
sprintf('%.4f', $callTime)
$_SESSION["AccountId"]
const FIBTYPE_STRING
const FIBTYPE_INTEGER
const FIBTYPE_DECIMAL
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 _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...
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
const CLOZE_NUMERIC
const CLOZE_SELECT
const CLOZE_TEXT
Cloze question constants.
$index
Definition: metadata.php:60
$response
$ilUser
Definition: imgupload.php:18

References $_SESSION, $GLOBALS, $ilUser, $index, $m, $response, ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), assQuestionImport\addGeneralMetadata(), assClozeGapCombination\clearGapCombinationsFromDb(), CLOZE_NUMERIC, CLOZE_SELECT, CLOZE_TEXT, assQuestionImport\fetchAdditionalContentEditingModeInformation(), FIBTYPE_DECIMAL, FIBTYPE_INTEGER, FIBTYPE_STRING, assQuestionImport\getQplImportArchivDirectory(), assQuestionImport\getTstImportArchivDirectory(), assClozeGapCombination\importGapCombinationToDb(), assQuestionImport\processNonAbstractedImageReferences(), and sprintf.

+ Here is the call graph for this function:

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