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

Data Fields

 $object
 
- Data Fields inherited from assQuestionImport
 $object
 

Additional Inherited Members

- 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 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 35 of file class.assOrderingQuestionImport.php.

References $_SESSION, $DIC, $ilUser, $index, $m, $response, $type, ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), assQuestionImport\addGeneralMetadata(), ilUtil\convertImage(), assQuestionImport\fetchAdditionalContentEditingModeInformation(), assQuestionImport\fetchIndexFromFeedbackIdent(), assQuestionImport\getFeedbackAnswerSpecific(), assQuestionImport\getQplImportArchivDirectory(), assQuestionImport\getTstImportArchivDirectory(), ilUtil\makeDirParents(), OQ_NESTED_PICTURES, OQ_NESTED_TERMS, OQ_PICTURES, OQ_TERMS, assQuestion\resetOriginalId(), and assQuestion\saveOriginalId().

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

Field Documentation

◆ $object

assOrderingQuestionImport::$object

Definition at line 20 of file class.assOrderingQuestionImport.php.


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