4 require_once
'Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php';
5 require_once
'Modules/TestQuestionPool/classes/class.ilAssKprimChoiceAnswer.php';
20 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
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);
121 $this->
object->setScorePartialSolutionEnabled(
false);
126 foreach ($resprocessing->respcondition as $respcondition)
128 if( !count($respcondition->setvar) )
130 foreach($respcondition->getConditionvar()->varequal as $varequal)
132 $ident = $varequal->respident;
133 $answers[$ident][
'correctness'] = (bool)$varequal->getContent();
138 foreach ($respcondition->displayfeedback as $feedbackpointer)
140 if (strlen($feedbackpointer->getLinkrefid()))
142 foreach ($item->itemfeedback as $ifb)
144 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0)
147 if (count($ifb->material))
149 foreach ($ifb->material as $material)
151 $feedbacks[$ident] = $material;
154 if ((count($ifb->flow_mat) > 0))
156 foreach ($ifb->flow_mat as $fmat)
158 if (count($fmat->material))
160 foreach ($fmat->material as $material)
162 $feedbacks[$ident] = $material;
174 foreach ($respcondition->displayfeedback as $feedbackpointer)
176 if (strlen($feedbackpointer->getLinkrefid()))
178 foreach ($item->itemfeedback as $ifb)
180 if( $ifb->getIdent() ==
"response_allcorrect" )
183 if (count($ifb->material))
185 foreach ($ifb->material as $material)
187 $feedbacksgeneric[1] = $material;
190 if ((count($ifb->flow_mat) > 0))
192 foreach ($ifb->flow_mat as $fmat)
194 if (count($fmat->material))
196 foreach ($fmat->material as $material)
198 $feedbacksgeneric[1] = $material;
204 else if ( $ifb->getIdent() ==
"response_onenotcorrect" )
207 if (count($ifb->material))
209 foreach ($ifb->material as $material)
211 $feedbacksgeneric[0] = $material;
214 if ((count($ifb->flow_mat) > 0))
216 foreach ($ifb->flow_mat as $fmat)
218 if (count($fmat->material))
220 foreach ($fmat->material as $material)
222 $feedbacksgeneric[0] = $material;
237 $this->
object->setTitle($item->getTitle());
238 $this->
object->setNrOfTries($item->getMaxattempts());
239 $this->
object->setComment($item->getComment());
240 $this->
object->setAuthor($item->getAuthor());
241 $this->
object->setOwner($ilUser->getId());
242 $this->
object->setQuestion($this->
object->QTIMaterialToString($item->getQuestiontext()));
243 $this->
object->setObjId($questionpool_id);
245 $this->
object->setShuffleAnswersEnabled($shuffle);
246 $this->
object->setAnswerType($item->getMetadataEntry(
"answer_type"));
247 $this->
object->setOptionLabel($item->getMetadataEntry(
"option_label_setting"));
248 $this->
object->setCustomTrueOptionLabel($item->getMetadataEntry(
"custom_true_option_label"));
249 $this->
object->setCustomFalseOptionLabel($item->getMetadataEntry(
"custom_false_option_label"));
250 $this->
object->setThumbSize($item->getMetadataEntry(
"thumb_size"));
252 $this->
object->saveToDb();
254 foreach ($answers as $answerData)
257 $answer->setImageFsDir($this->
object->getImagePath());
258 $answer->setImageWebDir($this->
object->getImagePathWeb());
260 $answer->setPosition($answerData[
'answerorder']);
261 $answer->setAnswertext($answerData[
'answertext']);
262 $answer->setCorrectness($answerData[
'correctness']);
264 if( isset($answerData[
'imagefile'][
'label']) )
266 $answer->setImageFile($answerData[
'imagefile'][
'label']);
269 $this->
object->addAnswer($answer);
272 $this->
object->setAdditionalContentEditingMode(
276 $this->
object->saveToDb();
278 foreach ($answers as $answer)
280 if (is_array($answer[
"imagefile"]) && (count($answer[
"imagefile"]) > 0))
282 $image =& base64_decode($answer[
"imagefile"][
"content"]);
283 $imagepath = $this->
object->getImagePath();
284 include_once
"./Services/Utilities/classes/class.ilUtil.php";
285 if (!file_exists($imagepath))
289 $imagepath .= $answer[
"imagefile"][
"label"];
290 if(
$fh = fopen($imagepath,
"wb"))
292 $imagefile = fwrite(
$fh, $image);
298 $feedbackSetting = $item->getMetadataEntry(
'feedback_setting');
299 if( !is_null($feedbackSetting) )
301 $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->
object->getId(), $feedbackSetting);
305 foreach ($feedbacks as $ident => $material)
307 $m = $this->
object->QTIMaterialToString($material);
308 $feedbacks[$ident] = $m;
310 foreach ($feedbacksgeneric as $correctness => $material)
312 $m = $this->
object->QTIMaterialToString($material);
313 $feedbacksgeneric[$correctness] = $m;
315 $questiontext = $this->
object->getQuestion();
316 $answers =& $this->
object->getAnswers();
317 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
319 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
320 include_once
"./Services/RTE/classes/class.ilRTE.php";
321 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
332 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
336 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
337 foreach ($answers as $key => $value)
339 $answer_obj =& $answers[$key];
340 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
342 foreach ($feedbacks as $ident => $material)
344 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
346 foreach ($feedbacksgeneric as $correctness => $material)
348 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
353 foreach ($answers as $key => $value)
355 $answer_obj =& $answers[$key];
358 foreach ($feedbacks as $ident => $material)
360 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
364 foreach ($feedbacksgeneric as $correctness => $material)
366 $this->
object->feedbackOBJ->importGenericFeedback(
370 $this->
object->saveToDb();
371 if (count($item->suggested_solutions))
373 foreach ($item->suggested_solutions as $suggested_solution)
375 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
377 $this->
object->saveToDb();
381 $q_1_id = $this->
object->getId();
382 $question_id = $this->
object->duplicate(
true, null, null, null, $tst_id);
383 $tst_object->questions[$question_counter++] = $question_id;
384 $import_mapping[$item->getIdent()] =
array(
"pool" => $q_1_id,
"test" => $question_id);
388 $import_mapping[$item->getIdent()] =
array(
"pool" => $this->
object->getId(),
"test" => 0);
static makeDirParents($a_dir)
Create a new directory and all parent directories.
addGeneralMetadata(ilQTIItem $item)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir) ...
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
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...
Create styles array
The data for the language used.
Create new PHPExcel object
obj_idprivate
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
Class for question imports.