ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
 __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 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 public

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

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

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

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