ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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 (string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
 
- Public Member Functions inherited from assQuestionImport
 getQuestionId ()
 
 getFeedbackGeneric ($item)
 
 fromXML (string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
 
 importSuggestedSolutions (int $question_id, array $solution_from_import)
 
 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)
 
 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 ()
 
 deduceThumbSizeFromImportValue (?int $size)
 
 addQuestionToParentObjectAndBuildMappingEntry (int $questionpool_id, ?int $tst_id, int &$question_counter, ?ilObjTest &$tst_object)
 
- Protected Attributes inherited from assQuestionImport
SuggestedSolutionsDatabaseRepository $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 34 of file class.assLongMenuImport.php.

Member Function Documentation

◆ fromXML()

assLongMenuImport::fromXML ( string  $importdirectory,
int  $user_id,
ilQTIItem  $item,
int  $questionpool_id,
?int  $tst_id,
?ilObject $tst_object,
int &  $question_counter,
array  $import_mapping 
)

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

References $DIC, $id, ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), assQuestionImport\addGeneralMetadata(), assQuestionImport\addQuestionToParentObjectAndBuildMappingEntry(), ilSession\clear(), assQuestionImport\fetchAdditionalContentEditingModeInformation(), ilSession\get(), ilQTIItem\getAuthor(), ilQTIItem\getComment(), ilQTIItem\getIdent(), getIdFromGapIdent(), ilQTIItem\getMaxattempts(), ilQTIItem\getMetadataEntry(), ilQTIItem\getPresentation(), ilQTIItem\getTitle(), IL_INST_ID, assQuestionImport\importSuggestedSolutions(), assLongMenu\MIN_LENGTH_AUTOCOMPLETE, ILIAS\Repository\object(), and assQuestionImport\QTIMaterialToString().

47  : array {
48  ilSession::clear('import_mob_xhtml');
49 
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  $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob["uri"];
76 
77  global $DIC; /* @var ILIAS\DI\Container $DIC */
78  $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
79 
80  $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
81  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
82 
83  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
84  $longmenutext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $longmenutext);
85  }
86  }
87  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
88  $this->object->setLongMenuTextValue(ilRTE::_replaceMediaObjectImageSrc($longmenutext, 1));
89  // fau.
90 
91  foreach ($item->resprocessing as $resprocessing) {
92  foreach ($resprocessing->respcondition as $respcondition) {
93  $correctness = 1;
94  $conditionvar = $respcondition->getConditionvar();
95  foreach ($conditionvar->order as $order) {
96  switch ($order['field']) {
97  case 'varequal':
98  $equals = $conditionvar->varequal[$order["index"]]->getContent();
99  $gapident = $conditionvar->varequal[$order["index"]]->getRespident();
100  $id = $this->getIdFromGapIdent($gapident);
101  if (!isset($answers[$id]) || !in_array($equals, $answers[$id])) {
102  $answers[$id][] = $equals;
103  }
104  break;
105  }
106  }
107  foreach ($respcondition->setvar as $setvar) {
108  if ($gapident !== '') {
109  if ($setvar->getContent() > 0) {
110  $id = $this->getIdFromGapIdent($gapident);
111  $correct_answers[$id][0][] = $equals;
112  $correct_answers[$id][1] = $setvar->getContent();
113  if (is_array($gap_types) && key_exists($id, $gap_types)) {
114  $correct_answers[$id][2] = $gap_types[$id];
115  }
116  }
117  }
118  }
119  foreach ($respcondition->displayfeedback as $feedbackpointer) {
120  if (strlen($feedbackpointer->getLinkrefid())) {
121  foreach ($item->itemfeedback as $ifb) {
122  if ($ifb->getIdent() === 'response_allcorrect') {
123  foreach ($ifb->material as $material) {
124  $feedbacksgeneric[1] = $material;
125  }
126  foreach ($ifb->flow_mat as $fmat) {
127  if (count($fmat->material)) {
128  foreach ($fmat->material as $material) {
129  $feedbacksgeneric[1] = $material;
130  }
131  }
132  }
133  } elseif ($ifb->getIdent() === 'response_onenotcorrect') {
134  foreach ($ifb->material as $material) {
135  $feedbacksgeneric[0] = $material;
136  }
137  foreach ($ifb->flow_mat as $fmat) {
138  if (count($fmat->material)) {
139  foreach ($fmat->material as $material) {
140  $feedbacksgeneric[0] = $material;
141  }
142  }
143  }
144  } else {
145  foreach ($ifb->material as $material) {
146  $feedbacks[$ifb->getIdent()] = $material;
147  }
148  foreach ($ifb->flow_mat as $fmat) {
149  if (count($fmat->material)) {
150  foreach ($fmat->material as $material) {
151  $feedbacks[$ifb->getIdent()] = $material;
152  }
153  }
154  }
155  }
156  }
157  }
158  }
159  }
160  }
161 
162  $sum = 0;
163  foreach ($correct_answers as $row) {
164  $sum += $row[1];
165  }
166  $this->object->setAnswers($answers);
167  // handle the import of media objects in XHTML code
168  if (isset($feedbacks) && count($feedbacks) > 0) {
169  foreach ($feedbacks as $ident => $material) {
170  $m = $this->QTIMaterialToString($material);
171  $feedbacks[$ident] = $m;
172  }
173  }
174  if (isset($feedbacksgeneric) && is_array($feedbacksgeneric) && count($feedbacksgeneric) > 0) {
175  foreach ($feedbacksgeneric as $correctness => $material) {
176  $m = $this->QTIMaterialToString($material);
177  $feedbacksgeneric[$correctness] = $m;
178  }
179  }
180 
181  $this->addGeneralMetadata($item);
182  $this->object->setTitle($item->getTitle());
183  $this->object->setNrOfTries((int) $item->getMaxattempts());
184  $this->object->setComment($item->getComment());
185  $this->object->setAuthor($item->getAuthor());
186  $this->object->setOwner($user_id);
187  $this->object->setObjId($questionpool_id);
188  $this->object->setMinAutoComplete((int) ($item->getMetadataEntry('minAutoCompleteLength') ?? assLongMenu::MIN_LENGTH_AUTOCOMPLETE));
189  $this->object->setIdenticalscoring((int) $item->getMetadataEntry('identical_scoring'));
190  $this->object->setCorrectAnswers($correct_answers);
191  $this->object->setPoints($sum);
192  // additional content editing mode information
193  $this->object->setAdditionalContentEditingMode(
195  );
196  $this->object->saveToDb();
197  $this->importSuggestedSolutions($this->object->getId(), $item->suggested_solutions);
198  if (isset($feedbacks) && count($feedbacks) > 0) {
199  foreach ($feedbacks as $ident => $material) {
200  $this->object->feedbackOBJ->importSpecificAnswerFeedback(
201  $this->object->getId(),
202  0,
203  $ident,
205  );
206  }
207  }
208  if (isset($feedbacksgeneric) && is_array($feedbacksgeneric) && count($feedbacksgeneric) > 0) {
209  foreach ($feedbacksgeneric as $correctness => $material) {
210  $this->object->feedbackOBJ->importGenericFeedback(
211  $this->object->getId(),
212  $correctness,
214  );
215  }
216  }
217  $this->object->saveToDb();
218 
219  $import_mapping[$item->getIdent()] = $this->addQuestionToParentObjectAndBuildMappingEntry(
220  $questionpool_id,
221  $tst_id,
222  $question_counter,
223  $tst_object
224  );
225  return $import_mapping;
226  }
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.
addQuestionToParentObjectAndBuildMappingEntry(int $questionpool_id, ?int $tst_id, int &$question_counter, ?ilObjTest &$tst_object)
getMetadataEntry(string $a_label)
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.
const MIN_LENGTH_AUTOCOMPLETE
global $DIC
Definition: shib_login.php:25
importSuggestedSolutions(int $question_id, array $solution_from_import)
static _saveTempFileAsMediaObject(string $name, string $tmp_name, bool $upload=true)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
static clear(string $a_var)
+ Here is the call graph for this function:

◆ getIdFromGapIdent()

assLongMenuImport::getIdFromGapIdent (   $ident)
private

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

References $id.

Referenced by fromXML().

229  {
230  $id = preg_split('/_/', $ident);
231  return $id[1] - 1;
232  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
+ Here is the caller graph for this function:

Field Documentation

◆ $object

assLongMenuImport::$object

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


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