ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator 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 (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)
 
- 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

Definition at line 19 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 23 of file class.assLongMenuImport.php.

References $DIC, $id, ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), assQuestionImport\addGeneralMetadata(), 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().

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

◆ getIdFromGapIdent()

assLongMenuImport::getIdFromGapIdent (   $ident)
private

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

References $id.

Referenced by fromXML().

216  {
217  $id = preg_split('/_/', $ident);
218  return $id[1] - 1;
219  }
$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 21 of file class.assLongMenuImport.php.


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