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)
26 $duration = $item->getDuration();
30 $presentation = $item->getPresentation();
31 foreach ($presentation->order as $entry)
33 switch ($entry[
"type"])
36 $response = $presentation->response[$entry[
"index"]];
37 $rendertype = $response->getRenderType();
38 switch (strtolower(get_class($response->getRenderType())))
40 case "ilqtirenderchoice":
41 $shuffle = $rendertype->getShuffle();
44 foreach ($rendertype->response_labels as $response_label)
46 $ident = $response_label->getIdent();
48 $answerimage = array();
49 foreach ($response_label->material as $mat)
52 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
54 $foundmat = $mat->getMaterial($m);
55 if (strcmp($foundmat[
"type"],
"mattext") == 0)
58 if (strcmp($foundmat[
"type"],
"matimage") == 0)
60 if (strlen($foundmat[
"material"]->getEmbedded()))
68 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
70 $foundmat = $mat->getMaterial($m);
71 if (strcmp($foundmat[
"type"],
"mattext") == 0)
73 $answertext .= $foundmat[
"material"]->getContent();
75 if (strcmp($foundmat[
"type"],
"matimage") == 0)
79 "imagetype" => $foundmat[
"material"]->getImageType(),
80 "label" => $foundmat[
"material"]->getLabel(),
81 "content" => $foundmat[
"material"]->getContent()
88 $answertext = $this->
object->QTIMaterialToString($mat);
92 $answers[$ident] = array(
93 "answertext" => $answertext,
94 "imagefile" => $answerimage,
95 "answerorder" => $ident
104 $feedbacks = array();
105 $feedbacksgeneric = array();
107 foreach ($item->resprocessing as $resprocessing)
109 foreach($resprocessing->outcomes->decvar as $decvar)
111 if( $decvar->getVarname() ==
'SCORE' )
113 $this->
object->setPoints($decvar->getMaxvalue());
115 if( $decvar->getMinvalue() > 0 )
117 $this->
object->setScorePartialSolutionEnabled(
true);
122 foreach ($resprocessing->respcondition as $respcondition)
124 if( !count($respcondition->setvar) )
126 foreach($respcondition->getConditionvar()->varequal as $varequal)
128 $ident = $varequal->respident;
129 $answers[$ident][
'correctness'] = (bool)$varequal->getContent();
134 foreach ($respcondition->displayfeedback as $feedbackpointer)
136 if (strlen($feedbackpointer->getLinkrefid()))
138 foreach ($item->itemfeedback as $ifb)
140 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0)
143 if (count($ifb->material))
145 foreach ($ifb->material as $material)
147 $feedbacks[$ident] = $material;
150 if ((count($ifb->flow_mat) > 0))
152 foreach ($ifb->flow_mat as $fmat)
154 if (count($fmat->material))
156 foreach ($fmat->material as $material)
158 $feedbacks[$ident] = $material;
170 foreach ($respcondition->displayfeedback as $feedbackpointer)
172 if (strlen($feedbackpointer->getLinkrefid()))
174 foreach ($item->itemfeedback as $ifb)
176 if( $ifb->getIdent() ==
"response_allcorrect" )
179 if (count($ifb->material))
181 foreach ($ifb->material as $material)
183 $feedbacksgeneric[1] = $material;
186 if ((count($ifb->flow_mat) > 0))
188 foreach ($ifb->flow_mat as $fmat)
190 if (count($fmat->material))
192 foreach ($fmat->material as $material)
194 $feedbacksgeneric[1] = $material;
200 else if ( $ifb->getIdent() ==
"response_onenotcorrect" )
203 if (count($ifb->material))
205 foreach ($ifb->material as $material)
207 $feedbacksgeneric[0] = $material;
210 if ((count($ifb->flow_mat) > 0))
212 foreach ($ifb->flow_mat as $fmat)
214 if (count($fmat->material))
216 foreach ($fmat->material as $material)
218 $feedbacksgeneric[0] = $material;
233 $this->
object->setTitle($item->getTitle());
234 $this->
object->setNrOfTries($item->getMaxattempts());
235 $this->
object->setComment($item->getComment());
236 $this->
object->setAuthor($item->getAuthor());
237 $this->
object->setOwner($ilUser->getId());
238 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
239 $this->
object->setObjId($questionpool_id);
240 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
241 $this->
object->setShuffleAnswersEnabled($shuffle);
242 $this->
object->setAnswerType($item->getMetadataEntry(
"answer_type"));
243 $this->
object->setOptionLabel($item->getMetadataEntry(
"option_label_setting"));
244 $this->
object->setCustomTrueOptionLabel($item->getMetadataEntry(
"custom_true_option_label"));
245 $this->
object->setCustomFalseOptionLabel($item->getMetadataEntry(
"custom_false_option_label"));
246 $this->
object->setThumbSize($item->getMetadataEntry(
"thumb_size"));
248 $this->
object->saveToDb();
250 foreach ($answers as $answerData)
253 $answer->setImageFsDir($this->object->getImagePath());
254 $answer->setImageWebDir($this->object->getImagePathWeb());
256 $answer->setPosition($answerData[
'answerorder']);
257 $answer->setAnswertext($answerData[
'answertext']);
258 $answer->setCorrectness($answerData[
'correctness']);
260 if( isset($answerData[
'imagefile'][
'label']) )
262 $answer->setImageFile($answerData[
'imagefile'][
'label']);
265 $this->
object->addAnswer($answer);
268 $this->
object->setAdditionalContentEditingMode(
272 $this->
object->saveToDb();
274 foreach ($answers as $answer)
276 if (is_array($answer[
"imagefile"]) && (count($answer[
"imagefile"]) > 0))
278 $image =& base64_decode($answer[
"imagefile"][
"content"]);
279 $imagepath = $this->
object->getImagePath();
280 include_once
"./Services/Utilities/classes/class.ilUtil.php";
281 if (!file_exists($imagepath))
285 $imagepath .= $answer[
"imagefile"][
"label"];
286 if($fh = fopen($imagepath,
"wb"))
288 $imagefile = fwrite($fh, $image);
294 $feedbackSetting = $item->getMetadataEntry(
'feedback_setting');
295 if( !is_null($feedbackSetting) )
297 $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting);
301 foreach ($feedbacks as $ident => $material)
303 $m = $this->
object->QTIMaterialToString($material);
304 $feedbacks[$ident] = $m;
306 foreach ($feedbacksgeneric as $correctness => $material)
308 $m = $this->
object->QTIMaterialToString($material);
309 $feedbacksgeneric[$correctness] = $m;
311 $questiontext = $this->
object->getQuestion();
312 $answers =& $this->
object->getAnswers();
313 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
315 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
316 include_once
"./Services/RTE/classes/class.ilRTE.php";
317 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
328 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
332 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
333 foreach ($answers as $key => $value)
335 $answer_obj =& $answers[$key];
336 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
338 foreach ($feedbacks as $ident => $material)
340 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
342 foreach ($feedbacksgeneric as $correctness => $material)
344 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
349 foreach ($answers as $key => $value)
351 $answer_obj =& $answers[$key];
354 foreach ($feedbacks as $ident => $material)
356 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
360 foreach ($feedbacksgeneric as $correctness => $material)
362 $this->
object->feedbackOBJ->importGenericFeedback(
366 $this->
object->saveToDb();
367 if (count($item->suggested_solutions))
369 foreach ($item->suggested_solutions as $suggested_solution)
371 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
373 $this->
object->saveToDb();
377 $q_1_id = $this->
object->getId();
378 $question_id = $this->
object->duplicate(
true,
null,
null,
null, $tst_id);
379 $tst_object->questions[$question_counter++] = $question_id;
380 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
384 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);
fromXML(&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
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.