Creates a question from a QTI file.
10 {
13
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
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) {
50 } else {
52 }
53
55 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
56
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 }
66
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();
78 $answers[$id][] = $equals;
79 break;
80 }
81 }
82 foreach ($respcondition->setvar as $setvar) {
83 if (strcmp($gapident, "") != 0) {
84 if ($setvar->getContent() > 0) {
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
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
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
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
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
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
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 }
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 _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...