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)
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);
245 foreach ($feedbacks as $ident => $material) {
246 $m = $this->
object->QTIMaterialToString($material);
247 $feedbacks[$ident] =
$m;
249 foreach ($feedbacksgeneric as $correctness => $material) {
250 $m = $this->
object->QTIMaterialToString($material);
251 $feedbacksgeneric[$correctness] =
$m;
253 $questiontext = $this->
object->getQuestion();
254 $answers = &$this->
object->getAnswers();
255 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
256 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
257 include_once
"./Services/RTE/classes/class.ilRTE.php";
258 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
266 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
270 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
271 foreach ($answers as
$key => $value) {
272 $answer_obj = &$answers[
$key];
273 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
275 foreach ($feedbacks as $ident => $material) {
276 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
278 foreach ($feedbacksgeneric as $correctness => $material) {
279 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
284 foreach ($answers as
$key => $value) {
285 $answer_obj = &$answers[
$key];
288 foreach ($feedbacks as $ident => $material) {
289 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
290 $this->object->getId(),
296 foreach ($feedbacksgeneric as $correctness => $material) {
297 $this->
object->feedbackOBJ->importGenericFeedback(
298 $this->object->getId(),
303 $this->
object->saveToDb();
304 if (count($item->suggested_solutions)) {
305 foreach ($item->suggested_solutions as $suggested_solution) {
306 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
308 $this->
object->saveToDb();
311 $q_1_id = $this->
object->getId();
312 $question_id = $this->
object->duplicate(
true, null, null, null, $tst_id);
313 $tst_object->questions[$question_counter++] = $question_id;
314 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
316 $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)
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...
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
Class for question imports.