4 include_once
"./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
35 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
42 $presentation = $item->getPresentation();
43 $duration = $item->getDuration();
47 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
51 foreach ($presentation->order as $entry) {
52 switch ($entry[
"type"]) {
54 $response = $presentation->response[$entry[
"index"]];
58 } elseif (
$response->getIdent() ==
'OQNP') {
60 } elseif (
$response->getIdent() ==
'OQNT') {
62 } elseif (
$response->getIdent() ==
'OQT') {
67 switch (strtolower(get_class($rendertype))) {
68 case "ilqtirenderchoice":
69 $shuffle = $rendertype->getShuffle();
71 foreach ($rendertype->response_labels as $response_label) {
72 $ident = $response_label->getIdent();
74 foreach ($response_label->material as $mat) {
75 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
76 $foundmat = $mat->getMaterial($m);
78 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) {
83 $answertext .= $foundmat[
"material"]->getContent();
85 if (strcmp($foundmat[
"type"],
"matimage") == 0
86 && strcmp($foundmat[
"material"]->getLabel(),
"answerdepth") != 0) {
89 "imagetype" => $foundmat[
"material"]->getImageType(),
90 "label" => $foundmat[
"material"]->getLabel(),
91 "content" => $foundmat[
"material"]->getContent()
96 $answers[$answerorder] = array(
98 "answertext" => $answertext,
99 "answerimage" => $answerimage,
101 "answerorder" => $answerorder,
102 "answerdepth" => $answerdepth,
114 $feedbacksgeneric = array();
115 foreach ($item->resprocessing as $resprocessing) {
116 foreach ($resprocessing->respcondition as $respcondition) {
119 $conditionvar = $respcondition->getConditionvar();
120 foreach ($conditionvar->order as $order) {
121 switch ($order[
"field"]) {
126 $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
127 $orderindex = $conditionvar->varequal[$order[
"index"]]->getIndex();
131 foreach ($respcondition->setvar as $setvar) {
132 if (strcmp($ident,
"") != 0) {
133 $answers[$ident][
"solutionorder"] = $orderindex;
134 $answers[$ident][
"action"] = $setvar->getAction();
135 $answers[$ident][
"points"] = $setvar->getContent();
138 if (count($respcondition->displayfeedback)) {
139 foreach ($respcondition->displayfeedback as $feedbackpointer) {
140 if (strlen($feedbackpointer->getLinkrefid())) {
141 foreach ($item->itemfeedback as $ifb) {
142 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0) {
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 (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0) {
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;
185 $this->
object->setTitle($item->getTitle());
186 $this->
object->setNrOfTries($item->getMaxattempts());
187 $this->
object->setComment($item->getComment());
188 $this->
object->setAuthor($item->getAuthor());
189 $this->
object->setOwner(
$ilUser->getId());
190 $this->
object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
191 $this->
object->setOrderingType(
$type);
192 $this->
object->setObjId($questionpool_id);
193 $this->
object->setThumbGeometry($item->getMetadataEntry(
"thumb_geometry"));
194 $this->
object->setElementHeight($item->getMetadataEntry(
"element_height"));
195 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
196 $this->
object->setShuffle($shuffle);
197 $this->
object->saveQuestionDataToDb();
199 $solanswers = array();
201 foreach ($answers as $answer) {
202 $solanswers[$answer[
"solutionorder"]] = $answer;
206 $element_list = $this->
object->getOrderingElementList();
207 foreach ($solanswers as $answer) {
208 $points += $answer[
"points"];
212 if ($element->isExportIdent($answer[
'ident'])) {
213 $element->setExportIdent($answer[
'ident']);
215 $element = $element->withPosition($position++);
216 if (isset($answer[
'answerdepth'])) {
217 $element = $element->withIndentation((
int) $answer[
'answerdepth']);
221 if ($this->object->isImageOrderingType()) {
222 $filename = $this->handleUploadedfile($answer);
224 $element = $element->withContent(
$filename);
227 $element = $element->withContent($answer[
"answertext"]);
230 $element_list->addElement($element);
232 $this->
object->setOrderingElementList($element_list);
233 $points = ($item->getMetadataEntry(
"points") > 0) ? $item->getMetadataEntry(
"points") : $points;
234 $this->
object->setPoints($points);
236 $this->
object->setAdditionalContentEditingMode(
239 $this->
object->saveToDb();
240 if (count($item->suggested_solutions)) {
241 foreach ($item->suggested_solutions as $suggested_solution) {
242 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
244 $this->
object->saveToDb();
247 foreach ($feedbacksgeneric as $correctness => $material) {
248 $m = $this->
object->QTIMaterialToString($material);
249 $feedbacksgeneric[$correctness] = $m;
251 $questiontext = $this->
object->getQuestion();
254 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
255 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
256 include_once
"./Services/RTE/classes/class.ilRTE.php";
257 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
265 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
269 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
270 foreach ($this->object->getOrderingElementList() as $element) {
271 $element->setContent(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $element->getContent()));
273 foreach ($feedbacksgeneric as $correctness => $material) {
274 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
276 foreach ($itemfeedbacks as $ident => $material) {
277 $itemfeedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
282 foreach ($this->object->getOrderingElementList() as $element) {
285 foreach ($feedbacksgeneric as $correctness => $material) {
286 $this->
object->feedbackOBJ->importGenericFeedback(
287 $this->object->getId(),
292 foreach ($itemfeedbacks as $ident => $material) {
295 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
296 $this->object->getId(),
302 $this->
object->saveToDb();
303 if (isset($tst_id) && $tst_id !== $questionpool_id) {
304 $qplQid = $this->
object->getId();
305 $tstQid = $this->
object->duplicate(
true,
'',
'',
'', $tst_id);
306 $tst_object->questions[$question_counter++] = $tstQid;
307 $import_mapping[$item->getIdent()] = array(
"pool" => $qplQid,
"test" => $tstQid);
312 $tst_object->questions[$question_counter++] = $this->
object->getId();
313 $import_mapping[$item->getIdent()] = array(
"pool" => 0,
"test" => $this->object->getId());
316 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);
321 $image = &base64_decode($answer[
"answerimage"][
"content"]);
322 $image_file_name = $answer[
'answerimage'][
'label'];
325 $file_handle = fopen($tmp_path,
"wb");
326 if ($file_handle ===
false) {
329 fwrite($file_handle, $image);
330 fclose($file_handle);
332 $suffix = strtolower(array_pop(explode(
".", $image_file_name)));
338 $target_filename = $this->
object->buildHashedImageFilename($image_file_name,
true);
339 $target_filepath = $this->
object->getImagePath() . $target_filename;
340 if (rename($tmp_path, $target_filepath)) {
341 $thumb_path = $this->
object->getImagePath() . $this->
object->getThumbPrefix() . $target_filename;
342 if ($this->object->getThumbGeometry()) {
345 return $target_filename;
353 if (!file_exists($this->object->getImagePath())) {
static makeDirParents($a_dir)
Create a new directory and all parent directories.
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
addGeneralMetadata(ilQTIItem $item)
const VALID_UPLOAD_SUFFIXES
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 ordering question imports.
const OQ_PICTURES
Ordering question constants.
handleUploadedFile(array $answer)
static convertImage( $a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
Class for question imports.
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')