Creates a question from a QTI file.
43 : array
44 {
47
48
50
51 $presentation = $item->getPresentation();
52 $now = getdate();
53 $questionimage = array();
54 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
55 $answers = array();
56 foreach ($presentation->order as $entry) {
57 switch ($entry["type"]) {
58 case "response":
59 $response = $presentation->response[$entry[
"index"]];
61 switch (strtolower(get_class($rendertype))) {
62 case "ilqtirenderhotspot":
63 foreach ($rendertype->material as $mat) {
64 for (
$i = 0;
$i < $mat->getMaterialCount();
$i++) {
65 $m = $mat->getMaterial(
$i);
66 if (strcmp($m["type"], "matimage") == 0) {
67 $questionimage = array(
68 "imagetype" => $m["material"]->getImageType(),
69 "label" => $m["material"]->getLabel(),
71 );
72 }
73 }
74 }
75 foreach ($rendertype->response_labels as $response_label) {
76 $ident = $response_label->getIdent();
77 $answerhint = "";
78 foreach ($response_label->material as $mat) {
79 $answerhint .= $this->object->QTIMaterialToString($mat);
80 }
81 $answers[$ident] = array(
82 "answerhint" => $answerhint,
83 "areatype" => $response_label->getRarea(),
84 "coordinates" => $response_label->getContent(),
85 "points" => 0,
86 "answerorder" => $response_label->getIdent(),
87 "correctness" => "1",
88 "action" => "",
89 "points_unchecked" => 0
90 );
91 }
92 break;
93 }
94 break;
95 }
96 }
97 $responses = array();
98 $feedbacks = array();
99 $feedbacksgeneric = array();
100 foreach ($item->resprocessing as $resprocessing) {
101 foreach ($resprocessing->respcondition as $respcondition) {
102 $coordinates = "";
103 $correctness = 1;
104 $conditionvar = $respcondition->getConditionvar();
105 foreach ($conditionvar->order as $order) {
106 switch ($order["field"]) {
107 case "arr_not":
108 $correctness = 0;
109 break;
110 case "varinside":
111 $coordinates = $conditionvar->varinside[$order["index"]]->getContent();
112 break;
113 case "varequal":
114 $coordinates = $conditionvar->varequal[$order["index"]]->getContent();
115 break;
116 }
117 }
118 foreach ($respcondition->setvar as $setvar) {
119 foreach ($answers as $ident => $answer) {
120 if (strcmp($answer["coordinates"], $coordinates) == 0) {
121 if ($correctness) {
122 $answers[$ident]["action"] = $setvar->getAction();
123 $answers[$ident]["points"] = $setvar->getContent();
124 if (count($respcondition->displayfeedback)) {
125 foreach ($respcondition->displayfeedback as $feedbackpointer) {
126 if (strlen($feedbackpointer->getLinkrefid())) {
127 foreach ($item->itemfeedback as $ifb) {
128 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
129
130 if (count($ifb->material)) {
131 foreach ($ifb->material as $material) {
132 $feedbacksgeneric[1] = $material;
133 }
134 }
135 if ((count($ifb->flow_mat) > 0)) {
136 foreach ($ifb->flow_mat as $fmat) {
137 if (count($fmat->material)) {
138 foreach ($fmat->material as $material) {
139 $feedbacksgeneric[1] = $material;
140 }
141 }
142 }
143 }
144 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
145
146 if (count($ifb->material)) {
147 foreach ($ifb->material as $material) {
148 $feedbacksgeneric[0] = $material;
149 }
150 }
151 if ((count($ifb->flow_mat) > 0)) {
152 foreach ($ifb->flow_mat as $fmat) {
153 if (count($fmat->material)) {
154 foreach ($fmat->material as $material) {
155 $feedbacksgeneric[0] = $material;
156 }
157 }
158 }
159 }
160 }
161 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
162
163 if (count($ifb->material)) {
164 foreach ($ifb->material as $material) {
165 $feedbacks[$ident] = $material;
166 }
167 }
168 if ((count($ifb->flow_mat) > 0)) {
169 foreach ($ifb->flow_mat as $fmat) {
170 if (count($fmat->material)) {
171 foreach ($fmat->material as $material) {
172 $feedbacks[$ident] = $material;
173 }
174 }
175 }
176 }
177 }
178 }
179 }
180 }
181 }
182 } else {
183 $answers[$ident]["action"] = $setvar->getAction();
184 $answers[$ident]["points_unchecked"] = $setvar->getContent();
185 }
186 }
187 }
188 }
189 }
190 }
191
193 $this->object->setTitle($item->getTitle());
194 $this->object->setNrOfTries((int) $item->getMaxattempts());
195 $this->object->setComment($item->getComment());
196 $this->object->setAuthor($item->getAuthor());
197 $this->
object->setOwner(
$ilUser->getId());
198 $this->
object->setQuestion($this->
object->QTIMaterialToString($item->getQuestiontext()));
199 $this->object->setObjId($questionpool_id);
200 $this->object->setIsMultipleChoice($item->getMetadataEntry("IS_MULTIPLE_CHOICE"));
201 $areas = array("2" => "rect", "1" => "circle", "3" => "poly");
202 $this->object->setImageFilename($questionimage["label"]);
203 foreach ($answers as $answer) {
204 $this->object->addAnswer($answer["answerhint"], $answer["points"], $answer["answerorder"], $answer["coordinates"], $areas[$answer["areatype"]], $answer["points_unchecked"]);
205 }
206
207 $this->object->setAdditionalContentEditingMode(
209 );
210 $this->object->saveToDb();
211 if (count($item->suggested_solutions)) {
212 foreach ($item->suggested_solutions as $suggested_solution) {
213 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->
getContent(), $suggested_solution[
"gap_index"],
true);
214 }
215 $this->object->saveToDb();
216 }
217 $image = base64_decode($questionimage["content"]);
218 $imagepath = $this->object->getImagePath();
219 if (!file_exists($imagepath)) {
221 }
222 $imagepath .= $questionimage["label"];
223 $fh = fopen($imagepath, "wb");
224 if ($fh == true) {
225 $imagefile = fwrite($fh, $image);
226 fclose($fh);
227 }
228
229 foreach ($feedbacks as $ident => $material) {
230 $m = $this->object->QTIMaterialToString($material);
231 $feedbacks[$ident] = $m;
232 }
233 foreach ($feedbacksgeneric as $correctness => $material) {
234 $m = $this->object->QTIMaterialToString($material);
235 $feedbacksgeneric[$correctness] = $m;
236 }
237 $questiontext = $this->object->getQuestion();
240 if ($tst_id > 0) {
242 } else {
244 }
245
247 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
248
251 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
252 foreach ($feedbacks as $ident => $material) {
253 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
254 }
255 foreach ($feedbacksgeneric as $correctness => $material) {
256 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
257 }
258 }
259 }
261 foreach ($feedbacks as $ident => $material) {
262 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
264 0,
265 $ident,
267 );
268 }
269 foreach ($feedbacksgeneric as $correctness => $material) {
270 $this->object->feedbackOBJ->importGenericFeedback(
272 $correctness,
274 );
275 }
276 $this->object->saveToDb();
277 if ($tst_id > 0) {
278 $q_1_id = $this->object->getId();
279 $question_id = $this->object->duplicate(true, "", "", "", $tst_id);
280 $tst_object->questions[$question_counter++] = $question_id;
281 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
282 } else {
283 $import_mapping[$item->getIdent()] = array(
"pool" => $this->
object->getId(),
"test" => 0);
284 }
285 return $import_mapping;
286 }
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 makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static get(string $a_var)
static clear(string $a_var)