4 include_once
"./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
30 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
36 $presentation = $item->getPresentation();
37 $duration = $item->getDuration();
39 $selectionLimit = null;
41 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
43 foreach ($presentation->order as $entry) {
44 switch ($entry[
"type"]) {
46 $response = $presentation->response[$entry[
"index"]];
48 switch (strtolower(get_class(
$response->getRenderType()))) {
49 case "ilqtirenderchoice":
50 $shuffle = $rendertype->getShuffle();
51 if ($rendertype->getMaxnumber()) {
52 $selectionLimit = $rendertype->getMaxnumber();
56 foreach ($rendertype->response_labels as $response_label) {
57 $ident = $response_label->getIdent();
59 $answerimage = array();
60 foreach ($response_label->material as $mat) {
62 for (
$m = 0;
$m < $mat->getMaterialCount();
$m++) {
63 $foundmat = $mat->getMaterial(
$m);
64 if (strcmp($foundmat[
"type"],
"mattext") == 0) {
66 if (strcmp($foundmat[
"type"],
"matimage") == 0) {
67 if (strlen($foundmat[
"material"]->getEmbedded())) {
73 for (
$m = 0;
$m < $mat->getMaterialCount();
$m++) {
74 $foundmat = $mat->getMaterial(
$m);
75 if (strcmp($foundmat[
"type"],
"mattext") == 0) {
76 $answertext .= $foundmat[
"material"]->getContent();
78 if (strcmp($foundmat[
"type"],
"matimage") == 0) {
81 "imagetype" => $foundmat[
"material"]->getImageType(),
82 "label" => $foundmat[
"material"]->getLabel(),
83 "content" => $foundmat[
"material"]->getContent()
88 $answertext = $this->
object->QTIMaterialToString($mat);
91 $answers[$ident] = array(
92 "answertext" => $answertext,
93 "imagefile" => $answerimage,
95 "answerorder" => $answerorder++,
96 "points_unchecked" => 0,
105 $responses = array();
106 $feedbacks = array();
107 $feedbacksgeneric = array();
108 foreach ($item->resprocessing as $resprocessing) {
109 foreach ($resprocessing->respcondition as $respcondition) {
112 $conditionvar = $respcondition->getConditionvar();
113 foreach ($conditionvar->order as $order) {
114 switch ($order[
"field"]) {
119 $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
123 foreach ($respcondition->setvar as $setvar) {
124 if (strcmp($ident,
"") != 0) {
126 $answers[$ident][
"action"] = $setvar->getAction();
127 $answers[$ident][
"points"] = $setvar->getContent();
128 if (count($respcondition->displayfeedback)) {
129 foreach ($respcondition->displayfeedback as $feedbackpointer) {
130 if (strlen($feedbackpointer->getLinkrefid())) {
131 foreach ($item->itemfeedback as $ifb) {
132 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0) {
134 if (count($ifb->material)) {
135 foreach ($ifb->material as $material) {
136 $feedbacksgeneric[1] = $material;
139 if ((count($ifb->flow_mat) > 0)) {
140 foreach ($ifb->flow_mat as $fmat) {
141 if (count($fmat->material)) {
142 foreach ($fmat->material as $material) {
143 $feedbacksgeneric[1] = $material;
148 } elseif (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0) {
150 if (count($ifb->material)) {
151 foreach ($ifb->material as $material) {
152 $feedbacksgeneric[0] = $material;
155 if ((count($ifb->flow_mat) > 0)) {
156 foreach ($ifb->flow_mat as $fmat) {
157 if (count($fmat->material)) {
158 foreach ($fmat->material as $material) {
159 $feedbacksgeneric[0] = $material;
165 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
167 if (count($ifb->material)) {
168 foreach ($ifb->material as $material) {
169 $feedbacks[$ident] = $material;
172 if ((count($ifb->flow_mat) > 0)) {
173 foreach ($ifb->flow_mat as $fmat) {
174 if (count($fmat->material)) {
175 foreach ($fmat->material as $material) {
176 $feedbacks[$ident] = $material;
187 $answers[$ident][
"action"] = $setvar->getAction();
188 $answers[$ident][
"points_unchecked"] = $setvar->getContent();
195 $this->
object->setTitle($item->getTitle());
196 $this->
object->setNrOfTries($item->getMaxattempts());
197 $this->
object->setComment($item->getComment());
198 $this->
object->setAuthor($item->getAuthor());
199 $this->
object->setOwner(
$ilUser->getId());
200 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
201 $this->
object->setObjId($questionpool_id);
202 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
203 $this->
object->setShuffle($shuffle);
204 $this->
object->setSelectionLimit($selectionLimit);
205 $this->
object->setThumbSize($item->getMetadataEntry(
"thumb_size"));
207 foreach ($answers as $answer) {
208 if ($item->getMetadataEntry(
'singleline') || (is_array($answer[
"imagefile"]) && count($answer[
"imagefile"]) > 0)) {
209 $this->
object->isSingleline =
true;
211 $this->
object->addAnswer($answer[
"answertext"], $answer[
"points"], $answer[
"points_unchecked"], $answer[
"answerorder"], $answer[
"imagefile"][
"label"]);
214 $this->
object->setAdditionalContentEditingMode(
217 $this->
object->saveToDb();
218 foreach ($answers as $answer) {
219 if (is_array($answer[
"imagefile"]) && (count($answer[
"imagefile"]) > 0)) {
220 $image = &base64_decode($answer[
"imagefile"][
"content"]);
221 $imagepath = $this->
object->getImagePath();
222 include_once
"./Services/Utilities/classes/class.ilUtil.php";
223 if (!file_exists($imagepath)) {
226 $imagepath .= $answer[
"imagefile"][
"label"];
227 $fh =
fopen($imagepath,
"wb");
230 $imagefile = fwrite($fh, $image);
236 $feedbackSetting = $item->getMetadataEntry(
'feedback_setting');
237 if (!is_null($feedbackSetting)) {
238 $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting);
242 foreach ($feedbacks as $ident => $material) {
243 $m = $this->
object->QTIMaterialToString($material);
244 $feedbacks[$ident] =
$m;
246 foreach ($feedbacksgeneric as $correctness => $material) {
247 $m = $this->
object->QTIMaterialToString($material);
248 $feedbacksgeneric[$correctness] =
$m;
250 $questiontext = $this->
object->getQuestion();
251 $answers = &$this->
object->getAnswers();
252 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
253 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
254 include_once
"./Services/RTE/classes/class.ilRTE.php";
255 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
263 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
267 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
268 foreach ($answers as
$key => $value) {
269 $answer_obj = &$answers[
$key];
270 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
272 foreach ($feedbacks as $ident => $material) {
273 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
275 foreach ($feedbacksgeneric as $correctness => $material) {
276 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
281 foreach ($answers as
$key => $value) {
282 $answer_obj = &$answers[
$key];
285 foreach ($feedbacks as $ident => $material) {
286 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
287 $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);
static makeDirParents($a_dir)
Create a new directory and all parent directories.
addGeneralMetadata(ilQTIItem $item)
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
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 multiple choice question imports.
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
Class for question imports.