ILIAS  release_7 Revision v7.30-3-g800a261c036
assLongMenuImport Class Reference
+ Inheritance diagram for assLongMenuImport:
+ Collaboration diagram for assLongMenuImport:

Public Member Functions

 fromXML (&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 Creates a question from a QTI file. More...
 
- 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...
 

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...
 

Detailed Description

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

Member Function Documentation

◆ fromXML()

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

Creates a question from a QTI file.

Receives parameters from a QTI parser and creates a valid ILIAS question object

Parameters
object$itemThe QTI item object
integer$questionpool_idThe id of the parent questionpool
integer$tst_idThe id of the parent test if the question is part of a test
object$tst_objectA reference to the parent test object
integer$question_counterA reference to a question counter to count the questions of an imported question pool
array$import_mappingAn array containing references to included ILIAS objects @access public

Reimplemented from assQuestionImport.

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

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

References $_SESSION, $DIC, $ilUser, ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), assQuestionImport\addGeneralMetadata(), assQuestionImport\fetchAdditionalContentEditingModeInformation(), getIdFromGapIdent(), assQuestionImport\getQplImportArchivDirectory(), assQuestionImport\getTstImportArchivDirectory(), and IL_INST_ID.

+ Here is the call graph for this function:

◆ getIdFromGapIdent()

assLongMenuImport::getIdFromGapIdent (   $ident)
private

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

231 {
232 $id = preg_split('/_/', $ident);
233 return $id[1] - 1;
234 }

Referenced by fromXML().

+ Here is the caller graph for this function:

Field Documentation

◆ $object

assLongMenuImport::$object

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


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