24 include_once
"./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
39 $image =& base64_decode(
$data);
40 $imagepath = $this->
object->getImagePath();
41 include_once
"./Services/Utilities/classes/class.ilUtil.php";
42 if (!file_exists($imagepath))
47 $fh = fopen($imagepath,
"wb");
53 $imagefile = fwrite($fh, $image);
71 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
77 $presentation = $item->getPresentation();
78 $duration = $item->getDuration();
81 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
82 $definitions = array();
85 foreach ($presentation->order as $entry)
87 switch ($entry[
"type"])
90 $response = $presentation->response[$entry[
"index"]];
91 $rendertype = $response->getRenderType();
92 switch (strtolower(get_class($rendertype)))
94 case "ilqtirenderchoice":
95 $shuffle = $rendertype->getShuffle();
97 foreach ($rendertype->response_labels as $response_label)
99 $ident = $response_label->getIdent();
101 $answerimage = array();
102 foreach ($response_label->material as $mat)
104 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
106 $foundmat = $mat->getMaterial($m);
107 if (strcmp($foundmat[
"type"],
"mattext") == 0)
109 $answertext .= $foundmat[
"material"]->getContent();
111 if (strcmp($foundmat[
"type"],
"matimage") == 0)
114 $answerimage = array(
115 "imagetype" => $foundmat[
"material"]->getImageType(),
116 "label" => $foundmat[
"material"]->getLabel(),
117 "content" => $foundmat[
"material"]->getContent()
122 if (($response_label->getMatchMax() == 1) && (strlen($response_label->getMatchGroup())))
124 $definitions[$ident] = array(
125 "answertext" => $answertext,
126 "answerimage" => $answerimage,
128 "answerorder" => $ident,
134 $terms[$ident] = array(
135 "term" => $answertext,
136 "answerimage" => $answerimage,
148 $responses = array();
149 $feedbacksgeneric = array();
150 foreach ($item->resprocessing as $resprocessing)
152 foreach ($resprocessing->respcondition as $respcondition)
156 $conditionvar = $respcondition->getConditionvar();
157 foreach ($conditionvar->order as $order)
159 switch ($order[
"field"])
162 $subset = split(
",", $conditionvar->varsubset[$order[
"index"]]->getContent());
166 foreach ($respcondition->setvar as $setvar)
168 array_push($responses, array(
"subset" => $subset,
"action" => $setvar->getAction(),
"points" => $setvar->getContent()));
171 if (count($respcondition->displayfeedback))
173 foreach ($respcondition->displayfeedback as $feedbackpointer)
175 if (strlen($feedbackpointer->getLinkrefid()))
177 foreach ($item->itemfeedback as $ifb)
179 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0)
182 if (count($ifb->material))
184 foreach ($ifb->material as $material)
186 $feedbacksgeneric[1] = $material;
189 if ((count($ifb->flow_mat) > 0))
191 foreach ($ifb->flow_mat as $fmat)
193 if (count($fmat->material))
195 foreach ($fmat->material as $material)
197 $feedbacksgeneric[1] = $material;
203 else if (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0)
206 if (count($ifb->material))
208 foreach ($ifb->material as $material)
210 $feedbacksgeneric[0] = $material;
213 if ((count($ifb->flow_mat) > 0))
215 foreach ($ifb->flow_mat as $fmat)
217 if (count($fmat->material))
219 foreach ($fmat->material as $material)
221 $feedbacksgeneric[0] = $material;
235 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
236 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
237 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
238 $this->
object->createNewQuestion();
239 $this->
object->setTitle($item->getTitle());
240 $this->
object->setExternalID($item->getIdent());
241 $this->
object->setNrOfTries($item->getMaxattempts());
242 $this->
object->setComment($item->getComment());
243 $this->
object->setAuthor($item->getAuthor());
244 $this->
object->setOwner($ilUser->getId());
245 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
246 $this->
object->setObjId($questionpool_id);
247 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
248 $extended_shuffle = $item->getMetadataEntry(
"shuffle");
249 $this->
object->setThumbGeometry($item->getMetadataEntry(
"thumb_geometry"));
250 $this->
object->setElementHeight($item->getMetadataEntry(
"element_height"));
253 foreach ($terms as $term)
255 if (count($term[
'answerimage'])) $this->
saveImage($term[
'answerimage'][
'content'], $term[
'answerimage'][
'label']);
257 foreach ($definitions as $definition)
259 if (count($definition[
'answerimage'])) $this->
saveImage($definition[
'answerimage'][
'content'], $definition[
'answerimage'][
'label']);
262 foreach ($terms as $termindex => $term)
264 $this->
object->addTerm(
new assAnswerMatchingTerm($term[
"term"], $term[
'answerimage'][
'label'], $term[
"ident"]));
266 foreach ($definitions as $definitionindex => $definition)
268 $this->
object->addDefinition(
new assAnswerMatchingDefinition($definition[
"answertext"], $definition[
'answerimage'][
'label'], $definition[
"answerorder"]));
271 if (strlen($extended_shuffle) > 0)
273 $shuffle = $extended_shuffle;
275 $this->
object->setShuffle($shuffle);
277 foreach ($responses as $response)
279 $subset = $response[
"subset"];
280 foreach ($subset as $ident)
282 if (array_key_exists($ident, $definitions))
284 $definition = $definitions[$ident];
286 if (array_key_exists($ident, $terms))
288 $term = $terms[$ident];
293 $this->
object->saveToDb();
294 if (count($item->suggested_solutions))
296 foreach ($item->suggested_solutions as $suggested_solution)
298 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
300 $this->
object->saveToDb();
302 foreach ($responses as $response)
304 $subset = $response[
"subset"];
305 foreach ($subset as $ident)
307 if (array_key_exists($ident, $definitions))
309 $definition = $definitions[$ident];
311 if (array_key_exists($ident, $terms))
313 $term = $terms[$ident];
318 foreach ($feedbacksgeneric as $correctness => $material)
320 $m = $this->
object->QTIMaterialToString($material);
321 $feedbacksgeneric[$correctness] = $m;
325 $questiontext = $this->
object->getQuestion();
326 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
328 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
329 include_once
"./Services/RTE/classes/class.ilRTE.php";
330 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
334 include_once
"./Modules/Test/classes/class.ilObjTest.php";
339 include_once
"./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
344 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
345 foreach ($feedbacksgeneric as $correctness => $material)
347 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
352 foreach ($feedbacksgeneric as $correctness => $material)
356 $this->
object->saveToDb();
359 $q_1_id = $this->
object->getId();
360 $question_id = $this->
object->duplicate(
true);
361 $tst_object->questions[$question_counter++] = $question_id;
362 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
366 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);
379 $oldIDExists =
false;
381 $checkResult = $ilDB->query(
"SHOW COLUMNS FROM qpl_a_mterm");
382 if ($checkResult->numRows() > 0)
384 while (
$data = $ilDB->fetchAssoc($checkResult))
386 if(
$data[
'field']==
'old_id')
400 $ilDB->addTableColumn(
"qpl_a_mterm",
"old_id",
401 array(
"type" =>
"integer",
"length" => 4));
404 $changeResult = $ilDB->queryF(
"SELECT * FROM qpl_a_mterm WHERE question_fi = %s ORDER BY term_id ASC",
406 array($this->object->id)
410 if ($changeResult->numRows() > 0)
412 while (
$data = $ilDB->fetchAssoc($changeResult))
414 $data[
'old_id']=array_search(
$data[
'term_id'], $this->object->masterTermIDs);
415 array_push($newTerms,
$data);
417 foreach ($newTerms as $singleTerm)
420 $ilDB->update(
"qpl_a_mterm", array(
421 "old_id" =>array(
"integer", $singleTerm[
'old_id'])),
423 "term_id" =>array(
"integer", $singleTerm[
'term_id']),
424 "question_fi" =>array(
"integer", $singleTerm[
'question_fi'])