ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
assKprimChoiceImport Class Reference
+ Inheritance diagram for assKprimChoiceImport:
+ Collaboration diagram for assKprimChoiceImport:

Public Member Functions

 fromXML (&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 
- 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

Definition at line 13 of file class.assKprimChoiceImport.php.

Member Function Documentation

◆ fromXML()

assKprimChoiceImport::fromXML ( $item,
  $questionpool_id,
$tst_id,
$tst_object,
$question_counter,
$import_mapping 
)

Definition at line 20 of file class.assKprimChoiceImport.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.

21  {
22  global $ilUser;
23 
24  unset($_SESSION["import_mob_xhtml"]);
25 
26  $duration = $item->getDuration();
27  $shuffle = 0;
28  $answers = array();
29 
30  $presentation = $item->getPresentation();
31  foreach ($presentation->order as $entry)
32  {
33  switch ($entry["type"])
34  {
35  case "response":
36  $response = $presentation->response[$entry["index"]];
37  $rendertype = $response->getRenderType();
38  switch (strtolower(get_class($response->getRenderType())))
39  {
40  case "ilqtirenderchoice":
41  $shuffle = $rendertype->getShuffle();
42  $answerorder = 0;
43  $foundimage = FALSE;
44  foreach ($rendertype->response_labels as $response_label)
45  {
46  $ident = $response_label->getIdent();
47  $answertext = "";
48  $answerimage = array();
49  foreach ($response_label->material as $mat)
50  {
51  $embedded = false;
52  for ($m = 0; $m < $mat->getMaterialCount(); $m++)
53  {
54  $foundmat = $mat->getMaterial($m);
55  if (strcmp($foundmat["type"], "mattext") == 0)
56  {
57  }
58  if (strcmp($foundmat["type"], "matimage") == 0)
59  {
60  if (strlen($foundmat["material"]->getEmbedded()))
61  {
62  $embedded = true;
63  }
64  }
65  }
66  if ($embedded)
67  {
68  for ($m = 0; $m < $mat->getMaterialCount(); $m++)
69  {
70  $foundmat = $mat->getMaterial($m);
71  if (strcmp($foundmat["type"], "mattext") == 0)
72  {
73  $answertext .= $foundmat["material"]->getContent();
74  }
75  if (strcmp($foundmat["type"], "matimage") == 0)
76  {
77  $foundimage = TRUE;
78  $answerimage = array(
79  "imagetype" => $foundmat["material"]->getImageType(),
80  "label" => $foundmat["material"]->getLabel(),
81  "content" => $foundmat["material"]->getContent()
82  );
83  }
84  }
85  }
86  else
87  {
88  $answertext = $this->object->QTIMaterialToString($mat);
89  }
90  }
91 
92  $answers[$ident] = array(
93  "answertext" => $answertext,
94  "imagefile" => $answerimage,
95  "answerorder" => $ident
96  );
97  }
98  break;
99  }
100  break;
101  }
102  }
103 
104  $feedbacks = array();
105  $feedbacksgeneric = array();
106 
107  foreach ($item->resprocessing as $resprocessing)
108  {
109  foreach($resprocessing->outcomes->decvar as $decvar)
110  {
111  if( $decvar->getVarname() == 'SCORE' )
112  {
113  $this->object->setPoints($decvar->getMaxvalue());
114 
115  if( $decvar->getMinvalue() > 0 )
116  {
117  $this->object->setScorePartialSolutionEnabled(true);
118  }
119  else
120  {
121  $this->object->setScorePartialSolutionEnabled(false);
122  }
123  }
124  }
125 
126  foreach ($resprocessing->respcondition as $respcondition)
127  {
128  if( !count($respcondition->setvar) )
129  {
130  foreach($respcondition->getConditionvar()->varequal as $varequal)
131  {
132  $ident = $varequal->respident;
133  $answers[$ident]['correctness'] = (bool)$varequal->getContent();
134 
135  break;
136  }
137 
138  foreach ($respcondition->displayfeedback as $feedbackpointer)
139  {
140  if (strlen($feedbackpointer->getLinkrefid()))
141  {
142  foreach ($item->itemfeedback as $ifb)
143  {
144  if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0)
145  {
146  // found a feedback for the identifier
147  if (count($ifb->material))
148  {
149  foreach ($ifb->material as $material)
150  {
151  $feedbacks[$ident] = $material;
152  }
153  }
154  if ((count($ifb->flow_mat) > 0))
155  {
156  foreach ($ifb->flow_mat as $fmat)
157  {
158  if (count($fmat->material))
159  {
160  foreach ($fmat->material as $material)
161  {
162  $feedbacks[$ident] = $material;
163  }
164  }
165  }
166  }
167  }
168  }
169  }
170  }
171  }
172  else
173  {
174  foreach ($respcondition->displayfeedback as $feedbackpointer)
175  {
176  if (strlen($feedbackpointer->getLinkrefid()))
177  {
178  foreach ($item->itemfeedback as $ifb)
179  {
180  if( $ifb->getIdent() == "response_allcorrect" )
181  {
182  // found a feedback for the identifier
183  if (count($ifb->material))
184  {
185  foreach ($ifb->material as $material)
186  {
187  $feedbacksgeneric[1] = $material;
188  }
189  }
190  if ((count($ifb->flow_mat) > 0))
191  {
192  foreach ($ifb->flow_mat as $fmat)
193  {
194  if (count($fmat->material))
195  {
196  foreach ($fmat->material as $material)
197  {
198  $feedbacksgeneric[1] = $material;
199  }
200  }
201  }
202  }
203  }
204  else if ( $ifb->getIdent() == "response_onenotcorrect" )
205  {
206  // found a feedback for the identifier
207  if (count($ifb->material))
208  {
209  foreach ($ifb->material as $material)
210  {
211  $feedbacksgeneric[0] = $material;
212  }
213  }
214  if ((count($ifb->flow_mat) > 0))
215  {
216  foreach ($ifb->flow_mat as $fmat)
217  {
218  if (count($fmat->material))
219  {
220  foreach ($fmat->material as $material)
221  {
222  $feedbacksgeneric[0] = $material;
223  }
224  }
225  }
226  }
227  }
228  }
229  }
230  }
231  }
232  }
233  }
234 
235  $this->addGeneralMetadata($item);
236 
237  $this->object->setTitle($item->getTitle());
238  $this->object->setNrOfTries($item->getMaxattempts());
239  $this->object->setComment($item->getComment());
240  $this->object->setAuthor($item->getAuthor());
241  $this->object->setOwner($ilUser->getId());
242  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
243  $this->object->setObjId($questionpool_id);
244  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
245  $this->object->setShuffleAnswersEnabled($shuffle);
246  $this->object->setAnswerType($item->getMetadataEntry("answer_type"));
247  $this->object->setOptionLabel($item->getMetadataEntry("option_label_setting"));
248  $this->object->setCustomTrueOptionLabel($item->getMetadataEntry("custom_true_option_label"));
249  $this->object->setCustomFalseOptionLabel($item->getMetadataEntry("custom_false_option_label"));
250  $this->object->setThumbSize($item->getMetadataEntry("thumb_size"));
251 
252  $this->object->saveToDb();
253 
254  foreach ($answers as $answerData)
255  {
256  $answer = new ilAssKprimChoiceAnswer();
257  $answer->setImageFsDir($this->object->getImagePath());
258  $answer->setImageWebDir($this->object->getImagePathWeb());
259 
260  $answer->setPosition($answerData['answerorder']);
261  $answer->setAnswertext($answerData['answertext']);
262  $answer->setCorrectness($answerData['correctness']);
263 
264  if( isset($answerData['imagefile']['label']) )
265  {
266  $answer->setImageFile($answerData['imagefile']['label']);
267  }
268 
269  $this->object->addAnswer($answer);
270  }
271  // additional content editing mode information
272  $this->object->setAdditionalContentEditingMode(
274  );
275 
276  $this->object->saveToDb();
277 
278  foreach ($answers as $answer)
279  {
280  if (is_array($answer["imagefile"]) && (count($answer["imagefile"]) > 0))
281  {
282  $image =& base64_decode($answer["imagefile"]["content"]);
283  $imagepath = $this->object->getImagePath();
284  include_once "./Services/Utilities/classes/class.ilUtil.php";
285  if (!file_exists($imagepath))
286  {
287  ilUtil::makeDirParents($imagepath);
288  }
289  $imagepath .= $answer["imagefile"]["label"];
290  if($fh = fopen($imagepath, "wb"))
291  {
292  $imagefile = fwrite($fh, $image);
293  fclose($fh);
294  }
295  }
296  }
297 
298  $feedbackSetting = $item->getMetadataEntry('feedback_setting');
299  if( !is_null($feedbackSetting) )
300  {
301  $this->object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting);
302  }
303 
304  // handle the import of media objects in XHTML code
305  foreach ($feedbacks as $ident => $material)
306  {
307  $m = $this->object->QTIMaterialToString($material);
308  $feedbacks[$ident] = $m;
309  }
310  foreach ($feedbacksgeneric as $correctness => $material)
311  {
312  $m = $this->object->QTIMaterialToString($material);
313  $feedbacksgeneric[$correctness] = $m;
314  }
315  $questiontext = $this->object->getQuestion();
316  $answers =& $this->object->getAnswers();
317  if (is_array($_SESSION["import_mob_xhtml"]))
318  {
319  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
320  include_once "./Services/RTE/classes/class.ilRTE.php";
321  foreach ($_SESSION["import_mob_xhtml"] as $mob)
322  {
323  if ($tst_id > 0)
324  {
325  $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
326  }
327  else
328  {
329  $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
330  }
331 
332  $GLOBALS['ilLog']->write(__METHOD__.': import mob from dir: '. $importfile);
333 
334  $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
335  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
336  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
337  foreach ($answers as $key => $value)
338  {
339  $answer_obj =& $answers[$key];
340  $answer_obj->setAnswertext(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $answer_obj->getAnswertext()));
341  }
342  foreach ($feedbacks as $ident => $material)
343  {
344  $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
345  }
346  foreach ($feedbacksgeneric as $correctness => $material)
347  {
348  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
349  }
350  }
351  }
352  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
353  foreach ($answers as $key => $value)
354  {
355  $answer_obj =& $answers[$key];
356  $answer_obj->setAnswertext(ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 1));
357  }
358  foreach ($feedbacks as $ident => $material)
359  {
360  $this->object->feedbackOBJ->importSpecificAnswerFeedback(
361  $this->object->getId(), $ident, ilRTE::_replaceMediaObjectImageSrc($material, 1)
362  );
363  }
364  foreach ($feedbacksgeneric as $correctness => $material)
365  {
366  $this->object->feedbackOBJ->importGenericFeedback(
367  $this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)
368  );
369  }
370  $this->object->saveToDb();
371  if (count($item->suggested_solutions))
372  {
373  foreach ($item->suggested_solutions as $suggested_solution)
374  {
375  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
376  }
377  $this->object->saveToDb();
378  }
379  if ($tst_id > 0)
380  {
381  $q_1_id = $this->object->getId();
382  $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
383  $tst_object->questions[$question_counter++] = $question_id;
384  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
385  }
386  else
387  {
388  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
389  }
390  //$ilLog->write(strftime("%D %T") . ": finished import multiple choice question (single response)");
391  }
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:

Field Documentation

◆ $object

assKprimChoiceImport::$object

Definition at line 18 of file class.assKprimChoiceImport.php.


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