Creates a question from a QTI file.
36 {
39
40
42 $presentation = $item->getPresentation();
43 $duration = $item->getDuration();
44 $now = getdate();
45 $maxchars = 0;
46 $maxpoints = 0;
47 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
48 foreach ($presentation->order as $entry) {
49 switch ($entry["type"]) {
50 case "response":
51 $response = $presentation->response[$entry[
"index"]];
53 switch (strtolower(get_class($rendertype))) {
54 case "ilqtirenderfib":
55 $maxchars = $rendertype->getMaxchars();
56 break;
57 }
58 break;
59 }
60 }
61
62 $feedbacksgeneric = array();
63 foreach ($item->resprocessing as $resprocessing) {
64 $outcomes = $resprocessing->getOutcomes();
65 foreach ($outcomes->decvar as $decvar) {
66 $maxpoints = $decvar->getMaxvalue();
67 }
68
69 foreach ($resprocessing->respcondition as $respcondition) {
70 foreach ($respcondition->displayfeedback as $feedbackpointer) {
71 if (strlen($feedbackpointer->getLinkrefid())) {
72 foreach ($item->itemfeedback as $ifb) {
73 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
74
75 if (count($ifb->material)) {
76 foreach ($ifb->material as $material) {
77 $feedbacksgeneric[1] = $material;
78 }
79 }
80 if ((count($ifb->flow_mat) > 0)) {
81 foreach ($ifb->flow_mat as $fmat) {
82 if (count($fmat->material)) {
83 foreach ($fmat->material as $material) {
84 $feedbacksgeneric[1] = $material;
85 }
86 }
87 }
88 }
89 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
90
91 if (count($ifb->material)) {
92 foreach ($ifb->material as $material) {
93 $feedbacksgeneric[0] = $material;
94 }
95 }
96 if ((count($ifb->flow_mat) > 0)) {
97 foreach ($ifb->flow_mat as $fmat) {
98 if (count($fmat->material)) {
99 foreach ($fmat->material as $material) {
100 $feedbacksgeneric[0] = $material;
101 }
102 }
103 }
104 }
105 }
106 }
107 }
108 }
109 }
110 }
112 $this->object->setTitle($item->getTitle());
113 $this->object->setNrOfTries($item->getMaxattempts());
114 $this->object->setComment($item->getComment());
115 $this->object->setAuthor($item->getAuthor());
116 $this->
object->setOwner(
$ilUser->getId());
117 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
118 $this->object->setObjId($questionpool_id);
119 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
120 $this->object->setPoints($maxpoints);
121 $this->object->setMaxNumOfChars($maxchars);
122 $this->object->setWordCounterEnabled((bool) $item->getMetadataEntry('wordcounter'));
123 $textrating = $item->getMetadataEntry("textrating");
124 if (strlen($textrating)) {
125 $this->object->setTextRating($textrating);
126 }
127 $this->object->matchcondition = (strlen($item->getMetadataEntry('matchcondition'))) ? $item->getMetadataEntry('matchcondition') : 0;
128
129 require_once './Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php';
130 $no_keywords_found = true;
131
133 for (
$i = 0;
$i < count($termscoring);
$i++) {
134 $this->
object->addAnswer($termscoring[
$i]->getAnswertext(), $termscoring[
$i]->getPoints());
135 $no_keywords_found = false;
136 }
137 if (count($termscoring)) {
138 $this->object->setKeywordRelation($item->getMetadataEntry('termrelation'));
139 }
140
141 $keywords = $item->getMetadataEntry("keywords");
142 if (strlen($keywords)) {
143 #$this->object->setKeywords($keywords);
144 $answers = explode(' ', $keywords);
145 foreach ($answers as $answer) {
146 $this->object->addAnswer($answer, 0);
147 }
148 $this->object->setKeywordRelation('one');
149 $no_keywords_found = false;
150 }
151 if ($no_keywords_found) {
152 $this->object->setKeywordRelation('non');
153 }
154
155
156 $this->object->setAdditionalContentEditingMode(
158 );
159 $this->object->saveToDb();
160 if (count($item->suggested_solutions)) {
161 foreach ($item->suggested_solutions as $suggested_solution) {
162 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
163 }
164 $this->object->saveToDb();
165 }
166 foreach ($feedbacksgeneric as $correctness => $material) {
167 $m = $this->object->QTIMaterialToString($material);
168 $feedbacksgeneric[$correctness] = $m;
169 }
170
171 $questiontext = $this->object->getQuestion();
172
174
175 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
176 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
177 include_once "./Services/RTE/classes/class.ilRTE.php";
178 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
179 if ($tst_id > 0) {
181 } else {
183 }
184
186 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
187
190 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
191 foreach ($feedbacks as $ident => $material) {
192 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
193 }
194 foreach ($feedbacksgeneric as $correctness => $material) {
195 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
196 }
197 }
198 }
200 foreach ($feedbacks as $ident => $material) {
202
203 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
204 $this->object->getId(),
205 0,
208 );
209 }
210 foreach ($feedbacksgeneric as $correctness => $material) {
211 $this->object->feedbackOBJ->importGenericFeedback(
212 $this->object->getId(),
213 $correctness,
215 );
216 }
217 $this->object->saveToDb();
218 if ($tst_id > 0) {
219 $q_1_id = $this->object->getId();
220 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
221 $tst_object->questions[$question_counter++] = $question_id;
222 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
223 } else {
224 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
225 }
226 }
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_')
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...