Creates a question from a QTI file.
31 {
33
34
36 $presentation = $item->getPresentation();
37 $duration = $item->getDuration();
38 $shuffle = 0;
39 $idents = array();
40 $now = getdate();
41 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
42 $gaps = array();
43 foreach ($presentation->order as $entry)
44 {
45 switch ($entry["type"])
46 {
47 case "response":
48 $response = $presentation->response[$entry["index"]];
50 {
51 array_push($idents, $response->getIdent());
52 }
53 break;
54 }
55 }
56 $responses = array();
57 $feedbacksgeneric = array();
58 foreach ($item->resprocessing as $resprocessing)
59 {
60 foreach ($resprocessing->respcondition as $respcondition)
61 {
62 $ident = "";
63 $correctness = 1;
64 $conditionvar = $respcondition->getConditionvar();
65 foreach ($conditionvar->order as $order)
66 {
67 switch ($order["field"])
68 {
69 case "varsubset":
70 $respident = $conditionvar->varsubset[$order["index"]]->getRespident();
71 $content = $conditionvar->varsubset[$order["index"]]->getContent();
72 if (!is_array($responses[$respident])) $responses[$respident] = array();
73 $vars = split(",", $content);
74 foreach ($vars as $var)
75 {
76 array_push($responses[$respident], array("solution" => $var, "points" => ""));
77 }
78 break;
79 }
80 }
81 foreach ($respcondition->setvar as $setvar)
82 {
83 if ((strcmp($setvar->getVarname(),
"matches") == 0) && ($setvar->getAction() ==
ACTION_ADD))
84 {
85 foreach ($responses[$respident] as $idx => $solutionarray)
86 {
87 if (strlen($solutionarray["points"] == 0))
88 {
89 $responses[$respident][$idx]["points"] = $setvar->getContent();
90 }
91 }
92 }
93 }
94 foreach ($resprocessing->respcondition as $respcondition)
95 {
96 foreach ($respcondition->displayfeedback as $feedbackpointer)
97 {
98 if (strlen($feedbackpointer->getLinkrefid()))
99 {
100 foreach ($item->itemfeedback as $ifb)
101 {
102 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0)
103 {
104
105 if (count($ifb->material))
106 {
107 foreach ($ifb->material as $material)
108 {
109 $feedbacksgeneric[1] = $material;
110 }
111 }
112 if ((count($ifb->flow_mat) > 0))
113 {
114 foreach ($ifb->flow_mat as $fmat)
115 {
116 if (count($fmat->material))
117 {
118 foreach ($fmat->material as $material)
119 {
120 $feedbacksgeneric[1] = $material;
121 }
122 }
123 }
124 }
125 }
126 else if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0)
127 {
128
129 if (count($ifb->material))
130 {
131 foreach ($ifb->material as $material)
132 {
133 $feedbacksgeneric[0] = $material;
134 }
135 }
136 if ((count($ifb->flow_mat) > 0))
137 {
138 foreach ($ifb->flow_mat as $fmat)
139 {
140 if (count($fmat->material))
141 {
142 foreach ($fmat->material as $material)
143 {
144 $feedbacksgeneric[0] = $material;
145 }
146 }
147 }
148 }
149 }
150 }
151 }
152 }
153 }
154 }
155 }
157 $this->object->setTitle($item->getTitle());
158 $this->object->setNrOfTries($item->getMaxattempts());
159 $this->object->setComment($item->getComment());
160 $this->object->setAuthor($item->getAuthor());
161 $this->object->setOwner($ilUser->getId());
162 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
163 $this->object->setObjId($questionpool_id);
164 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
165 $textrating = $item->getMetadataEntry("textrating");
166 if (strlen($textrating) == 0) $textrating = "ci";
167 $this->object->setTextRating($textrating);
168 $this->object->setCorrectAnswers($item->getMetadataEntry("correctanswers"));
169 $response = current($responses);
170 $counter = 0;
171 if (is_array($response))
172 {
173 foreach ($response as $answer)
174 {
175 $this->object->addAnswer($answer["solution"], $answer["points"], $counter);
176 $counter++;
177 }
178 }
179
180 $this->object->setAdditionalContentEditingMode(
182 );
183 $this->object->saveToDb();
184 if (count($item->suggested_solutions))
185 {
186 foreach ($item->suggested_solutions as $suggested_solution)
187 {
188 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
189 }
190 $this->object->saveToDb();
191 }
192 foreach ($feedbacksgeneric as $correctness => $material)
193 {
194 $m = $this->object->QTIMaterialToString($material);
195 $feedbacksgeneric[$correctness] = $m;
196 }
197
198 $questiontext = $this->object->getQuestion();
199 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
200 {
201 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
202 include_once "./Services/RTE/classes/class.ilRTE.php";
203 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
204 {
205 if ($tst_id > 0)
206 {
208 }
209 else
210 {
212 }
213
214 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
215
218 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
219 foreach ($feedbacksgeneric as $correctness => $material)
220 {
221 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
222 }
223 }
224 }
226 foreach ($feedbacksgeneric as $correctness => $material)
227 {
228 $this->object->feedbackOBJ->importGenericFeedback(
230 );
231 }
232 $this->object->saveToDb();
233 if ($tst_id > 0)
234 {
235 $q_1_id = $this->object->getId();
236 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
237 $tst_object->questions[$question_counter++] = $question_id;
238 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
239 }
240 else
241 {
242 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
243 }
244 }
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...
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.