ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.assTextQuestionImport.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once "./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
5
16{
30 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
31 {
32 global $DIC;
33 $ilUser = $DIC['ilUser'];
34
35 // empty session variable for imported xhtml mobs
36 unset($_SESSION["import_mob_xhtml"]);
37 $presentation = $item->getPresentation();
38 $duration = $item->getDuration();
39 $now = getdate();
40 $maxchars = 0;
41 $maxpoints = 0;
42 $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"]) {
45 case "response":
46 $response = $presentation->response[$entry["index"]];
47 $rendertype = $response->getRenderType();
48 switch (strtolower(get_class($rendertype))) {
49 case "ilqtirenderfib":
50 $maxchars = $rendertype->getMaxchars();
51 break;
52 }
53 break;
54 }
55 }
56
57 $feedbacksgeneric = array();
58 foreach ($item->resprocessing as $resprocessing) {
59 $outcomes = $resprocessing->getOutcomes();
60 foreach ($outcomes->decvar as $decvar) {
61 $maxpoints = $decvar->getMaxvalue();
62 }
63
64 foreach ($resprocessing->respcondition as $respcondition) {
65 foreach ($respcondition->displayfeedback as $feedbackpointer) {
66 if (strlen($feedbackpointer->getLinkrefid())) {
67 foreach ($item->itemfeedback as $ifb) {
68 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
69 // found a feedback for the identifier
70 if (count($ifb->material)) {
71 foreach ($ifb->material as $material) {
72 $feedbacksgeneric[1] = $material;
73 }
74 }
75 if ((count($ifb->flow_mat) > 0)) {
76 foreach ($ifb->flow_mat as $fmat) {
77 if (count($fmat->material)) {
78 foreach ($fmat->material as $material) {
79 $feedbacksgeneric[1] = $material;
80 }
81 }
82 }
83 }
84 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
85 // found a feedback for the identifier
86 if (count($ifb->material)) {
87 foreach ($ifb->material as $material) {
88 $feedbacksgeneric[0] = $material;
89 }
90 }
91 if ((count($ifb->flow_mat) > 0)) {
92 foreach ($ifb->flow_mat as $fmat) {
93 if (count($fmat->material)) {
94 foreach ($fmat->material as $material) {
95 $feedbacksgeneric[0] = $material;
96 }
97 }
98 }
99 }
100 }
101 }
102 }
103 }
104 }
105 }
106 $this->addGeneralMetadata($item);
107 $this->object->setTitle($item->getTitle());
108 $this->object->setNrOfTries($item->getMaxattempts());
109 $this->object->setComment($item->getComment());
110 $this->object->setAuthor($item->getAuthor());
111 $this->object->setOwner($ilUser->getId());
112 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
113 $this->object->setObjId($questionpool_id);
114 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
115 $this->object->setPoints($maxpoints);
116 $this->object->setMaxNumOfChars($maxchars);
117 $textrating = $item->getMetadataEntry("textrating");
118 if (strlen($textrating)) {
119 $this->object->setTextRating($textrating);
120 }
121 $this->object->matchcondition = (strlen($item->getMetadataEntry('matchcondition'))) ? $item->getMetadataEntry('matchcondition') : 0;
122
123 require_once './Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php';
124 $no_keywords_found = true;
125
126 $termscoring = $this->fetchTermScoring($item);
127 for ($i = 0; $i < count($termscoring); $i++) {
128 $this->object->addAnswer($termscoring[$i]->getAnswertext(), $termscoring[$i]->getPoints());
129 $no_keywords_found = false;
130 }
131 if (count($termscoring)) {
132 $this->object->setKeywordRelation($item->getMetadataEntry('termrelation'));
133 }
134
135 $keywords = $item->getMetadataEntry("keywords");
136 if (strlen($keywords)) {
137 #$this->object->setKeywords($keywords);
138 $answers = explode(' ', $keywords);
139 foreach ($answers as $answer) {
140 $this->object->addAnswer($answer, 0);
141 }
142 $this->object->setKeywordRelation('one');
143 $no_keywords_found = false;
144 }
145 if ($no_keywords_found) {
146 $this->object->setKeywordRelation('non');
147 }
148
149 // additional content editing mode information
150 $this->object->setAdditionalContentEditingMode(
152 );
153 $this->object->saveToDb();
154 if (count($item->suggested_solutions)) {
155 foreach ($item->suggested_solutions as $suggested_solution) {
156 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
157 }
158 $this->object->saveToDb();
159 }
160 foreach ($feedbacksgeneric as $correctness => $material) {
161 $m = $this->object->QTIMaterialToString($material);
162 $feedbacksgeneric[$correctness] = $m;
163 }
164 // handle the import of media objects in XHTML code
165 $questiontext = $this->object->getQuestion();
166
167 $feedbacks = $this->getFeedbackAnswerSpecific($item);
168
169 if (is_array($_SESSION["import_mob_xhtml"])) {
170 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
171 include_once "./Services/RTE/classes/class.ilRTE.php";
172 foreach ($_SESSION["import_mob_xhtml"] as $mob) {
173 if ($tst_id > 0) {
174 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
175 } else {
176 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
177 }
178
179 global $DIC; /* @var ILIAS\DI\Container $DIC */
180 $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
181
182 $media_object = &ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
183 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
184 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
185 foreach ($feedbacks as $ident => $material) {
186 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
187 }
188 foreach ($feedbacksgeneric as $correctness => $material) {
189 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
190 }
191 }
192 }
193 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
194 foreach ($feedbacks as $ident => $material) {
195 $index = $this->fetchIndexFromFeedbackIdent($ident);
196
197 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
198 $this->object->getId(),
199 0,
200 $index,
202 );
203 }
204 foreach ($feedbacksgeneric as $correctness => $material) {
205 $this->object->feedbackOBJ->importGenericFeedback(
206 $this->object->getId(),
207 $correctness,
209 );
210 }
211 $this->object->saveToDb();
212 if ($tst_id > 0) {
213 $q_1_id = $this->object->getId();
214 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
215 $tst_object->questions[$question_counter++] = $question_id;
216 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
217 } else {
218 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
219 }
220 }
221
222 protected function fetchTermScoring($item)
223 {
224 $termScoringString = $item->getMetadataEntry('termscoring');
225
226 if (!strlen($termScoringString)) {
227 return array();
228 }
229
230 $termScoring = unserialize($termScoringString);
231
232 if (is_array($termScoring)) {
233 return $termScoring;
234 }
235
236 $termScoringString = base64_decode($termScoringString);
237 $termScoring = unserialize($termScoringString);
238
239 if (is_array($termScoring)) {
240 return $termScoring;
241 }
242
243 return array();
244 }
245}
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
Class for question imports.
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)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')
Class for essay question imports.
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
static _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
static _saveTempFileAsMediaObject($name, $tmp_name, $upload=true)
Create new media object and update page in db and return new media object.
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...
$i
Definition: disco.tpl.php:19
$index
Definition: metadata.php:60
$response
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18