Creates a question from a QTI file.
48 {
51
52
54 $presentation = $item->getPresentation();
55 $duration = $item->getDuration();
56 $shuffle = 0;
57 $now = getdate();
58 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
59 $definitions = array();
60 $terms = array();
61 $foundimage = false;
62 foreach ($presentation->order as $entry) {
63 switch ($entry["type"]) {
64 case "response":
65 $response = $presentation->response[$entry[
"index"]];
67 switch (strtolower(get_class($rendertype))) {
68 case "ilqtirenderchoice":
69 $shuffle = $rendertype->getShuffle();
70 $answerorder = 0;
71 foreach ($rendertype->response_labels as $response_label) {
72 $ident = $response_label->getIdent();
73 $answertext = "";
74 $answerimage = array();
75 foreach ($response_label->material as $mat) {
76 for (
$m = 0;
$m < $mat->getMaterialCount();
$m++) {
77 $foundmat = $mat->getMaterial(
$m);
78 if (strcmp($foundmat["type"], "mattext") == 0) {
79 $answertext .= $foundmat["material"]->getContent();
80 }
81 if (strcmp($foundmat["type"], "matimage") == 0) {
82 $foundimage = true;
83 $answerimage = array(
84 "imagetype" => $foundmat["material"]->getImageType(),
85 "label" => $foundmat["material"]->getLabel(),
86 "content" => $foundmat["material"]->getContent()
87 );
88 }
89 }
90 }
91 if (($response_label->getMatchMax() == 1) && (strlen($response_label->getMatchGroup()))) {
92 $definitions[$ident] = array(
93 "answertext" => $answertext,
94 "answerimage" => $answerimage,
95 "points" => 0,
96 "answerorder" => $ident,
97 "action" => ""
98 );
99 } else {
100 $terms[$ident] = array(
101 "term" => $answertext,
102 "answerimage" => $answerimage,
103 "points" => 0,
104 "ident" => $ident,
105 "action" => ""
106 );
107 }
108 }
109 break;
110 }
111 break;
112 }
113 }
114 $responses = array();
115 $feedbacksgeneric = array();
116 foreach ($item->resprocessing as $resprocessing) {
117 foreach ($resprocessing->respcondition as $respcondition) {
118 $subset = array();
119 $correctness = 1;
120 $conditionvar = $respcondition->getConditionvar();
121 foreach ($conditionvar->order as $order) {
122 switch ($order["field"]) {
123 case "varsubset":
124 $subset = explode(",", $conditionvar->varsubset[$order["index"]]->getContent());
125 break;
126 }
127 }
128 foreach ($respcondition->setvar as $setvar) {
129 array_push($responses, array("subset" => $subset, "action" => $setvar->getAction(), "points" => $setvar->getContent()));
130 }
131
132 if (count($respcondition->displayfeedback)) {
133 foreach ($respcondition->displayfeedback as $feedbackpointer) {
134 if (strlen($feedbackpointer->getLinkrefid())) {
135 foreach ($item->itemfeedback as $ifb) {
136 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
137
138 if (count($ifb->material)) {
139 foreach ($ifb->material as $material) {
140 $feedbacksgeneric[1] = $material;
141 }
142 }
143 if ((count($ifb->flow_mat) > 0)) {
144 foreach ($ifb->flow_mat as $fmat) {
145 if (count($fmat->material)) {
146 foreach ($fmat->material as $material) {
147 $feedbacksgeneric[1] = $material;
148 }
149 }
150 }
151 }
152 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
153
154 if (count($ifb->material)) {
155 foreach ($ifb->material as $material) {
156 $feedbacksgeneric[0] = $material;
157 }
158 }
159 if ((count($ifb->flow_mat) > 0)) {
160 foreach ($ifb->flow_mat as $fmat) {
161 if (count($fmat->material)) {
162 foreach ($fmat->material as $material) {
163 $feedbacksgeneric[0] = $material;
164 }
165 }
166 }
167 }
168 }
169 }
170 }
171 }
172 }
173 }
174 }
175
176 include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
177 include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
178 include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
179 $this->object->createNewQuestion();
181 $this->object->setTitle($item->getTitle());
182 $this->object->setNrOfTries($item->getMaxattempts());
183 $this->object->setComment($item->getComment());
184 $this->object->setAuthor($item->getAuthor());
185 $this->
object->setOwner(
$ilUser->getId());
186 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
187 $this->object->setObjId($questionpool_id);
188 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
189 $extended_shuffle = $item->getMetadataEntry("shuffle");
190 $this->object->setThumbGeometry($item->getMetadataEntry("thumb_geometry"));
191
192 if (strlen($item->getMetadataEntry('matching_mode'))) {
193 $this->object->setMatchingMode($item->getMetadataEntry('matching_mode'));
194 } else {
196 }
197
198
199 foreach ($terms as $term) {
200 if (count($term['answerimage'])) {
201 $this->
saveImage($term[
'answerimage'][
'content'], $term[
'answerimage'][
'label']);
202 }
203 }
204 foreach ($definitions as $definition) {
205 if (count($definition['answerimage'])) {
206 $this->
saveImage($definition[
'answerimage'][
'content'], $definition[
'answerimage'][
'label']);
207 }
208 }
209
210 foreach ($terms as $termindex => $term) {
211 $this->
object->addTerm(
new assAnswerMatchingTerm($term[
"term"], $term[
'answerimage'][
'label'], $term[
"ident"]));
212 }
213 foreach ($definitions as $definitionindex => $definition) {
214 $this->
object->addDefinition(
new assAnswerMatchingDefinition($definition[
"answertext"], $definition[
'answerimage'][
'label'], $definition[
"answerorder"]));
215 }
216
217 if (strlen($extended_shuffle) > 0) {
218 $shuffle = $extended_shuffle;
219 }
220 $this->object->setShuffle($shuffle);
221
224 foreach ($subset as $ident) {
225 if (array_key_exists($ident, $definitions)) {
226 $definition = $definitions[$ident];
227 }
228 if (array_key_exists($ident, $terms)) {
229 $term = $terms[$ident];
230 }
231 }
233 }
234
235 $this->object->setAdditionalContentEditingMode(
237 );
238 $this->object->saveToDb();
239 if (count($item->suggested_solutions)) {
240 foreach ($item->suggested_solutions as $suggested_solution) {
241 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
242 }
243 $this->object->saveToDb();
244 }
247 foreach ($subset as $ident) {
248 if (array_key_exists($ident, $definitions)) {
249 $definition = $definitions[$ident];
250 }
251 if (array_key_exists($ident, $terms)) {
252 $term = $terms[$ident];
253 }
254 }
255 }
256
257 foreach ($feedbacksgeneric as $correctness => $material) {
258 $m = $this->
object->QTIMaterialToString($material);
259 $feedbacksgeneric[$correctness] =
$m;
260 }
261
263
264
265 $questiontext = $this->object->getQuestion();
266 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
267 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
268 include_once "./Services/RTE/classes/class.ilRTE.php";
269 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
270 if ($tst_id > 0) {
272 } else {
274 }
275
277 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
278
281 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
282 foreach ($feedbacks as $ident => $material) {
283 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
284 }
285 foreach ($feedbacksgeneric as $correctness => $material) {
286 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
287 }
288 }
289 }
291 foreach ($feedbacks as $ident => $material) {
293
294 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
295 $this->object->getId(),
296 0,
299 );
300 }
301 foreach ($feedbacksgeneric as $correctness => $material) {
302 $this->object->feedbackOBJ->importGenericFeedback(
303 $this->object->getId(),
304 $correctness,
306 );
307 }
308 $this->object->saveToDb();
309 if ($tst_id > 0) {
310 $q_1_id = $this->object->getId();
311 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
312 $tst_object->questions[$question_counter++] = $question_id;
313 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
314 } else {
315 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
316 }
317 }
Class for matching question definitions.
Class for matching question terms.
saveImage($data, $filename)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')
const MATCHING_MODE_1_ON_1
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir)
addGeneralMetadata(ilQTIItem $item)
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...