ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.assNumericImport.php
Go to the documentation of this file.
1<?php
2
29{
30 public function fromXML(
31 string $importdirectory,
32 int $user_id,
33 ilQTIItem $item,
34 int $questionpool_id,
35 ?int $tst_id,
36 ?ilObject &$tst_object,
37 int &$question_counter,
38 array $import_mapping
39 ): array {
40 // empty session variable for imported xhtml mobs
41 ilSession::clear('import_mob_xhtml');
42
43 $presentation = $item->getPresentation();
44 $now = getdate();
45 $maxchars = 0;
46 $points = 0;
47 $upperlimit = 0;
48 $lowerlimit = 0;
49 $feedbacksgeneric = [];
50 $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"]) {
53 case "response":
54 $response = $presentation->response[$entry["index"]];
55 $rendertype = $response->getRenderType();
56 switch (strtolower(get_class($rendertype))) {
57 case "ilqtirenderfib":
58 $maxchars = $rendertype->getMaxchars();
59 break;
60 }
61 break;
62 }
63 }
64
65 foreach ($item->resprocessing as $resprocessing) {
66 foreach ($resprocessing->respcondition as $respcondition) {
67 $conditionvar = $respcondition->getConditionvar();
68 foreach ($conditionvar->order as $order) {
69 switch ($order["field"]) {
70 case "varlte":
71 $upperlimit = $conditionvar->varlte[$order["index"]]->getContent();
72 break;
73 case "vargte":
74 $lowerlimit = $conditionvar->vargte[$order["index"]]->getContent();
75 break;
76 }
77 }
78 foreach ($respcondition->setvar as $setvar) {
79 $points = $setvar->getContent();
80 }
81 if (count($respcondition->displayfeedback)) {
82 foreach ($respcondition->displayfeedback as $feedbackpointer) {
83 if (strlen($feedbackpointer->getLinkrefid())) {
84 foreach ($item->itemfeedback as $ifb) {
85 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
86 // found a feedback for the identifier
87 if (count($ifb->material)) {
88 foreach ($ifb->material as $material) {
89 $feedbacksgeneric[1] = $material;
90 }
91 }
92 if ((count($ifb->flow_mat) > 0)) {
93 foreach ($ifb->flow_mat as $fmat) {
94 if (count($fmat->material)) {
95 foreach ($fmat->material as $material) {
96 $feedbacksgeneric[1] = $material;
97 }
98 }
99 }
100 }
101 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
102 // found a feedback for the identifier
103 if (count($ifb->material)) {
104 foreach ($ifb->material as $material) {
105 $feedbacksgeneric[0] = $material;
106 }
107 }
108 if ((count($ifb->flow_mat) > 0)) {
109 foreach ($ifb->flow_mat as $fmat) {
110 if (count($fmat->material)) {
111 foreach ($fmat->material as $material) {
112 $feedbacksgeneric[0] = $material;
113 }
114 }
115 }
116 }
117 }
118 }
119 }
120 }
121 }
122 }
123 }
124
125 $this->addGeneralMetadata($item);
126 $this->object->setTitle($item->getTitle());
127 $this->object->setNrOfTries((int) $item->getMaxattempts());
128 $this->object->setComment($item->getComment());
129 $this->object->setAuthor($item->getAuthor());
130 $this->object->setOwner($user_id);
131 $this->object->setQuestion($this->QTIMaterialToString($item->getQuestiontext()));
132 $this->object->setObjId($questionpool_id);
133 $this->object->setMaxChars($maxchars);
134 $this->object->setPoints($points);
135 $this->object->setLowerLimit($lowerlimit);
136 $this->object->setUpperLimit($upperlimit);
137 // additional content editing mode information
138 $this->object->setAdditionalContentEditingMode(
140 );
141 $this->object->saveToDb();
142 $this->importSuggestedSolutions($this->object->getId(), $item->suggested_solutions);
143 foreach ($feedbacksgeneric as $correctness => $material) {
144 $m = $this->QTIMaterialToString($material);
145 $feedbacksgeneric[$correctness] = $m;
146 }
147 // handle the import of media objects in XHTML code
148 $questiontext = $this->object->getQuestion();
149 if (is_array(ilSession::get("import_mob_xhtml"))) {
150 foreach (ilSession::get("import_mob_xhtml") as $mob) {
151 $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob["uri"];
152
153 global $DIC; /* @var ILIAS\DI\Container $DIC */
154 $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
155
156 $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
157 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
158 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
159 foreach ($feedbacksgeneric as $correctness => $material) {
160 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
161 }
162 }
163 }
164 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
165 foreach ($feedbacksgeneric as $correctness => $material) {
166 $this->object->feedbackOBJ->importGenericFeedback(
167 $this->object->getId(),
168 $correctness,
170 );
171 }
172 $this->object->saveToDb();
173 $import_mapping[$item->getIdent()] = $this->addQuestionToParentObjectAndBuildMappingEntry(
174 $questionpool_id,
175 $tst_id,
176 $question_counter,
177 $tst_object
178 );
179 return $import_mapping;
180 }
181}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
fromXML(string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
Class for question imports.
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
addQuestionToParentObjectAndBuildMappingEntry(int $questionpool_id, ?int $tst_id, int &$question_counter, ?ilObjTest &$tst_object)
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
addGeneralMetadata(ilQTIItem $item)
importSuggestedSolutions(int $question_id, array $solution_from_import)
static _saveTempFileAsMediaObject(string $name, string $tmp_name, bool $upload=true)
static _saveUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Save usage of mob within another container (e.g.
Class ilObject Basic functions for all objects.
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static get(string $a_var)
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: shib_login.php:26
$response
Definition: xapitoken.php:93