ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilUser;
33
34 // empty session variable for imported xhtml mobs
35 unset($_SESSION["import_mob_xhtml"]);
36 $presentation = $item->getPresentation();
37 $duration = $item->getDuration();
38 $now = getdate();
39 $maxchars = 0;
40 $maxpoints = 0;
41 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
42 foreach ($presentation->order as $entry) {
43 switch ($entry["type"]) {
44 case "response":
45 $response = $presentation->response[$entry["index"]];
46 $rendertype = $response->getRenderType();
47 switch (strtolower(get_class($rendertype))) {
48 case "ilqtirenderfib":
49 $maxchars = $rendertype->getMaxchars();
50 break;
51 }
52 break;
53 }
54 }
55
56 $feedbacksgeneric = array();
57 foreach ($item->resprocessing as $resprocessing) {
58 $outcomes = $resprocessing->getOutcomes();
59 foreach ($outcomes->decvar as $decvar) {
60 $maxpoints = $decvar->getMaxvalue();
61 }
62
63 foreach ($resprocessing->respcondition as $respcondition) {
64 foreach ($respcondition->displayfeedback as $feedbackpointer) {
65 if (strlen($feedbackpointer->getLinkrefid())) {
66 foreach ($item->itemfeedback as $ifb) {
67 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
68 // found a feedback for the identifier
69 if (count($ifb->material)) {
70 foreach ($ifb->material as $material) {
71 $feedbacksgeneric[1] = $material;
72 }
73 }
74 if ((count($ifb->flow_mat) > 0)) {
75 foreach ($ifb->flow_mat as $fmat) {
76 if (count($fmat->material)) {
77 foreach ($fmat->material as $material) {
78 $feedbacksgeneric[1] = $material;
79 }
80 }
81 }
82 }
83 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
84 // found a feedback for the identifier
85 if (count($ifb->material)) {
86 foreach ($ifb->material as $material) {
87 $feedbacksgeneric[0] = $material;
88 }
89 }
90 if ((count($ifb->flow_mat) > 0)) {
91 foreach ($ifb->flow_mat as $fmat) {
92 if (count($fmat->material)) {
93 foreach ($fmat->material as $material) {
94 $feedbacksgeneric[0] = $material;
95 }
96 }
97 }
98 }
99 }
100 }
101 }
102 }
103 }
104 }
105 $this->addGeneralMetadata($item);
106 $this->object->setTitle($item->getTitle());
107 $this->object->setNrOfTries($item->getMaxattempts());
108 $this->object->setComment($item->getComment());
109 $this->object->setAuthor($item->getAuthor());
110 $this->object->setOwner($ilUser->getId());
111 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
112 $this->object->setObjId($questionpool_id);
113 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
114 $this->object->setPoints($maxpoints);
115 $this->object->setMaxNumOfChars($maxchars);
116 $textrating = $item->getMetadataEntry("textrating");
117 if (strlen($textrating)) {
118 $this->object->setTextRating($textrating);
119 }
120 $this->object->matchcondition = (strlen($item->getMetadataEntry('matchcondition'))) ? $item->getMetadataEntry('matchcondition') : 0;
121
122 require_once './Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php';
123 $no_keywords_found=true;
124
125 $termscoring = $this->fetchTermScoring($item);
126 for ($i = 0; $i < count($termscoring); $i++) {
127 $this->object->addAnswer($termscoring[$i]->getAnswertext(), $termscoring[$i]->getPoints());
128 $no_keywords_found=false;
129 }
130 if (count($termscoring)) {
131 $this->object->setKeywordRelation($item->getMetadataEntry('termrelation'));
132 }
133
134 $keywords = $item->getMetadataEntry("keywords");
135 if (strlen($keywords)) {
136 #$this->object->setKeywords($keywords);
137 $answers = explode(' ', $keywords);
138 foreach ($answers as $answer) {
139 $this->object->addAnswer($answer, 0);
140 }
141 $this->object->setKeywordRelation('one');
142 $no_keywords_found=false;
143 }
144 if ($no_keywords_found) {
145 $this->object->setKeywordRelation('non');
146 }
147
148 // additional content editing mode information
149 $this->object->setAdditionalContentEditingMode(
151 );
152 $this->object->saveToDb();
153 if (count($item->suggested_solutions)) {
154 foreach ($item->suggested_solutions as $suggested_solution) {
155 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
156 }
157 $this->object->saveToDb();
158 }
159 foreach ($feedbacksgeneric as $correctness => $material) {
160 $m = $this->object->QTIMaterialToString($material);
161 $feedbacksgeneric[$correctness] = $m;
162 }
163 // handle the import of media objects in XHTML code
164 $questiontext = $this->object->getQuestion();
165
166 $feedbacks = $this->getFeedbackAnswerSpecific($item);
167
168 if (is_array($_SESSION["import_mob_xhtml"])) {
169 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
170 include_once "./Services/RTE/classes/class.ilRTE.php";
171 foreach ($_SESSION["import_mob_xhtml"] as $mob) {
172 if ($tst_id > 0) {
173 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
174 } else {
175 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
176 }
177
178 $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
179
180 $media_object =&ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
181 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
182 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
183 foreach ($feedbacks as $ident => $material) {
184 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
185 }
186 foreach ($feedbacksgeneric as $correctness => $material) {
187 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
188 }
189 }
190 }
191 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
192 foreach ($feedbacks as $ident => $material) {
193 $index = $this->fetchIndexFromFeedbackIdent($ident);
194
195 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
196 $this->object->getId(),
197 $index,
199 );
200 }
201 foreach ($feedbacksgeneric as $correctness => $material) {
202 $this->object->feedbackOBJ->importGenericFeedback(
203 $this->object->getId(),
204 $correctness,
206 );
207 }
208 $this->object->saveToDb();
209 if ($tst_id > 0) {
210 $q_1_id = $this->object->getId();
211 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
212 $tst_object->questions[$question_counter++] = $question_id;
213 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
214 } else {
215 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
216 }
217 }
218
219 protected function fetchTermScoring($item)
220 {
221 $termScoringString = $item->getMetadataEntry('termscoring');
222
223 if (!strlen($termScoringString)) {
224 return array();
225 }
226
227 $termScoring = unserialize($termScoringString);
228
229 if (is_array($termScoring)) {
230 return $termScoring;
231 }
232
233 $termScoringString = base64_decode($termScoringString);
234 $termScoring = unserialize($termScoringString);
235
236 if (is_array($termScoring)) {
237 return $termScoring;
238 }
239
240 return array();
241 }
242}
sprintf('%.4f', $callTime)
$_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
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$index
Definition: metadata.php:60
$response
$ilUser
Definition: imgupload.php:18