4 include_once
"./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
30 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
36 $presentation = $item->getPresentation();
40 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
42 foreach ($presentation->order as $entry)
44 switch ($entry[
"type"])
47 $response = $presentation->response[$entry[
"index"]];
48 $rendertype = $response->getRenderType();
49 switch (strtolower(get_class($response->getRenderType())))
51 case "ilqtirenderchoice":
52 $shuffle = $rendertype->getShuffle();
55 foreach ($rendertype->response_labels as $response_label)
57 $ident = $response_label->getIdent();
59 $answerimage =
array();
60 foreach ($response_label->material as $mat)
63 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
65 $foundmat = $mat->getMaterial($m);
66 if (strcmp($foundmat[
"type"],
"mattext") == 0)
69 if (strcmp($foundmat[
"type"],
"matimage") == 0)
71 if (strlen($foundmat[
"material"]->getEmbedded()))
79 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
81 $foundmat = $mat->getMaterial($m);
82 if (strcmp($foundmat[
"type"],
"mattext") == 0)
84 $answertext .= $foundmat[
"material"]->getContent();
86 if (strcmp($foundmat[
"type"],
"matimage") == 0)
90 "imagetype" => $foundmat[
"material"]->getImageType(),
91 "label" => $foundmat[
"material"]->getLabel(),
92 "content" => $foundmat[
"material"]->getContent()
99 $answertext = $this->
object->QTIMaterialToString($mat);
102 $answers[$ident] =
array(
103 "answertext" => $answertext,
104 "imagefile" => $answerimage,
106 "answerorder" => $answerorder++,
107 "points_unchecked" => 0,
116 $responses =
array();
117 $feedbacks =
array();
118 $feedbacksgeneric =
array();
119 foreach ($item->resprocessing as $resprocessing)
121 foreach ($resprocessing->respcondition as $respcondition)
125 $conditionvar = $respcondition->getConditionvar();
126 foreach ($conditionvar->order as $order)
128 switch ($order[
"field"])
134 $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
138 foreach ($respcondition->setvar as $setvar)
140 if (strcmp($ident,
"") != 0)
144 $answers[$ident][
"action"] = $setvar->getAction();
145 $answers[$ident][
"points"] = $setvar->getContent();
146 if (count($respcondition->displayfeedback))
148 foreach ($respcondition->displayfeedback as $feedbackpointer)
150 if (strlen($feedbackpointer->getLinkrefid()))
152 foreach ($item->itemfeedback as $ifb)
154 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0)
157 if (count($ifb->material))
159 foreach ($ifb->material as $material)
161 $feedbacksgeneric[1] = $material;
164 if ((count($ifb->flow_mat) > 0))
166 foreach ($ifb->flow_mat as $fmat)
168 if (count($fmat->material))
170 foreach ($fmat->material as $material)
172 $feedbacksgeneric[1] = $material;
178 else if (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0)
181 if (count($ifb->material))
183 foreach ($ifb->material as $material)
185 $feedbacksgeneric[0] = $material;
188 if ((count($ifb->flow_mat) > 0))
190 foreach ($ifb->flow_mat as $fmat)
192 if (count($fmat->material))
194 foreach ($fmat->material as $material)
196 $feedbacksgeneric[0] = $material;
202 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0)
205 if (count($ifb->material))
207 foreach ($ifb->material as $material)
209 $feedbacks[$ident] = $material;
212 if ((count($ifb->flow_mat) > 0))
214 foreach ($ifb->flow_mat as $fmat)
216 if (count($fmat->material))
218 foreach ($fmat->material as $material)
220 $feedbacks[$ident] = $material;
233 $answers[$ident][
"action"] = $setvar->getAction();
234 $answers[$ident][
"points_unchecked"] = $setvar->getContent();
241 $this->
object->setTitle($item->getTitle());
242 $this->
object->setNrOfTries($item->getMaxattempts());
243 $this->
object->setComment($item->getComment());
244 $this->
object->setAuthor($item->getAuthor());
245 $this->
object->setOwner($ilUser->getId());
246 $this->
object->setQuestion($this->
object->QTIMaterialToString($item->getQuestiontext()));
247 $this->
object->setObjId($questionpool_id);
249 $this->
object->setShuffle($shuffle);
250 $this->
object->setThumbSize($item->getMetadataEntry(
"thumb_size"));
251 foreach ($answers as $answer)
253 if ($item->getMetadataEntry(
'singleline') || (is_array($answer[
"imagefile"]) && count($answer[
"imagefile"]) > 0))
255 $this->
object->isSingleline =
true;
257 $this->
object->addAnswer($answer[
"answertext"], $answer[
"points"], $answer[
"answerorder"], $answer[
"imagefile"][
"label"]);
260 $this->
object->setAdditionalContentEditingMode(
263 $this->
object->saveToDb();
264 foreach ($answers as $answer)
266 if (is_array($answer[
"imagefile"]) && (count($answer[
"imagefile"]) > 0))
268 $image =& base64_decode($answer[
"imagefile"][
"content"]);
269 $imagepath = $this->
object->getImagePath();
270 include_once
"./Services/Utilities/classes/class.ilUtil.php";
271 if (!file_exists($imagepath))
275 $imagepath .= $answer[
"imagefile"][
"label"];
276 $fh = fopen($imagepath,
"wb");
282 $imagefile = fwrite(
$fh, $image);
288 $feedbackSetting = $item->getMetadataEntry(
'feedback_setting');
289 if( !is_null($feedbackSetting) )
291 $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->
object->getId(), $feedbackSetting);
294 foreach ($feedbacks as $ident => $material)
296 $m = $this->
object->QTIMaterialToString($material);
297 $feedbacks[$ident] = $m;
299 foreach ($feedbacksgeneric as $correctness => $material)
301 $m = $this->
object->QTIMaterialToString($material);
302 $feedbacksgeneric[$correctness] = $m;
305 $questiontext = $this->
object->getQuestion();
306 $answers =& $this->
object->getAnswers();
307 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
309 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
310 include_once
"./Services/RTE/classes/class.ilRTE.php";
311 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
322 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
326 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
327 foreach ($answers as $key => $value)
329 $answer_obj = $answers[$key];
330 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
332 foreach ($feedbacks as $ident => $material)
334 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
336 foreach ($feedbacksgeneric as $correctness => $material)
338 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
343 foreach ($answers as $key => $value)
345 $answer_obj =& $answers[$key];
348 foreach ($feedbacks as $ident => $material)
350 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
354 foreach ($feedbacksgeneric as $correctness => $material)
356 $this->
object->feedbackOBJ->importGenericFeedback(
360 $this->
object->saveToDb();
361 if (count($item->suggested_solutions))
363 foreach ($item->suggested_solutions as $suggested_solution)
365 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
367 $this->
object->saveToDb();
371 $q_1_id = $this->
object->getId();
372 $question_id = $this->
object->duplicate(
true, null, null, null, $tst_id);
373 $tst_object->questions[$question_counter++] = $question_id;
374 $import_mapping[$item->getIdent()] =
array(
"pool" => $q_1_id,
"test" => $question_id);
378 $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) ...
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...
Class for single choice question imports.
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.
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.