4include_once
"./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
30 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
36 $presentation = $item->getPresentation();
37 $duration = $item->getDuration();
39 $questionimage = array();
40 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
42 foreach ($presentation->order as $entry)
44 switch ($entry[
"type"])
47 $response = $presentation->response[$entry[
"index"]];
48 $rendertype = $response->getRenderType();
49 switch (strtolower(get_class($rendertype)))
51 case "ilqtirenderhotspot":
52 foreach ($rendertype->material as $mat)
54 for ($i = 0; $i < $mat->getMaterialCount(); $i++)
56 $m = $mat->getMaterial($i);
57 if (strcmp($m[
"type"],
"matimage") == 0)
59 $questionimage = array(
60 "imagetype" => $m[
"material"]->getImageType(),
61 "label" => $m[
"material"]->getLabel(),
62 "content" => $m[
"material"]->getContent()
67 foreach ($rendertype->response_labels as $response_label)
69 $ident = $response_label->getIdent();
71 foreach ($response_label->material as $mat)
73 $answerhint .= $this->
object->QTIMaterialToString($mat);
75 $answers[$ident] = array(
76 "answerhint" => $answerhint,
77 "areatype" => $response_label->getRarea(),
78 "coordinates" => $response_label->getContent(),
80 "answerorder" => $response_label->getIdent(),
83 "points_unchecked" => 0
93 $feedbacksgeneric = array();
94 foreach ($item->resprocessing as $resprocessing)
96 foreach ($resprocessing->respcondition as $respcondition)
100 $conditionvar = $respcondition->getConditionvar();
101 foreach ($conditionvar->order as $order)
103 switch ($order[
"field"])
109 $coordinates = $conditionvar->varinside[$order[
"index"]]->getContent();
112 $coordinates = $conditionvar->varequal[$order[
"index"]]->getContent();
116 foreach ($respcondition->setvar as $setvar)
118 foreach ($answers as $ident => $answer)
120 if (strcmp($answer[
"coordinates"], $coordinates) == 0)
124 $answers[$ident][
"action"] = $setvar->getAction();
125 $answers[$ident][
"points"] = $setvar->getContent();
126 if (count($respcondition->displayfeedback))
128 foreach ($respcondition->displayfeedback as $feedbackpointer)
130 if (strlen($feedbackpointer->getLinkrefid()))
132 foreach ($item->itemfeedback as $ifb)
134 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0)
137 if (count($ifb->material))
139 foreach ($ifb->material as $material)
141 $feedbacksgeneric[1] = $material;
144 if ((count($ifb->flow_mat) > 0))
146 foreach ($ifb->flow_mat as $fmat)
148 if (count($fmat->material))
150 foreach ($fmat->material as $material)
152 $feedbacksgeneric[1] = $material;
158 else if (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0)
161 if (count($ifb->material))
163 foreach ($ifb->material as $material)
165 $feedbacksgeneric[0] = $material;
168 if ((count($ifb->flow_mat) > 0))
170 foreach ($ifb->flow_mat as $fmat)
172 if (count($fmat->material))
174 foreach ($fmat->material as $material)
176 $feedbacksgeneric[0] = $material;
182 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0)
185 if (count($ifb->material))
187 foreach ($ifb->material as $material)
189 $feedbacks[$ident] = $material;
192 if ((count($ifb->flow_mat) > 0))
194 foreach ($ifb->flow_mat as $fmat)
196 if (count($fmat->material))
198 foreach ($fmat->material as $material)
200 $feedbacks[$ident] = $material;
213 $answers[$ident][
"action"] = $setvar->getAction();
214 $answers[$ident][
"points_unchecked"] = $setvar->getContent();
223 $this->
object->setTitle($item->getTitle());
224 $this->
object->setNrOfTries($item->getMaxattempts());
225 $this->
object->setComment($item->getComment());
226 $this->
object->setAuthor($item->getAuthor());
227 $this->
object->setOwner($ilUser->getId());
228 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
229 $this->
object->setObjId($questionpool_id);
230 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
231 $this->
object->setIsMultipleChoice($item->getMetadataEntry(
"IS_MULTIPLE_CHOICE"));
232 $areas = array(
"2" =>
"rect",
"1" =>
"circle",
"3" =>
"poly");
233 $this->
object->setImageFilename($questionimage[
"label"]);
234 foreach ($answers as $answer)
236 $this->
object->addAnswer($answer[
"answerhint"], $answer[
"points"], $answer[
"answerorder"], $answer[
"coordinates"], $areas[$answer[
"areatype"]], $answer[
"points_unchecked"]);
239 $this->
object->setAdditionalContentEditingMode(
242 $this->
object->saveToDb();
243 if (count($item->suggested_solutions))
245 foreach ($item->suggested_solutions as $suggested_solution)
247 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
249 $this->
object->saveToDb();
251 $image =& base64_decode($questionimage[
"content"]);
252 $imagepath = $this->
object->getImagePath();
253 if (!file_exists($imagepath))
255 include_once
"./Services/Utilities/classes/class.ilUtil.php";
258 $imagepath .= $questionimage[
"label"];
259 $fh = fopen($imagepath,
"wb");
268 $imagefile = fwrite($fh, $image);
272 foreach ($feedbacks as $ident => $material)
274 $m = $this->
object->QTIMaterialToString($material);
275 $feedbacks[$ident] = $m;
277 foreach ($feedbacksgeneric as $correctness => $material)
279 $m = $this->
object->QTIMaterialToString($material);
280 $feedbacksgeneric[$correctness] = $m;
282 $questiontext = $this->
object->getQuestion();
283 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
285 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
286 include_once
"./Services/RTE/classes/class.ilRTE.php";
287 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
298 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
302 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
303 foreach ($feedbacks as $ident => $material)
305 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
307 foreach ($feedbacksgeneric as $correctness => $material)
309 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
314 foreach ($feedbacks as $ident => $material)
316 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
320 foreach ($feedbacksgeneric as $correctness => $material)
322 $this->
object->feedbackOBJ->importGenericFeedback(
326 $this->
object->saveToDb();
329 $q_1_id = $this->
object->getId();
330 $question_id = $this->
object->duplicate(
true,
null,
null,
null, $tst_id);
331 $tst_object->questions[$question_counter++] = $question_id;
332 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
336 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);
Class for imagemap question imports.
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
Class for question imports.
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.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.