ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
assImagemapQuestionImport Class Reference

Class for imagemap question imports. More...

+ Inheritance diagram for assImagemapQuestionImport:
+ Collaboration diagram for assImagemapQuestionImport:

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

assImagemapQuestionImport is a class for imagemap 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.assImagemapQuestionImport.php.

Member Function Documentation

◆ fromXML()

assImagemapQuestionImport::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.assImagemapQuestionImport.php.

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

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  $now = getdate();
39  $questionimage = array();
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  {
44  switch ($entry["type"])
45  {
46  case "response":
47  $response = $presentation->response[$entry["index"]];
48  $rendertype = $response->getRenderType();
49  switch (strtolower(get_class($rendertype)))
50  {
51  case "ilqtirenderhotspot":
52  foreach ($rendertype->material as $mat)
53  {
54  for ($i = 0; $i < $mat->getMaterialCount(); $i++)
55  {
56  $m = $mat->getMaterial($i);
57  if (strcmp($m["type"], "matimage") == 0)
58  {
59  $questionimage = array(
60  "imagetype" => $m["material"]->getImageType(),
61  "label" => $m["material"]->getLabel(),
62  "content" => $m["material"]->getContent()
63  );
64  }
65  }
66  }
67  foreach ($rendertype->response_labels as $response_label)
68  {
69  $ident = $response_label->getIdent();
70  $answerhint = "";
71  foreach ($response_label->material as $mat)
72  {
73  $answerhint .= $this->object->QTIMaterialToString($mat);
74  }
75  $answers[$ident] = array(
76  "answerhint" => $answerhint,
77  "areatype" => $response_label->getRarea(),
78  "coordinates" => $response_label->getContent(),
79  "points" => 0,
80  "answerorder" => $response_label->getIdent(),
81  "correctness" => "1",
82  "action" => "",
83  "points_unchecked" => 0
84  );
85  }
86  break;
87  }
88  break;
89  }
90  }
91  $responses = array();
92  $feedbacks = array();
93  $feedbacksgeneric = array();
94  foreach ($item->resprocessing as $resprocessing)
95  {
96  foreach ($resprocessing->respcondition as $respcondition)
97  {
98  $coordinates = "";
99  $correctness = 1;
100  $conditionvar = $respcondition->getConditionvar();
101  foreach ($conditionvar->order as $order)
102  {
103  switch ($order["field"])
104  {
105  case "arr_not":
106  $correctness = 0;
107  break;
108  case "varinside":
109  $coordinates = $conditionvar->varinside[$order["index"]]->getContent();
110  break;
111  case "varequal":
112  $coordinates = $conditionvar->varequal[$order["index"]]->getContent();
113  break;
114  }
115  }
116  foreach ($respcondition->setvar as $setvar)
117  {
118  foreach ($answers as $ident => $answer)
119  {
120  if (strcmp($answer["coordinates"], $coordinates) == 0)
121  {
122  if ($correctness)
123  {
124  $answers[$ident]["action"] = $setvar->getAction();
125  $answers[$ident]["points"] = $setvar->getContent();
126  if (count($respcondition->displayfeedback))
127  {
128  foreach ($respcondition->displayfeedback as $feedbackpointer)
129  {
130  if (strlen($feedbackpointer->getLinkrefid()))
131  {
132  foreach ($item->itemfeedback as $ifb)
133  {
134  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0)
135  {
136  // found a feedback for the identifier
137  if (count($ifb->material))
138  {
139  foreach ($ifb->material as $material)
140  {
141  $feedbacksgeneric[1] = $material;
142  }
143  }
144  if ((count($ifb->flow_mat) > 0))
145  {
146  foreach ($ifb->flow_mat as $fmat)
147  {
148  if (count($fmat->material))
149  {
150  foreach ($fmat->material as $material)
151  {
152  $feedbacksgeneric[1] = $material;
153  }
154  }
155  }
156  }
157  }
158  else if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0)
159  {
160  // found a feedback for the identifier
161  if (count($ifb->material))
162  {
163  foreach ($ifb->material as $material)
164  {
165  $feedbacksgeneric[0] = $material;
166  }
167  }
168  if ((count($ifb->flow_mat) > 0))
169  {
170  foreach ($ifb->flow_mat as $fmat)
171  {
172  if (count($fmat->material))
173  {
174  foreach ($fmat->material as $material)
175  {
176  $feedbacksgeneric[0] = $material;
177  }
178  }
179  }
180  }
181  }
182  if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0)
183  {
184  // found a feedback for the identifier
185  if (count($ifb->material))
186  {
187  foreach ($ifb->material as $material)
188  {
189  $feedbacks[$ident] = $material;
190  }
191  }
192  if ((count($ifb->flow_mat) > 0))
193  {
194  foreach ($ifb->flow_mat as $fmat)
195  {
196  if (count($fmat->material))
197  {
198  foreach ($fmat->material as $material)
199  {
200  $feedbacks[$ident] = $material;
201  }
202  }
203  }
204  }
205  }
206  }
207  }
208  }
209  }
210  }
211  else
212  {
213  $answers[$ident]["action"] = $setvar->getAction();
214  $answers[$ident]["points_unchecked"] = $setvar->getContent();
215  }
216  }
217  }
218  }
219  }
220  }
221 
222  $this->addGeneralMetadata($item);
223  $this->object->setTitle($item->getTitle());
224  $this->object->setNrOfTries($item->getMaxattempts());
225  $this->object->setComment($item->getComment());
226  $this->object->setAuthor($item->getAuthor());
227  $this->object->setOwner($ilUser->getId());
228  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
229  $this->object->setObjId($questionpool_id);
230  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
231  $this->object->setIsMultipleChoice($item->getMetadataEntry("IS_MULTIPLE_CHOICE"));
232  $areas = array("2" => "rect", "1" => "circle", "3" => "poly");
233  $this->object->setImageFilename($questionimage["label"]);
234  foreach ($answers as $answer)
235  {
236  $this->object->addAnswer($answer["answerhint"], $answer["points"], $answer["answerorder"], $answer["coordinates"], $areas[$answer["areatype"]], $answer["points_unchecked"]);
237  }
238  // additional content editing mode information
239  $this->object->setAdditionalContentEditingMode(
241  );
242  $this->object->saveToDb();
243  if (count($item->suggested_solutions))
244  {
245  foreach ($item->suggested_solutions as $suggested_solution)
246  {
247  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
248  }
249  $this->object->saveToDb();
250  }
251  $image =& base64_decode($questionimage["content"]);
252  $imagepath = $this->object->getImagePath();
253  if (!file_exists($imagepath))
254  {
255  include_once "./Services/Utilities/classes/class.ilUtil.php";
256  ilUtil::makeDirParents($imagepath);
257  }
258  $imagepath .= $questionimage["label"];
259  $fh = fopen($imagepath, "wb");
260  if ($fh == false)
261  {
262 // global $ilErr;
263 // $ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE);
264 // return;
265  }
266  else
267  {
268  $imagefile = fwrite($fh, $image);
269  fclose($fh);
270  }
271  // handle the import of media objects in XHTML code
272  foreach ($feedbacks as $ident => $material)
273  {
274  $m = $this->object->QTIMaterialToString($material);
275  $feedbacks[$ident] = $m;
276  }
277  foreach ($feedbacksgeneric as $correctness => $material)
278  {
279  $m = $this->object->QTIMaterialToString($material);
280  $feedbacksgeneric[$correctness] = $m;
281  }
282  $questiontext = $this->object->getQuestion();
283  if (is_array($_SESSION["import_mob_xhtml"]))
284  {
285  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
286  include_once "./Services/RTE/classes/class.ilRTE.php";
287  foreach ($_SESSION["import_mob_xhtml"] as $mob)
288  {
289  if ($tst_id > 0)
290  {
291  $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
292  }
293  else
294  {
295  $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
296  }
297 
298  $GLOBALS['ilLog']->write(__METHOD__.': import mob from dir: '. $importfile);
299 
300  $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
301  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
302  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
303  foreach ($feedbacks as $ident => $material)
304  {
305  $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
306  }
307  foreach ($feedbacksgeneric as $correctness => $material)
308  {
309  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
310  }
311  }
312  }
313  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
314  foreach ($feedbacks as $ident => $material)
315  {
316  $this->object->feedbackOBJ->importSpecificAnswerFeedback(
317  $this->object->getId(), $ident, ilRTE::_replaceMediaObjectImageSrc($material, 1)
318  );
319  }
320  foreach ($feedbacksgeneric as $correctness => $material)
321  {
322  $this->object->feedbackOBJ->importGenericFeedback(
323  $this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)
324  );
325  }
326  $this->object->saveToDb();
327  if ($tst_id > 0)
328  {
329  $q_1_id = $this->object->getId();
330  $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
331  $tst_object->questions[$question_counter++] = $question_id;
332  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
333  }
334  else
335  {
336  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
337  }
338  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
addGeneralMetadata(ilQTIItem $item)
$_SESSION["AccountId"]
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
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 _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 _saveTempFileAsMediaObject($name, $tmp_name, $upload=TRUE)
Create new media object and update page in db and return new media object.
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
Create new PHPExcel object
obj_idprivate
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst 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.
+ Here is the call graph for this function:

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