4require_once
'Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php';
5require_once
'Modules/TestQuestionPool/classes/class.ilAssKprimChoiceAnswer.php';
20 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
27 $duration = $item->getDuration();
31 $presentation = $item->getPresentation();
32 foreach ($presentation->order as $entry) {
33 switch ($entry[
"type"]) {
35 $response = $presentation->response[$entry[
"index"]];
37 switch (strtolower(get_class(
$response->getRenderType()))) {
38 case "ilqtirenderchoice":
39 $shuffle = $rendertype->getShuffle();
42 foreach ($rendertype->response_labels as $response_label) {
43 $ident = $response_label->getIdent();
45 $answerimage = array();
46 foreach ($response_label->material as $mat) {
48 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
49 $foundmat = $mat->getMaterial($m);
50 if (strcmp($foundmat[
"type"],
"mattext") == 0) {
52 if (strcmp($foundmat[
"type"],
"matimage") == 0) {
53 if (strlen($foundmat[
"material"]->getEmbedded())) {
59 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
60 $foundmat = $mat->getMaterial($m);
61 if (strcmp($foundmat[
"type"],
"mattext") == 0) {
62 $answertext .= $foundmat[
"material"]->getContent();
64 if (strcmp($foundmat[
"type"],
"matimage") == 0) {
67 "imagetype" => $foundmat[
"material"]->getImageType(),
68 "label" => $foundmat[
"material"]->getLabel(),
69 "content" => $foundmat[
"material"]->getContent()
74 $answertext = $this->
object->QTIMaterialToString($mat);
78 $answers[$ident] = array(
79 "answertext" => $answertext,
80 "imagefile" => $answerimage,
81 "answerorder" => $ident
91 $feedbacksgeneric = array();
93 foreach ($item->resprocessing as $resprocessing) {
94 foreach ($resprocessing->outcomes->decvar as $decvar) {
95 if ($decvar->getVarname() ==
'SCORE') {
96 $this->
object->setPoints($decvar->getMaxvalue());
98 if ($decvar->getMinvalue() > 0) {
99 $this->
object->setScorePartialSolutionEnabled(
true);
101 $this->
object->setScorePartialSolutionEnabled(
false);
106 foreach ($resprocessing->respcondition as $respcondition) {
107 if (!count($respcondition->setvar)) {
108 foreach ($respcondition->getConditionvar()->varequal as $varequal) {
109 $ident = $varequal->respident;
110 $answers[$ident][
'correctness'] = (bool) $varequal->getContent();
115 foreach ($respcondition->displayfeedback as $feedbackpointer) {
116 if (strlen($feedbackpointer->getLinkrefid())) {
117 foreach ($item->itemfeedback as $ifb) {
118 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
120 if (count($ifb->material)) {
121 foreach ($ifb->material as $material) {
122 $feedbacks[$ident] = $material;
125 if ((count($ifb->flow_mat) > 0)) {
126 foreach ($ifb->flow_mat as $fmat) {
127 if (count($fmat->material)) {
128 foreach ($fmat->material as $material) {
129 $feedbacks[$ident] = $material;
139 foreach ($respcondition->displayfeedback as $feedbackpointer) {
140 if (strlen($feedbackpointer->getLinkrefid())) {
141 foreach ($item->itemfeedback as $ifb) {
142 if ($ifb->getIdent() ==
"response_allcorrect") {
144 if (count($ifb->material)) {
145 foreach ($ifb->material as $material) {
146 $feedbacksgeneric[1] = $material;
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;
158 } elseif ($ifb->getIdent() ==
"response_onenotcorrect") {
160 if (count($ifb->material)) {
161 foreach ($ifb->material as $material) {
162 $feedbacksgeneric[0] = $material;
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;
184 $this->
object->setTitle($item->getTitle());
185 $this->
object->setNrOfTries($item->getMaxattempts());
186 $this->
object->setComment($item->getComment());
187 $this->
object->setAuthor($item->getAuthor());
188 $this->
object->setOwner(
$ilUser->getId());
189 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
190 $this->
object->setObjId($questionpool_id);
191 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
192 $this->
object->setShuffleAnswersEnabled($shuffle);
193 $this->
object->setAnswerType($item->getMetadataEntry(
"answer_type"));
194 $this->
object->setOptionLabel($item->getMetadataEntry(
"option_label_setting"));
195 $this->
object->setCustomTrueOptionLabel($item->getMetadataEntry(
"custom_true_option_label"));
196 $this->
object->setCustomFalseOptionLabel($item->getMetadataEntry(
"custom_false_option_label"));
197 $this->
object->setThumbSize($item->getMetadataEntry(
"thumb_size"));
199 $this->
object->saveToDb();
201 foreach ($answers as $answerData) {
203 $answer->setImageFsDir($this->object->getImagePath());
204 $answer->setImageWebDir($this->object->getImagePathWeb());
206 $answer->setPosition($answerData[
'answerorder']);
207 $answer->setAnswertext($answerData[
'answertext']);
208 $answer->setCorrectness($answerData[
'correctness']);
210 if (isset($answerData[
'imagefile'][
'label'])) {
211 $answer->setImageFile($answerData[
'imagefile'][
'label']);
214 $this->
object->addAnswer($answer);
217 $this->
object->setAdditionalContentEditingMode(
221 $this->
object->saveToDb();
223 foreach ($answers as $answer) {
224 if (is_array($answer[
"imagefile"]) && (count($answer[
"imagefile"]) > 0)) {
225 $image = &base64_decode($answer[
"imagefile"][
"content"]);
226 $imagepath = $this->
object->getImagePath();
227 include_once
"./Services/Utilities/classes/class.ilUtil.php";
228 if (!file_exists($imagepath)) {
231 $imagepath .= $answer[
"imagefile"][
"label"];
232 if ($fh = fopen($imagepath,
"wb")) {
233 $imagefile = fwrite($fh, $image);
239 $feedbackSetting = $item->getMetadataEntry(
'feedback_setting');
240 if (!is_null($feedbackSetting)) {
241 $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting);
242 $this->
object->setSpecificFeedbackSetting($feedbackSetting);
246 foreach ($feedbacks as $ident => $material) {
247 $m = $this->
object->QTIMaterialToString($material);
248 $feedbacks[$ident] = $m;
250 foreach ($feedbacksgeneric as $correctness => $material) {
251 $m = $this->
object->QTIMaterialToString($material);
252 $feedbacksgeneric[$correctness] = $m;
254 $questiontext = $this->
object->getQuestion();
255 $answers = &$this->
object->getAnswers();
256 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
257 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
258 include_once
"./Services/RTE/classes/class.ilRTE.php";
259 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
267 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
271 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
272 foreach ($answers as $key => $value) {
273 $answer_obj = &$answers[$key];
274 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
276 foreach ($feedbacks as $ident => $material) {
277 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
279 foreach ($feedbacksgeneric as $correctness => $material) {
280 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
285 foreach ($answers as $key => $value) {
286 $answer_obj = &$answers[$key];
289 foreach ($feedbacks as $ident => $material) {
290 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
291 $this->object->getId(),
297 foreach ($feedbacksgeneric as $correctness => $material) {
298 $this->
object->feedbackOBJ->importGenericFeedback(
299 $this->object->getId(),
304 $this->
object->saveToDb();
305 if (count($item->suggested_solutions)) {
306 foreach ($item->suggested_solutions as $suggested_solution) {
307 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
309 $this->
object->saveToDb();
312 $q_1_id = $this->
object->getId();
313 $question_id = $this->
object->duplicate(
true,
null,
null,
null, $tst_id);
314 $tst_object->questions[$question_counter++] = $question_id;
315 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
317 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);
An exception for terminatinating execution or to throw for unit testing.
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.