ILIAS  trunk Revision v5.2.0beta1-34132-g2d4d73d4a0
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)
 
 QTIMaterialToString (ilQTIMaterial $a_material)
 Reads an QTI material tag and creates a text or XHTML string. More...
 

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...
 
 findSolutionTypeByValue (string $value)
 
 getSuggestedSolutionsRepo ()
 
- Protected Attributes inherited from assQuestionImport
assQuestionSuggestedSolutionsDatabaseRepository $suggestedsolution_repo = null
 

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 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 33 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 37 of file class.assLongMenuImport.php.

References ILIAS\LTI\ToolProvider\$created, $DIC, $id, 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, ILIAS\Repository\object(), and assQuestionImport\QTIMaterialToString().

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

References $id.

Referenced by fromXML().

256  {
257  $id = preg_split('/_/', $ident);
258  return $id[1] - 1;
259  }
$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 35 of file class.assLongMenuImport.php.


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