ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
assOrderingQuestionImport Class Reference

Class for ordering question imports. More...

+ Inheritance diagram for assOrderingQuestionImport:
+ Collaboration diagram for assOrderingQuestionImport:

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
 assQuestionImport (&$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
 getFeedbackAnswerSpecific (ilQTIItem $item)
 
 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 ordering question imports.

assOrderingQuestionImport is a class for ordering 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.assOrderingQuestionImport.php.

Member Function Documentation

◆ fromXML()

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

References $_SESSION, $GLOBALS, $ilUser, ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), assQuestionImport\addGeneralMetadata(), ilUtil\convertImage(), assQuestionImport\fetchAdditionalContentEditingModeInformation(), assQuestionImport\getQplImportArchivDirectory(), assQuestionImport\getTstImportArchivDirectory(), ilUtil\makeDirParents(), OQ_NESTED_PICTURES, OQ_NESTED_TERMS, OQ_PICTURES, and OQ_TERMS.

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

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