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 {
48 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
49 {
50 if ($tst_id > 0)
51 {
53 }
54 else
55 {
57 }
58
60 $DIC[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
61
64
65 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
66 $longmenutext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $longmenutext);
67
68 }
69 }
72
73
74 foreach ($item->resprocessing as $resprocessing) {
75 foreach ($resprocessing->respcondition as $respcondition) {
76 $correctness = 1;
77 $conditionvar = $respcondition->getConditionvar();
78 foreach ($conditionvar->order as $order) {
79 switch ($order["field"]) {
80 case "varequal":
81 $equals = $conditionvar->varequal[$order["index"]]->getContent();
82 $gapident = $conditionvar->varequal[$order["index"]]->getRespident();
84 $answers[
$id][] = $equals;
85 break;
86 }
87 }
88 foreach ($respcondition->setvar as $setvar) {
89 if (strcmp($gapident, "") != 0) {
90 if ($setvar->getContent() > 0) {
92 $correct_answers[
$id][0][] = $equals;
93 $correct_answers[
$id][1] = $setvar->getContent();
94 if (is_array($gap_types) && key_exists(
$id, $gap_types)) {
95 $correct_answers[
$id][2] = $gap_types[
$id];
96 }
97 }
98 }
99 }
100 if (count($respcondition->displayfeedback)) {
101 foreach ($respcondition->displayfeedback as $feedbackpointer) {
102 if (strlen($feedbackpointer->getLinkrefid())) {
103 foreach ($item->itemfeedback as $ifb) {
104 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
105
106 if (count($ifb->material)) {
107 foreach ($ifb->material as $material) {
108 $feedbacksgeneric[1] = $material;
109 }
110 }
111 if ((count($ifb->flow_mat) > 0)) {
112 foreach ($ifb->flow_mat as $fmat) {
113 if (count($fmat->material)) {
114 foreach ($fmat->material as $material) {
115 $feedbacksgeneric[1] = $material;
116 }
117 }
118 }
119 }
120 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
121
122 if (count($ifb->material)) {
123 foreach ($ifb->material as $material) {
124 $feedbacksgeneric[0] = $material;
125 }
126 }
127 if ((count($ifb->flow_mat) > 0)) {
128 foreach ($ifb->flow_mat as $fmat) {
129 if (count($fmat->material)) {
130 foreach ($fmat->material as $material) {
131 $feedbacksgeneric[0] = $material;
132 }
133 }
134 }
135 }
136 } else {
137
138 if (count($ifb->material)) {
139 foreach ($ifb->material as $material) {
140 $feedbacks[$ifb->getIdent()] = $material;
141 }
142 }
143 if ((count($ifb->flow_mat) > 0)) {
144 foreach ($ifb->flow_mat as $fmat) {
145 if (count($fmat->material)) {
146 foreach ($fmat->material as $material) {
147 $feedbacks[$ifb->getIdent()] = $material;
148 }
149 }
150 }
151 }
152 }
153 }
154 }
155 }
156 }
157 }
158 }
159
160 $sum = 0;
161 foreach ($correct_answers as
$row) {
163 }
164 $this->object->setAnswers($answers);
165
166 if (count($feedbacks) > 0) {
167 foreach ($feedbacks as $ident => $material) {
168 $m = $this->
object->QTIMaterialToString($material);
169 $feedbacks[$ident] =
$m;
170 }
171 }
172 if (is_array($feedbacksgeneric) && count($feedbacksgeneric) > 0) {
173 foreach ($feedbacksgeneric as $correctness => $material) {
174 $m = $this->
object->QTIMaterialToString($material);
175 $feedbacksgeneric[$correctness] =
$m;
176 }
177 }
178
180 $this->object->setTitle($item->getTitle());
181 $this->object->setNrOfTries($item->getMaxattempts());
182 $this->object->setComment($item->getComment());
183 $this->object->setAuthor($item->getAuthor());
184 $this->
object->setOwner(
$ilUser->getId());
185 $this->object->setObjId($questionpool_id);
186 $this->object->setMinAutoComplete($item->getMetadataEntry("minAutoCompleteLength"));
187 $this->object->setIdenticalscoring((int) $item->getMetadataEntry("identical_scoring"));
188 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
189 $this->object->setCorrectAnswers($correct_answers);
190 $this->object->setPoints($sum);
191
192 $this->object->setAdditionalContentEditingMode(
194 );
195 $this->object->saveToDb();
196
197 if (count($feedbacks) > 0) {
198 foreach ($feedbacks as $ident => $material) {
199 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
200 $this->object->getId(),
201 0,
202 $ident,
204 );
205 }
206 }
207 if (is_array($feedbacksgeneric) && count($feedbacksgeneric) > 0) {
208 foreach ($feedbacksgeneric as $correctness => $material) {
209 $this->object->feedbackOBJ->importGenericFeedback(
210 $this->object->getId(),
211 $correctness,
213 );
214 }
215 }
216 $this->object->saveToDb();
217 if (count($item->suggested_solutions)) {
218 foreach ($item->suggested_solutions as $suggested_solution) {
219 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
220 }
221 $this->object->saveToDb();
222 }
223
224 if ($tst_id > 0) {
225 $q_1_id = $this->object->getId();
226 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
227 $tst_object->questions[$question_counter++] = $question_id;
228 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
229 } else {
230 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
231 }
232 }
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...
if(!array_key_exists('StateId', $_REQUEST)) $id