ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
assLongMenuImport Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for assLongMenuImport:
+ Collaboration diagram for assLongMenuImport:

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...
 
 getQuestionId ()
 
 getFeedbackGeneric ($item)
 
 fromXML (&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping)
 Creates a question from a QTI file. More...
 
 importSuggestedSolution (int $question_id, string $value="", int $subquestion_index=0)
 

Data Fields

 $object
 
- Data Fields inherited from assQuestionImport
 $object
 

Private Member Functions

 getIdFromGapIdent ($ident)
 

Additional Inherited Members

- Protected Member Functions inherited from assQuestionImport
 fetchIndexFromFeedbackIdent ($feedbackIdent, $prefix='response_')
 
 getFeedbackAnswerSpecific (ilQTIItem $item, $prefix='response_')
 
 addGeneralMetadata (ilQTIItem $item)
 
 fetchLifecycle (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_RTE when no or invalid information is given More...
 
 deduceThumbSizeFromImportValue (?int $size)
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

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

Member Function Documentation

◆ fromXML()

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

Definition at line 22 of file class.assLongMenuImport.php.

References ILIAS\LTI\ToolProvider\$created, $DIC, $id, $ilUser, ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), assQuestionImport\addGeneralMetadata(), ilSession\clear(), assQuestionImport\fetchAdditionalContentEditingModeInformation(), ilSession\get(), ILIAS\UI\Implementation\Component\Input\ViewControl\getContent(), getIdFromGapIdent(), assQuestionImport\getQplImportArchivDirectory(), assQuestionImport\getTstImportArchivDirectory(), IL_INST_ID, and ILIAS\Repository\object().

22  : array
23  {
24  global $DIC;
25  $ilUser = $DIC['ilUser'];
26 
27  ilSession::clear('import_mob_xhtml');
28 
29  $presentation = $item->getPresentation();
30  $questiontext = array();
31  $seperate_question_field = $item->getMetadataEntry("question");
32  $clozetext = array();
33  $now = getdate();
34  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
35  $answers = array();
36  $correct_answers = array();
37  $presentation = $item->getPresentation();
38  $gap_types = json_decode($item->getMetadataEntry("gapTypes"));
39  foreach ($presentation->order as $entry) {
40  switch ($entry["type"]) {
41  case "material":
42 
43  $material = $presentation->material[$entry["index"]];
44  if (preg_match('/\[Longmenu \d\]/', $this->object->QTIMaterialToString($material))) {
45  $this->object->setLongMenuTextValue($this->object->QTIMaterialToString($material));
46  } else {
47  $this->object->setQuestion($this->object->QTIMaterialToString($material));
48  }
49 
50 
51  break;
52  }
53  }
54 
55  // fixLongMenuImageImport - process images in question and long menu text when question is imported
56  $questiontext = $this->object->getQuestion();
57  $longmenutext = $this->object->getLongMenuTextValue();
58  if (is_array(ilSession::get("import_mob_xhtml"))) {
59  foreach (ilSession::get("import_mob_xhtml") as $mob) {
60  if ($tst_id > 0) {
61  $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
62  } else {
63  $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
64  }
65 
66  global $DIC; /* @var ILIAS\DI\Container $DIC */
67  $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
68 
69  $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
70  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
71 
72  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
73  $longmenutext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $longmenutext);
74  }
75  }
76  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
77  $this->object->setLongMenuTextValue(ilRTE::_replaceMediaObjectImageSrc($longmenutext, 1));
78  // fau.
79 
80  foreach ($item->resprocessing as $resprocessing) {
81  foreach ($resprocessing->respcondition as $respcondition) {
82  $correctness = 1;
83  $conditionvar = $respcondition->getConditionvar();
84  foreach ($conditionvar->order as $order) {
85  switch ($order["field"]) {
86  case "varequal":
87  $equals = $conditionvar->varequal[$order["index"]]->getContent();
88  $gapident = $conditionvar->varequal[$order["index"]]->getRespident();
89  $id = $this->getIdFromGapIdent($gapident);
90  $answers[$id][] = $equals;
91  break;
92  }
93  }
94  foreach ($respcondition->setvar as $setvar) {
95  if (strcmp($gapident, "") != 0) {
96  if ($setvar->getContent() > 0) {
97  $id = $this->getIdFromGapIdent($gapident);
98  $correct_answers[$id][0][] = $equals;
99  $correct_answers[$id][1] = $setvar->getContent();
100  if (is_array($gap_types) && key_exists($id, $gap_types)) {
101  $correct_answers[$id][2] = $gap_types[$id];
102  }
103  }
104  }
105  }
106  if (count($respcondition->displayfeedback)) {
107  foreach ($respcondition->displayfeedback as $feedbackpointer) {
108  if (strlen($feedbackpointer->getLinkrefid())) {
109  foreach ($item->itemfeedback as $ifb) {
110  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
111  // found a feedback for the identifier
112  if (count($ifb->material)) {
113  foreach ($ifb->material as $material) {
114  $feedbacksgeneric[1] = $material;
115  }
116  }
117  if ((count($ifb->flow_mat) > 0)) {
118  foreach ($ifb->flow_mat as $fmat) {
119  if (count($fmat->material)) {
120  foreach ($fmat->material as $material) {
121  $feedbacksgeneric[1] = $material;
122  }
123  }
124  }
125  }
126  } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
127  // found a feedback for the identifier
128  if (count($ifb->material)) {
129  foreach ($ifb->material as $material) {
130  $feedbacksgeneric[0] = $material;
131  }
132  }
133  if ((count($ifb->flow_mat) > 0)) {
134  foreach ($ifb->flow_mat as $fmat) {
135  if (count($fmat->material)) {
136  foreach ($fmat->material as $material) {
137  $feedbacksgeneric[0] = $material;
138  }
139  }
140  }
141  }
142  } else {
143  // found a feedback for the identifier
144  if (count($ifb->material)) {
145  foreach ($ifb->material as $material) {
146  $feedbacks[$ifb->getIdent()] = $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  $feedbacks[$ifb->getIdent()] = $material;
154  }
155  }
156  }
157  }
158  }
159  }
160  }
161  }
162  }
163  }
164  }
165 
166  $sum = 0;
167  foreach ($correct_answers as $row) {
168  $sum += $row[1];
169  }
170  $this->object->setAnswers($answers);
171  // handle the import of media objects in XHTML code
172  if (isset($feedbacks) && count($feedbacks) > 0) {
173  foreach ($feedbacks as $ident => $material) {
174  $m = $this->object->QTIMaterialToString($material);
175  $feedbacks[$ident] = $m;
176  }
177  }
178  if (isset($feedbacksgeneric) && is_array($feedbacksgeneric) && count($feedbacksgeneric) > 0) {
179  foreach ($feedbacksgeneric as $correctness => $material) {
180  $m = $this->object->QTIMaterialToString($material);
181  $feedbacksgeneric[$correctness] = $m;
182  }
183  }
184 
185  $this->addGeneralMetadata($item);
186  $this->object->setTitle($item->getTitle());
187  $this->object->setNrOfTries((int)$item->getMaxattempts());
188  $this->object->setComment($item->getComment());
189  $this->object->setAuthor($item->getAuthor());
190  $this->object->setOwner($ilUser->getId());
191  $this->object->setObjId($questionpool_id);
192  $this->object->setMinAutoComplete($item->getMetadataEntry("minAutoCompleteLength"));
193  $this->object->setIdenticalscoring((int) $item->getMetadataEntry("identical_scoring"));
194  $this->object->setCorrectAnswers($correct_answers);
195  $this->object->setPoints($sum);
196  // additional content editing mode information
197  $this->object->setAdditionalContentEditingMode(
199  );
200  $this->object->saveToDb();
201 
202  if (isset($feedbacks) && count($feedbacks) > 0) {
203  foreach ($feedbacks as $ident => $material) {
204  $this->object->feedbackOBJ->importSpecificAnswerFeedback(
205  $this->object->getId(),
206  0,
207  $ident,
209  );
210  }
211  }
212  if (isset($feedbacksgeneric) && is_array($feedbacksgeneric) && count($feedbacksgeneric) > 0) {
213  foreach ($feedbacksgeneric as $correctness => $material) {
214  $this->object->feedbackOBJ->importGenericFeedback(
215  $this->object->getId(),
216  $correctness,
218  );
219  }
220  }
221  $this->object->saveToDb();
222  if (count($item->suggested_solutions)) {
223  foreach ($item->suggested_solutions as $suggested_solution) {
224  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
225  }
226  $this->object->saveToDb();
227  }
228 
229  if ($tst_id > 0) {
230  $q_1_id = $this->object->getId();
231  $question_id = $this->object->duplicate(true, "", "", "", $tst_id);
232  $tst_object->questions[$question_counter++] = $question_id;
233  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
234  } else {
235  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
236  }
237  return $import_mapping;
238  }
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static get(string $a_var)
addGeneralMetadata(ilQTIItem $item)
const IL_INST_ID
Definition: constants.php:40
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
static _saveUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Save usage of mob within another container (e.g.
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir) ...
global $DIC
Definition: feed.php:28
static _saveTempFileAsMediaObject(string $name, string $tmp_name, bool $upload=true)
Create new media object and update page in db and return new media object.
$ilUser
Definition: imgupload.php:34
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
static clear(string $a_var)
int $created
Timestamp for when the object was created.
Definition: System.php:151
+ Here is the call graph for this function:

◆ getIdFromGapIdent()

assLongMenuImport::getIdFromGapIdent (   $ident)
private

Definition at line 240 of file class.assLongMenuImport.php.

References $id.

Referenced by fromXML().

241  {
242  $id = preg_split('/_/', $ident);
243  return $id[1] - 1;
244  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the caller graph for this function:

Field Documentation

◆ $object

assLongMenuImport::$object

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


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