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) {
32 switch ($entry[
"type"]) {
34 $response = $presentation->response[$entry[
"index"]];
36 switch (strtolower(get_class(
$response->getRenderType()))) {
37 case "ilqtirenderchoice":
38 $shuffle = $rendertype->getShuffle();
41 foreach ($rendertype->response_labels as $response_label) {
42 $ident = $response_label->getIdent();
44 $answerimage = array();
45 foreach ($response_label->material as $mat) {
47 for (
$m = 0;
$m < $mat->getMaterialCount();
$m++) {
48 $foundmat = $mat->getMaterial(
$m);
49 if (strcmp($foundmat[
"type"],
"mattext") == 0) {
51 if (strcmp($foundmat[
"type"],
"matimage") == 0) {
52 if (strlen($foundmat[
"material"]->getEmbedded())) {
58 for (
$m = 0;
$m < $mat->getMaterialCount();
$m++) {
59 $foundmat = $mat->getMaterial(
$m);
60 if (strcmp($foundmat[
"type"],
"mattext") == 0) {
61 $answertext .= $foundmat[
"material"]->getContent();
63 if (strcmp($foundmat[
"type"],
"matimage") == 0) {
66 "imagetype" => $foundmat[
"material"]->getImageType(),
67 "label" => $foundmat[
"material"]->getLabel(),
68 "content" => $foundmat[
"material"]->getContent()
73 $answertext = $this->
object->QTIMaterialToString($mat);
77 $answers[$ident] = array(
78 "answertext" => $answertext,
79 "imagefile" => $answerimage,
80 "answerorder" => $ident
90 $feedbacksgeneric = array();
92 foreach ($item->resprocessing as $resprocessing) {
93 foreach ($resprocessing->outcomes->decvar as $decvar) {
94 if ($decvar->getVarname() ==
'SCORE') {
95 $this->
object->setPoints($decvar->getMaxvalue());
97 if ($decvar->getMinvalue() > 0) {
98 $this->
object->setScorePartialSolutionEnabled(
true);
100 $this->
object->setScorePartialSolutionEnabled(
false);
105 foreach ($resprocessing->respcondition as $respcondition) {
106 if (!count($respcondition->setvar)) {
107 foreach ($respcondition->getConditionvar()->varequal as $varequal) {
108 $ident = $varequal->respident;
109 $answers[$ident][
'correctness'] = (bool) $varequal->getContent();
114 foreach ($respcondition->displayfeedback as $feedbackpointer) {
115 if (strlen($feedbackpointer->getLinkrefid())) {
116 foreach ($item->itemfeedback as $ifb) {
117 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
119 if (count($ifb->material)) {
120 foreach ($ifb->material as $material) {
121 $feedbacks[$ident] = $material;
124 if ((count($ifb->flow_mat) > 0)) {
125 foreach ($ifb->flow_mat as $fmat) {
126 if (count($fmat->material)) {
127 foreach ($fmat->material as $material) {
128 $feedbacks[$ident] = $material;
138 foreach ($respcondition->displayfeedback as $feedbackpointer) {
139 if (strlen($feedbackpointer->getLinkrefid())) {
140 foreach ($item->itemfeedback as $ifb) {
141 if ($ifb->getIdent() ==
"response_allcorrect") {
143 if (count($ifb->material)) {
144 foreach ($ifb->material as $material) {
145 $feedbacksgeneric[1] = $material;
148 if ((count($ifb->flow_mat) > 0)) {
149 foreach ($ifb->flow_mat as $fmat) {
150 if (count($fmat->material)) {
151 foreach ($fmat->material as $material) {
152 $feedbacksgeneric[1] = $material;
157 } elseif ($ifb->getIdent() ==
"response_onenotcorrect") {
159 if (count($ifb->material)) {
160 foreach ($ifb->material as $material) {
161 $feedbacksgeneric[0] = $material;
164 if ((count($ifb->flow_mat) > 0)) {
165 foreach ($ifb->flow_mat as $fmat) {
166 if (count($fmat->material)) {
167 foreach ($fmat->material as $material) {
168 $feedbacksgeneric[0] = $material;
183 $this->
object->setTitle($item->getTitle());
184 $this->
object->setNrOfTries($item->getMaxattempts());
185 $this->
object->setComment($item->getComment());
186 $this->
object->setAuthor($item->getAuthor());
187 $this->
object->setOwner($ilUser->getId());
188 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
189 $this->
object->setObjId($questionpool_id);
190 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
191 $this->
object->setShuffleAnswersEnabled($shuffle);
192 $this->
object->setAnswerType($item->getMetadataEntry(
"answer_type"));
193 $this->
object->setOptionLabel($item->getMetadataEntry(
"option_label_setting"));
194 $this->
object->setCustomTrueOptionLabel($item->getMetadataEntry(
"custom_true_option_label"));
195 $this->
object->setCustomFalseOptionLabel($item->getMetadataEntry(
"custom_false_option_label"));
196 $this->
object->setThumbSize($item->getMetadataEntry(
"thumb_size"));
198 $this->
object->saveToDb();
200 foreach ($answers as $answerData) {
202 $answer->setImageFsDir($this->object->getImagePath());
203 $answer->setImageWebDir($this->object->getImagePathWeb());
205 $answer->setPosition($answerData[
'answerorder']);
206 $answer->setAnswertext($answerData[
'answertext']);
207 $answer->setCorrectness($answerData[
'correctness']);
209 if (isset($answerData[
'imagefile'][
'label'])) {
210 $answer->setImageFile($answerData[
'imagefile'][
'label']);
213 $this->
object->addAnswer($answer);
216 $this->
object->setAdditionalContentEditingMode(
220 $this->
object->saveToDb();
222 foreach ($answers as $answer) {
223 if (is_array($answer[
"imagefile"]) && (count($answer[
"imagefile"]) > 0)) {
224 $image =&base64_decode($answer[
"imagefile"][
"content"]);
225 $imagepath = $this->
object->getImagePath();
226 include_once
"./Services/Utilities/classes/class.ilUtil.php";
227 if (!file_exists($imagepath)) {
230 $imagepath .= $answer[
"imagefile"][
"label"];
231 if (
$fh = fopen($imagepath,
"wb")) {
232 $imagefile = fwrite(
$fh, $image);
238 $feedbackSetting = $item->getMetadataEntry(
'feedback_setting');
239 if (!is_null($feedbackSetting)) {
240 $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting);
244 foreach ($feedbacks as $ident => $material) {
245 $m = $this->
object->QTIMaterialToString($material);
246 $feedbacks[$ident] =
$m;
248 foreach ($feedbacksgeneric as $correctness => $material) {
249 $m = $this->
object->QTIMaterialToString($material);
250 $feedbacksgeneric[$correctness] =
$m;
252 $questiontext = $this->
object->getQuestion();
253 $answers =&$this->
object->getAnswers();
254 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
255 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
256 include_once
"./Services/RTE/classes/class.ilRTE.php";
257 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
264 $GLOBALS[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
268 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
269 foreach ($answers as
$key => $value) {
270 $answer_obj =&$answers[
$key];
271 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
273 foreach ($feedbacks as $ident => $material) {
274 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
276 foreach ($feedbacksgeneric as $correctness => $material) {
277 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
282 foreach ($answers as
$key => $value) {
283 $answer_obj =&$answers[
$key];
286 foreach ($feedbacks as $ident => $material) {
287 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
288 $this->object->getId(),
293 foreach ($feedbacksgeneric as $correctness => $material) {
294 $this->
object->feedbackOBJ->importGenericFeedback(
295 $this->object->getId(),
300 $this->
object->saveToDb();
301 if (count($item->suggested_solutions)) {
302 foreach ($item->suggested_solutions as $suggested_solution) {
303 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
305 $this->
object->saveToDb();
308 $q_1_id = $this->
object->getId();
309 $question_id = $this->
object->duplicate(
true,
null,
null,
null, $tst_id);
310 $tst_object->questions[$question_counter++] = $question_id;
311 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
313 $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.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.