Creates a question from a QTI file.
36 {
38
39
41 $presentation = $item->getPresentation();
42 $duration = $item->getDuration();
43 $shuffle = 0;
44 $now = getdate();
45 $foundimage = false;
46 $created =
sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
47 $answers = array();
49
50 foreach ($presentation->order as $entry) {
51 switch ($entry["type"]) {
52 case "response":
53 $response = $presentation->response[$entry[
"index"]];
57 } elseif (
$response->getIdent() ==
'OQNP') {
59 } elseif (
$response->getIdent() ==
'OQNT') {
61 } elseif (
$response->getIdent() ==
'OQT') {
63 }
64
66 switch (strtolower(get_class($rendertype))) {
67 case "ilqtirenderchoice":
68 $shuffle = $rendertype->getShuffle();
69 $answerorder = 0;
70 foreach ($rendertype->response_labels as $response_label) {
71 $ident = $response_label->getIdent();
72 $answertext = "";
73 foreach ($response_label->material as $mat) {
74 for (
$m = 0;
$m < $mat->getMaterialCount();
$m++) {
75 $foundmat = $mat->getMaterial(
$m);
76
77 if (strcmp($foundmat["material"]->getLabel(), "answerdepth") == 0) {
78 $answerdepth = $foundmat["material"]->getContent();
79 }
80 if (strcmp($foundmat["type"], "mattext") == 0
81 && strcmp($foundmat["material"]->getLabel(), "answerdepth") != 0) {
82 $answertext .= $foundmat["material"]->getContent();
83 }
84 if (strcmp($foundmat["type"], "matimage") == 0
85 && strcmp($foundmat["material"]->getLabel(), "answerdepth") != 0) {
86 $foundimage = true;
87 $answerimage = array(
88 "imagetype" => $foundmat["material"]->getImageType(),
89 "label" => $foundmat["material"]->getLabel(),
90 "content" => $foundmat["material"]->getContent()
91 );
92 }
93 }
94 }
95 $answers[$answerorder] = array(
96 'ident' => $ident,
97 "answertext" => $answertext,
98 "answerimage" => $answerimage,
99 "points" => 0,
100 "answerorder" => $answerorder,
101 "answerdepth" => $answerdepth,
102 "correctness" => "",
103 "action" => ""
104 );
105 $answerorder++;
106 }
107 break;
108 }
109 break;
110 }
111 }
112 $responses = array();
113 $feedbacksgeneric = array();
114 foreach ($item->resprocessing as $resprocessing) {
115 foreach ($resprocessing->respcondition as $respcondition) {
116 $ident = "";
117 $correctness = 1;
118 $conditionvar = $respcondition->getConditionvar();
119 foreach ($conditionvar->order as $order) {
120 switch ($order["field"]) {
121 case "arr_not":
122 $correctness = 0;
123 break;
124 case "varequal":
125 $ident = $conditionvar->varequal[$order["index"]]->getContent();
126 $orderindex = $conditionvar->varequal[$order["index"]]->getIndex();
127 break;
128 }
129 }
130 foreach ($respcondition->setvar as $setvar) {
131 if (strcmp($ident, "") != 0) {
132 $answers[$ident]["solutionorder"] = $orderindex;
133 $answers[$ident]["action"] = $setvar->getAction();
134 $answers[$ident]["points"] = $setvar->getContent();
135 }
136 }
137 if (count($respcondition->displayfeedback)) {
138 foreach ($respcondition->displayfeedback as $feedbackpointer) {
139 if (strlen($feedbackpointer->getLinkrefid())) {
140 foreach ($item->itemfeedback as $ifb) {
141 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
142
143 if (count($ifb->material)) {
144 foreach ($ifb->material as $material) {
145 $feedbacksgeneric[1] = $material;
146 }
147 }
148 if ((count($ifb->flow_mat) > 0)) {
149 foreach ($ifb->flow_mat as $fmat) {
150 if (count($fmat->material)) {
151 foreach ($fmat->material as $material) {
152 $feedbacksgeneric[1] = $material;
153 }
154 }
155 }
156 }
157 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
158
159 if (count($ifb->material)) {
160 foreach ($ifb->material as $material) {
161 $feedbacksgeneric[0] = $material;
162 }
163 }
164 if ((count($ifb->flow_mat) > 0)) {
165 foreach ($ifb->flow_mat as $fmat) {
166 if (count($fmat->material)) {
167 foreach ($fmat->material as $material) {
168 $feedbacksgeneric[0] = $material;
169 }
170 }
171 }
172 }
173 }
174 }
175 }
176 }
177 }
178 }
179 }
180
182
184 $this->object->setTitle($item->getTitle());
185 $this->object->setNrOfTries($item->getMaxattempts());
186 $this->object->setComment($item->getComment());
187 $this->object->setAuthor($item->getAuthor());
188 $this->object->setOwner($ilUser->getId());
189 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
190 $this->
object->setOrderingType(
$type);
191 $this->object->setObjId($questionpool_id);
192 $this->object->setThumbGeometry($item->getMetadataEntry("thumb_geometry"));
193 $this->object->setElementHeight($item->getMetadataEntry("element_height"));
194 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
195 $this->object->setShuffle($shuffle);
196 $points = 0;
197 $solanswers = array();
198
199 foreach ($answers as $answer) {
200 $solanswers[$answer["solutionorder"]] = $answer;
201 }
202 ksort($solanswers);
203 $position = 0;
204 foreach ($solanswers as $answer) {
205 $points += $answer["points"];
206
208
209 if ($element->isExportIdent($answer['ident'])) {
210 $element->setExportIdent($answer['ident']);
211 } else {
212 $element->setPosition($position++);
213 if (isset($answer['answerdepth'])) {
214 $element->setIndentation($answer['answerdepth']);
215 }
216 }
217
218 if ($this->object->isImageOrderingType()) {
219 $element->setContent($answer["answerimage"]["label"]);
220 } else {
221 $element->setContent($answer["answertext"]);
222 }
223
224 $this->object->getOrderingElementList()->addElement($element);
225 }
226 $points = ($item->getMetadataEntry("points") > 0) ? $item->getMetadataEntry("points") : $points;
227 $this->object->setPoints($points);
228
229 $this->object->setAdditionalContentEditingMode(
231 );
232 $this->object->saveToDb();
233 if (count($item->suggested_solutions)) {
234 foreach ($item->suggested_solutions as $suggested_solution) {
235 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
236 }
237 $this->object->saveToDb();
238 }
239 foreach ($answers as $answer) {
241 include_once "./Services/Utilities/classes/class.ilUtil.php";
242 if (strlen($answer['answerimage']['label']) && strlen($answer['answerimage']['content'])) {
243 $image =&base64_decode($answer["answerimage"]["content"]);
244 $imagepath = $this->object->getImagePath();
245 if (!file_exists($imagepath)) {
247 }
248 $imagepath .= $answer["answerimage"]["label"];
249 $fh = fopen($imagepath,
"wb");
251
252
253
254 } else {
255 $imagefile = fwrite(
$fh, $image);
257 }
258
259 $thumbpath = $imagepath . "." . "thumb.jpg";
261 }
262 }
263 }
264 foreach ($feedbacksgeneric as $correctness => $material) {
265 $m = $this->
object->QTIMaterialToString($material);
266 $feedbacksgeneric[$correctness] =
$m;
267 }
268 $questiontext = $this->object->getQuestion();
269
270
271 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
272 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
273 include_once "./Services/RTE/classes/class.ilRTE.php";
274 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
275 if ($tst_id > 0) {
277 } else {
279 }
280
281 $GLOBALS[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
282
285 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
286 foreach ($this->object->getOrderingElementList() as $element) {
287 $element->setContent(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $element->getContent()));
288 }
289 foreach ($feedbacksgeneric as $correctness => $material) {
290 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
291 }
292 foreach ($itemfeedbacks as $ident => $material) {
293 $itemfeedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
294 }
295 }
296 }
298 foreach ($this->object->getOrderingElementList() as $element) {
300 }
301 foreach ($feedbacksgeneric as $correctness => $material) {
302 $this->object->feedbackOBJ->importGenericFeedback(
303 $this->object->getId(),
304 $correctness,
306 );
307 }
308 foreach ($itemfeedbacks as $ident => $material) {
310
311 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
312 $this->object->getId(),
315 );
316 }
317 $this->object->saveToDb();
318 if ($tst_id > 0) {
319 $this->object->setObjId($tst_id);
320 $tstQid = $this->object->getId();
321 $qplQid = $this->object->duplicate(true, null, null, null, $questionpool_id);
324 $tst_object->questions[$question_counter++] = $tstQid;
325 $import_mapping[$item->getIdent()] = array("pool" => $qplQid, "test" => $tstQid);
326 } else {
327 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
328 }
329 }
sprintf('%.4f', $callTime)
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
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)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')
static resetOriginalId($questionId)
static saveOriginalId($questionId, $originalId)
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 convertImage( $a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
const OQ_PICTURES
Ordering question constants.