Creates a question from a QTI file.
31 {
34
35
37 $presentation = $item->getPresentation();
38 $duration = $item->getDuration();
39 $shuffle = 0;
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 $answers = array();
43 foreach ($presentation->order as $entry) {
44 switch ($entry["type"]) {
45 case "response":
46 $response = $presentation->response[$entry[
"index"]];
48 switch (strtolower(get_class(
$response->getRenderType()))) {
49 case "ilqtirenderchoice":
50 $shuffle = $rendertype->getShuffle();
51 $answerorder = 0;
52 $foundimage = false;
53 foreach ($rendertype->response_labels as $response_label) {
54 $ident = $response_label->getIdent();
55 $answertext = "";
56 $answerimage = array();
57 foreach ($response_label->material as $mat) {
58 $embedded = false;
59 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
60 $foundmat = $mat->getMaterial($m);
61 if (strcmp($foundmat["type"], "mattext") == 0) {
62 }
63 if (strcmp($foundmat["type"], "matimage") == 0) {
64 if (strlen($foundmat["material"]->getEmbedded())) {
65 $embedded = true;
66 }
67 }
68 }
69 if ($embedded) {
70 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
71 $foundmat = $mat->getMaterial($m);
72 if (strcmp($foundmat["type"], "mattext") == 0) {
73 $answertext .= $foundmat["material"]->getContent();
74 }
75 if (strcmp($foundmat["type"], "matimage") == 0) {
76 $foundimage = true;
77 $answerimage = array(
78 "imagetype" => $foundmat["material"]->getImageType(),
79 "label" => $foundmat["material"]->getLabel(),
80 "content" => $foundmat["material"]->getContent()
81 );
82 }
83 }
84 } else {
85 $answertext = $this->object->QTIMaterialToString($mat);
86 }
87 }
88 $answers[$ident] = array(
89 "answertext" => $answertext,
90 "imagefile" => $answerimage,
91 "points" => 0,
92 "answerorder" => $answerorder++,
93 "points_unchecked" => 0,
94 "action" => ""
95 );
96 }
97 break;
98 }
99 break;
100 }
101 }
102 $responses = array();
103 $feedbacks = array();
104 $feedbacksgeneric = array();
105 foreach ($item->resprocessing as $resprocessing) {
106 foreach ($resprocessing->respcondition as $respcondition) {
107 $ident = "";
108 $correctness = 1;
109 $conditionvar = $respcondition->getConditionvar();
110 foreach ($conditionvar->order as $order) {
111 switch ($order["field"]) {
112 case "arr_not":
113 $correctness = 0;
114 break;
115 case "varequal":
116 $ident = $conditionvar->varequal[$order["index"]]->getContent();
117 break;
118 }
119 }
120 foreach ($respcondition->setvar as $setvar) {
121 if (strcmp($ident, "") != 0) {
122 if ($correctness) {
123 $answers[$ident]["action"] = $setvar->getAction();
124 $answers[$ident]["points"] = $setvar->getContent();
125 if (count($respcondition->displayfeedback)) {
126 foreach ($respcondition->displayfeedback as $feedbackpointer) {
127 if (strlen($feedbackpointer->getLinkrefid())) {
128 foreach ($item->itemfeedback as $ifb) {
129 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
130
131 if (count($ifb->material)) {
132 foreach ($ifb->material as $material) {
133 $feedbacksgeneric[1] = $material;
134 }
135 }
136 if ((count($ifb->flow_mat) > 0)) {
137 foreach ($ifb->flow_mat as $fmat) {
138 if (count($fmat->material)) {
139 foreach ($fmat->material as $material) {
140 $feedbacksgeneric[1] = $material;
141 }
142 }
143 }
144 }
145 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
146
147 if (count($ifb->material)) {
148 foreach ($ifb->material as $material) {
149 $feedbacksgeneric[0] = $material;
150 }
151 }
152 if ((count($ifb->flow_mat) > 0)) {
153 foreach ($ifb->flow_mat as $fmat) {
154 if (count($fmat->material)) {
155 foreach ($fmat->material as $material) {
156 $feedbacksgeneric[0] = $material;
157 }
158 }
159 }
160 }
161 }
162 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
163
164 if (count($ifb->material)) {
165 foreach ($ifb->material as $material) {
166 $feedbacks[$ident] = $material;
167 }
168 }
169 if ((count($ifb->flow_mat) > 0)) {
170 foreach ($ifb->flow_mat as $fmat) {
171 if (count($fmat->material)) {
172 foreach ($fmat->material as $material) {
173 $feedbacks[$ident] = $material;
174 }
175 }
176 }
177 }
178 }
179 }
180 }
181 }
182 }
183 } else {
184 $answers[$ident]["action"] = $setvar->getAction();
185 $answers[$ident]["points_unchecked"] = $setvar->getContent();
186 }
187 }
188 }
189 }
190 }
192 $this->object->setTitle($item->getTitle());
193 $this->object->setNrOfTries($item->getMaxattempts());
194 $this->object->setComment($item->getComment());
195 $this->object->setAuthor($item->getAuthor());
196 $this->
object->setOwner(
$ilUser->getId());
197 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
198 $this->object->setObjId($questionpool_id);
199 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
200 $this->object->setShuffle($shuffle);
201 $this->object->setThumbSize($item->getMetadataEntry("thumb_size"));
202 foreach ($answers as $answer) {
203 if ($item->getMetadataEntry('singleline') || (is_array($answer["imagefile"]) && count($answer["imagefile"]) > 0)) {
204 $this->object->isSingleline = true;
205 }
206 $this->object->addAnswer($answer["answertext"], $answer["points"], $answer["answerorder"], $answer["imagefile"]["label"]);
207 }
208
209 $this->object->setAdditionalContentEditingMode(
211 );
212 $this->object->saveToDb();
213 foreach ($answers as $answer) {
214 if (is_array($answer["imagefile"]) && (count($answer["imagefile"]) > 0)) {
215 $image = &base64_decode($answer["imagefile"]["content"]);
216 $imagepath = $this->object->getImagePath();
217 include_once "./Services/Utilities/classes/class.ilUtil.php";
218 if (!file_exists($imagepath)) {
220 }
221 $imagepath .= $answer["imagefile"]["label"];
222 $fh = fopen($imagepath, "wb");
223 if ($fh == false) {
224 } else {
225 $imagefile = fwrite($fh, $image);
226 fclose($fh);
227 }
228 }
229 }
230
231 $feedbackSetting = $item->getMetadataEntry('feedback_setting');
232 if (!is_null($feedbackSetting)) {
233 $this->object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting);
234 }
235
236 foreach ($feedbacks as $ident => $material) {
237 $m = $this->object->QTIMaterialToString($material);
238 $feedbacks[$ident] = $m;
239 }
240 foreach ($feedbacksgeneric as $correctness => $material) {
241 $m = $this->object->QTIMaterialToString($material);
242 $feedbacksgeneric[$correctness] = $m;
243 }
244
245 $questiontext = $this->object->getQuestion();
246 $answers = &$this->object->getAnswers();
247 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
248 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
249 include_once "./Services/RTE/classes/class.ilRTE.php";
250 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
251 if ($tst_id > 0) {
253 } else {
255 }
256
258 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
259
262 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
263 foreach ($answers as $key => $value) {
264 $answer_obj = $answers[$key];
265 $answer_obj->setAnswertext(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $answer_obj->getAnswertext()));
266 }
267 foreach ($feedbacks as $ident => $material) {
268 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
269 }
270 foreach ($feedbacksgeneric as $correctness => $material) {
271 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
272 }
273 }
274 }
276 foreach ($answers as $key => $value) {
277 $answer_obj = &$answers[$key];
279 }
280 foreach ($feedbacks as $ident => $material) {
281 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
282 $this->object->getId(),
283 0,
284 $ident,
286 );
287 }
288 foreach ($feedbacksgeneric as $correctness => $material) {
289 $this->object->feedbackOBJ->importGenericFeedback(
290 $this->object->getId(),
291 $correctness,
293 );
294 }
295 $this->object->saveToDb();
296 if (count($item->suggested_solutions)) {
297 foreach ($item->suggested_solutions as $suggested_solution) {
298 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
299 }
300 $this->object->saveToDb();
301 }
302 if ($tst_id > 0) {
303 $q_1_id = $this->object->getId();
304 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
305 $tst_object->questions[$question_counter++] = $question_id;
306 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
307 } else {
308 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
309 }
310 }
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...
static makeDirParents($a_dir)
Create a new directory and all parent directories.