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();
37 $duration = $item->getDuration();
41 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
45 foreach ($presentation->order as $entry)
47 switch ($entry[
"type"])
50 $response = $presentation->response[$entry[
"index"]];
51 $type = $response->getIdent();
52 if($response->getIdent() ==
'OQP' )
54 else if($response->getIdent() ==
'OQNP')
56 else if($response->getIdent() ==
'OQNT')
58 else if($response->getIdent() ==
'OQT')
61 $rendertype = $response->getRenderType();
62 switch (strtolower(get_class($rendertype)))
64 case "ilqtirenderchoice":
65 $shuffle = $rendertype->getShuffle();
67 foreach ($rendertype->response_labels as $response_label)
69 $ident = $response_label->getIdent();
71 foreach ($response_label->material as $mat)
73 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
75 $foundmat = $mat->getMaterial($m);
77 if (strcmp($foundmat[
"material"]->getLabel(),
"answerdepth") == 0)
79 $answerdepth = $foundmat[
"material"]->getContent();
81 if (strcmp($foundmat[
"type"],
"mattext") == 0
82 && strcmp($foundmat[
"material"]->getLabel(),
"answerdepth") != 0)
84 $answertext .= $foundmat[
"material"]->getContent();
86 if (strcmp($foundmat[
"type"],
"matimage") == 0
87 && strcmp($foundmat[
"material"]->getLabel(),
"answerdepth") != 0)
91 "imagetype" => $foundmat[
"material"]->getImageType(),
92 "label" => $foundmat[
"material"]->getLabel(),
93 "content" => $foundmat[
"material"]->getContent()
98 $answers[$ident] = array(
99 "answertext" => $answertext,
100 "answerimage" => $answerimage,
102 "answerorder" => $answerorder++,
103 "answerdepth" => $answerdepth,
113 $responses = array();
114 $feedbacksgeneric = array();
115 foreach ($item->resprocessing as $resprocessing)
117 foreach ($resprocessing->respcondition as $respcondition)
121 $conditionvar = $respcondition->getConditionvar();
122 foreach ($conditionvar->order as $order)
124 switch ($order[
"field"])
130 $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
131 $orderindex = $conditionvar->varequal[$order[
"index"]]->getIndex();
135 foreach ($respcondition->setvar as $setvar)
137 if (strcmp($ident,
"") != 0)
139 $answers[$ident][
"solutionorder"] = $orderindex;
140 $answers[$ident][
"action"] = $setvar->getAction();
141 $answers[$ident][
"points"] = $setvar->getContent();
144 if (count($respcondition->displayfeedback))
146 foreach ($respcondition->displayfeedback as $feedbackpointer)
148 if (strlen($feedbackpointer->getLinkrefid()))
150 foreach ($item->itemfeedback as $ifb)
152 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0)
155 if (count($ifb->material))
157 foreach ($ifb->material as $material)
159 $feedbacksgeneric[1] = $material;
162 if ((count($ifb->flow_mat) > 0))
164 foreach ($ifb->flow_mat as $fmat)
166 if (count($fmat->material))
168 foreach ($fmat->material as $material)
170 $feedbacksgeneric[1] = $material;
176 else if (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0)
179 if (count($ifb->material))
181 foreach ($ifb->material as $material)
183 $feedbacksgeneric[0] = $material;
186 if ((count($ifb->flow_mat) > 0))
188 foreach ($ifb->flow_mat as $fmat)
190 if (count($fmat->material))
192 foreach ($fmat->material as $material)
194 $feedbacksgeneric[0] = $material;
208 $this->
object->setTitle($item->getTitle());
209 $this->
object->setNrOfTries($item->getMaxattempts());
210 $this->
object->setComment($item->getComment());
211 $this->
object->setAuthor($item->getAuthor());
212 $this->
object->setOwner($ilUser->getId());
213 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
214 $this->
object->setOrderingType($type);
215 $this->
object->setObjId($questionpool_id);
216 $this->
object->setThumbGeometry($item->getMetadataEntry(
"thumb_geometry"));
217 $this->
object->setElementHeight($item->getMetadataEntry(
"element_height"));
218 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
219 $this->
object->setShuffle($shuffle);
221 $solanswers = array();
223 foreach ($answers as $answer)
225 $solanswers[$answer[
"solutionorder"]] = $answer;
228 foreach ($solanswers as $answer)
230 $points += $answer[
"points"];
233 $this->
object->addAnswer($answer[
"answertext"], -1, $answer[
'answerdepth']);
237 $this->
object->addAnswer($answer[
"answerimage"][
"label"], -1, $answer[
'answerdepth']);
240 $points = ($item->getMetadataEntry(
"points") > 0) ? $item->getMetadataEntry(
"points") : $points;
241 $this->
object->setPoints($points);
243 $this->
object->setAdditionalContentEditingMode(
246 $this->
object->saveToDb();
247 if (count($item->suggested_solutions))
249 foreach ($item->suggested_solutions as $suggested_solution)
251 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
253 $this->
object->saveToDb();
255 foreach ($answers as $answer)
259 include_once
"./Services/Utilities/classes/class.ilUtil.php";
260 $image =& base64_decode($answer[
"answerimage"][
"content"]);
261 $imagepath = $this->
object->getImagePath();
262 if (!file_exists($imagepath))
266 $imagepath .= $answer[
"answerimage"][
"label"];
267 $fh = fopen($imagepath,
"wb");
276 $imagefile = fwrite($fh, $image);
280 $thumbpath = $imagepath .
"." .
"thumb.jpg";
284 foreach ($feedbacksgeneric as $correctness => $material)
286 $m = $this->
object->QTIMaterialToString($material);
287 $feedbacksgeneric[$correctness] = $m;
289 $questiontext = $this->
object->getQuestion();
290 $answers =& $this->
object->getAnswers();
292 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
294 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
295 include_once
"./Services/RTE/classes/class.ilRTE.php";
296 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
307 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
311 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
312 foreach ($answers as $key => $value)
314 $answer_obj =& $answers[$key];
315 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
317 foreach ($feedbacksgeneric as $correctness => $material)
319 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
324 foreach ($answers as $key => $value)
326 $answer_obj =& $answers[$key];
329 foreach ($feedbacksgeneric as $correctness => $material)
331 $this->
object->feedbackOBJ->importGenericFeedback(
335 $this->
object->saveToDb();
338 $q_1_id = $this->
object->getId();
339 $question_id = $this->
object->duplicate(
true, null, null, null, $tst_id);
340 $tst_object->questions[$question_counter++] = $question_id;
341 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
345 $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) ...
Class for ordering question imports.
const OQ_PICTURES
Ordering question constants.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0)
replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
static convertImage($a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
Class for question imports.