24 include_once
"./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
50 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
56 $presentation = $item->getPresentation();
57 $duration = $item->getDuration();
61 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
63 foreach ($presentation->order as $entry)
65 switch ($entry[
"type"])
68 $response = $presentation->response[$entry[
"index"]];
71 array_push($idents, $response->getIdent());
77 $feedbacksgeneric = array();
78 foreach ($item->resprocessing as $resprocessing)
80 foreach ($resprocessing->respcondition as $respcondition)
84 $conditionvar = $respcondition->getConditionvar();
85 foreach ($conditionvar->order as $order)
87 switch ($order[
"field"])
90 $respident = $conditionvar->varsubset[$order[
"index"]]->getRespident();
91 $content = $conditionvar->varsubset[$order[
"index"]]->getContent();
92 if (!is_array($responses[$respident])) $responses[$respident] = array();
93 $vars = split(
",", $content);
94 foreach ($vars as $var)
96 array_push($responses[$respident], array(
"solution" => $var,
"points" =>
""));
101 foreach ($respcondition->setvar as $setvar)
103 if ((strcmp($setvar->getVarname(),
"matches") == 0) && ($setvar->getAction() ==
ACTION_ADD))
105 foreach ($responses[$respident] as $idx => $solutionarray)
107 if (strlen($solutionarray[
"points"] == 0))
109 $responses[$respident][$idx][
"points"] = $setvar->getContent();
114 foreach ($resprocessing->respcondition as $respcondition)
116 foreach ($respcondition->displayfeedback as $feedbackpointer)
118 if (strlen($feedbackpointer->getLinkrefid()))
120 foreach ($item->itemfeedback as $ifb)
122 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0)
125 if (count($ifb->material))
127 foreach ($ifb->material as $material)
129 $feedbacksgeneric[1] = $material;
132 if ((count($ifb->flow_mat) > 0))
134 foreach ($ifb->flow_mat as $fmat)
136 if (count($fmat->material))
138 foreach ($fmat->material as $material)
140 $feedbacksgeneric[1] = $material;
146 else if (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0)
149 if (count($ifb->material))
151 foreach ($ifb->material as $material)
153 $feedbacksgeneric[0] = $material;
156 if ((count($ifb->flow_mat) > 0))
158 foreach ($ifb->flow_mat as $fmat)
160 if (count($fmat->material))
162 foreach ($fmat->material as $material)
164 $feedbacksgeneric[0] = $material;
177 $this->
object->setTitle($item->getTitle());
178 $this->
object->setNrOfTries($item->getMaxattempts());
179 $this->
object->setComment($item->getComment());
180 $this->
object->setAuthor($item->getAuthor());
181 $this->
object->setOwner($ilUser->getId());
182 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
183 $this->
object->setObjId($questionpool_id);
184 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
185 $textrating = $item->getMetadataEntry(
"textrating");
186 if (strlen($textrating) == 0) $textrating =
"ci";
187 $this->
object->setTextRating($textrating);
188 $this->
object->setCorrectAnswers($item->getMetadataEntry(
"correctanswers"));
189 $response = current($responses);
191 if (is_array($response))
193 foreach ($response as $answer)
195 $this->
object->addAnswer($answer[
"solution"], $answer[
"points"], $counter);
199 $this->
object->saveToDb();
200 if (count($item->suggested_solutions))
202 foreach ($item->suggested_solutions as $suggested_solution)
204 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
206 $this->
object->saveToDb();
208 foreach ($feedbacksgeneric as $correctness => $material)
210 $m = $this->
object->QTIMaterialToString($material);
211 $feedbacksgeneric[$correctness] = $m;
214 $questiontext = $this->
object->getQuestion();
215 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
217 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
218 include_once
"./Services/RTE/classes/class.ilRTE.php";
219 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
230 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
234 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
235 foreach ($feedbacksgeneric as $correctness => $material)
237 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
242 foreach ($feedbacksgeneric as $correctness => $material)
246 $this->
object->saveToDb();
249 $q_1_id = $this->
object->getId();
250 $question_id = $this->
object->duplicate(
true, null, null, null, $tst_id);
251 $tst_object->questions[$question_counter++] = $question_id;
252 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
256 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);