Creates a question from a QTI file.
36 {
39
40
42 $presentation = $item->getPresentation();
43 $duration = $item->getDuration();
44 $shuffle = 0;
45 $now = getdate();
46 $foundimage = false;
47 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
48 $answers = array();
50
51 foreach ($presentation->order as $entry) {
52 switch ($entry["type"]) {
53 case "response":
54 $response = $presentation->response[$entry[
"index"]];
58 } elseif (
$response->getIdent() ==
'OQNP') {
60 } elseif (
$response->getIdent() ==
'OQNT') {
62 } elseif (
$response->getIdent() ==
'OQT') {
64 }
65
67 switch (strtolower(get_class($rendertype))) {
68 case "ilqtirenderchoice":
69 $shuffle = $rendertype->getShuffle();
70 $answerorder = 0;
71 foreach ($rendertype->response_labels as $response_label) {
72 $ident = $response_label->getIdent();
73 $answertext = "";
74 foreach ($response_label->material as $mat) {
75 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
76 $foundmat = $mat->getMaterial($m);
77
78 if (strcmp($foundmat["material"]->getLabel(), "answerdepth") == 0) {
79 $answerdepth = $foundmat["material"]->getContent();
80 }
81 if (strcmp($foundmat["type"], "mattext") == 0
82 && strcmp($foundmat["material"]->getLabel(), "answerdepth") != 0) {
83 $answertext .= $foundmat["material"]->getContent();
84 }
85 if (strcmp($foundmat["type"], "matimage") == 0
86 && strcmp($foundmat["material"]->getLabel(), "answerdepth") != 0) {
87 $foundimage = true;
88 $answerimage = array(
89 "imagetype" => $foundmat["material"]->getImageType(),
90 "label" => $foundmat["material"]->getLabel(),
91 "content" => $foundmat["material"]->getContent()
92 );
93 }
94 }
95 }
96 $answers[$answerorder] = array(
97 'ident' => $ident,
98 "answertext" => $answertext,
99 "answerimage" => $answerimage,
100 "points" => 0,
101 "answerorder" => $answerorder,
102 "answerdepth" => $answerdepth,
103 "correctness" => "",
104 "action" => ""
105 );
106 $answerorder++;
107 }
108 break;
109 }
110 break;
111 }
112 }
113
114 $feedbacksgeneric = array();
115 foreach ($item->resprocessing as $resprocessing) {
116 foreach ($resprocessing->respcondition as $respcondition) {
117 $ident = "";
118 $correctness = 1;
119 $conditionvar = $respcondition->getConditionvar();
120 foreach ($conditionvar->order as $order) {
121 switch ($order["field"]) {
122 case "arr_not":
123 $correctness = 0;
124 break;
125 case "varequal":
126 $ident = $conditionvar->varequal[$order["index"]]->getContent();
127 $orderindex = $conditionvar->varequal[$order["index"]]->getIndex();
128 break;
129 }
130 }
131 foreach ($respcondition->setvar as $setvar) {
132 if (strcmp($ident, "") != 0) {
133 $answers[$ident]["solutionorder"] = $orderindex;
134 $answers[$ident]["action"] = $setvar->getAction();
135 $answers[$ident]["points"] = $setvar->getContent();
136 }
137 }
138 if (count($respcondition->displayfeedback)) {
139 foreach ($respcondition->displayfeedback as $feedbackpointer) {
140 if (strlen($feedbackpointer->getLinkrefid())) {
141 foreach ($item->itemfeedback as $ifb) {
142 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
143
144 if (count($ifb->material)) {
145 foreach ($ifb->material as $material) {
146 $feedbacksgeneric[1] = $material;
147 }
148 }
149 if ((count($ifb->flow_mat) > 0)) {
150 foreach ($ifb->flow_mat as $fmat) {
151 if (count($fmat->material)) {
152 foreach ($fmat->material as $material) {
153 $feedbacksgeneric[1] = $material;
154 }
155 }
156 }
157 }
158 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
159
160 if (count($ifb->material)) {
161 foreach ($ifb->material as $material) {
162 $feedbacksgeneric[0] = $material;
163 }
164 }
165 if ((count($ifb->flow_mat) > 0)) {
166 foreach ($ifb->flow_mat as $fmat) {
167 if (count($fmat->material)) {
168 foreach ($fmat->material as $material) {
169 $feedbacksgeneric[0] = $material;
170 }
171 }
172 }
173 }
174 }
175 }
176 }
177 }
178 }
179 }
180 }
181
183
185 $this->object->setTitle($item->getTitle());
186 $this->object->setNrOfTries($item->getMaxattempts());
187 $this->object->setComment($item->getComment());
188 $this->object->setAuthor($item->getAuthor());
189 $this->
object->setOwner(
$ilUser->getId());
190 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
191 $this->
object->setOrderingType(
$type);
192 $this->object->setObjId($questionpool_id);
193 $this->object->setThumbGeometry($item->getMetadataEntry("thumb_geometry"));
194 $this->object->setElementHeight($item->getMetadataEntry("element_height"));
195 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
196 $this->object->setShuffle($shuffle);
197 $this->object->saveQuestionDataToDb();
198 $points = 0;
199 $solanswers = array();
200
201 foreach ($answers as $answer) {
202 $solanswers[$answer["solutionorder"]] = $answer;
203 }
204 ksort($solanswers);
205 $position = 0;
206 $element_list = $this->object->getOrderingElementList();
207 foreach ($solanswers as $answer) {
208 $points += $answer["points"];
209
211
212 if ($element->isExportIdent($answer['ident'])) {
213 $element->setExportIdent($answer['ident']);
214 } else {
215 $element = $element->withPosition($position++);
216 if (isset($answer['answerdepth'])) {
217 $element = $element->withIndentation((int) $answer['answerdepth']);
218 }
219 }
220
221 if ($this->object->isImageOrderingType()) {
222 $filename = $this->handleUploadedfile($answer);
224 $element = $element->withContent(
$filename);
225 }
226 } else {
227 $element = $element->withContent($answer["answertext"]);
228 }
229
230 $element_list->addElement($element);
231 }
232 $this->object->setOrderingElementList($element_list);
233 $points = ($item->getMetadataEntry("points") > 0) ? $item->getMetadataEntry("points") : $points;
234 $this->object->setPoints($points);
235
236 $this->object->setAdditionalContentEditingMode(
238 );
239 $this->object->saveToDb();
240 if (count($item->suggested_solutions)) {
241 foreach ($item->suggested_solutions as $suggested_solution) {
242 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
243 }
244 $this->object->saveToDb();
245 }
246
247 foreach ($feedbacksgeneric as $correctness => $material) {
248 $m = $this->object->QTIMaterialToString($material);
249 $feedbacksgeneric[$correctness] = $m;
250 }
251 $questiontext = $this->object->getQuestion();
252
253
254 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
255 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
256 include_once "./Services/RTE/classes/class.ilRTE.php";
257 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
258 if ($tst_id > 0) {
260 } else {
262 }
263
265 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
266
269 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
270 foreach ($this->object->getOrderingElementList() as $element) {
271 $element->setContent(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $element->getContent()));
272 }
273 foreach ($feedbacksgeneric as $correctness => $material) {
274 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
275 }
276 foreach ($itemfeedbacks as $ident => $material) {
277 $itemfeedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
278 }
279 }
280 }
282 foreach ($this->object->getOrderingElementList() as $element) {
284 }
285 foreach ($feedbacksgeneric as $correctness => $material) {
286 $this->object->feedbackOBJ->importGenericFeedback(
287 $this->object->getId(),
288 $correctness,
290 );
291 }
292 foreach ($itemfeedbacks as $ident => $material) {
294
295 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
296 $this->object->getId(),
297 0,
300 );
301 }
302 $this->object->saveToDb();
303 if (isset($tst_id) && $tst_id !== $questionpool_id) {
304 $qplQid = $this->object->getId();
305 $tstQid = $this->object->duplicate(true, '', '', '', $tst_id);
306 $tst_object->questions[$question_counter++] = $tstQid;
307 $import_mapping[$item->getIdent()] = array("pool" => $qplQid, "test" => $tstQid);
308 return;
309 }
310
311 if ($tst_id > 0) {
312 $tst_object->questions[$question_counter++] = $this->object->getId();
313 $import_mapping[$item->getIdent()] = array("pool" => 0, "test" => $this->object->getId());
314 return;
315 }
316 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
317 }
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 _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...
const OQ_PICTURES
Ordering question constants.