ILIAS  release_8 Revision v8.24
class.assTextSubsetImport.php
Go to the documentation of this file.
1<?php
2
29{
43 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping): array
44 {
45 global $DIC;
46 $ilUser = $DIC['ilUser'];
47
48 // empty session variable for imported xhtml mobs
49 ilSession::clear('import_mob_xhtml');
50 ;
51 $presentation = $item->getPresentation();
52 $shuffle = 0;
53 $idents = array();
54 $now = getdate();
55 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
56 $gaps = array();
57 foreach ($presentation->order as $entry) {
58 switch ($entry["type"]) {
59 case "response":
60 $response = $presentation->response[$entry["index"]];
61 if ($response->getResponseType() == ilQTIResponse::RT_RESPONSE_STR) {
62 array_push($idents, $response->getIdent());
63 }
64 break;
65 }
66 }
67 $responses = array();
68 $feedbacksgeneric = array();
69 foreach ($item->resprocessing as $resprocessing) {
70 foreach ($resprocessing->respcondition as $respcondition) {
71 $ident = "";
72 $correctness = 1;
73 $conditionvar = $respcondition->getConditionvar();
74 foreach ($conditionvar->order as $order) {
75 switch ($order["field"]) {
76 case "varsubset":
77 $respident = $conditionvar->varsubset[$order["index"]]->getRespident();
78 $content = $conditionvar->varsubset[$order["index"]]->getContent();
79 if (!isset($responses[$respident]) || !is_array($responses[$respident])) {
80 $responses[$respident] = array();
81 }
82 $vars = explode(",", $content);
83 foreach ($vars as $var) {
84 array_push($responses[$respident], array("solution" => $var, "points" => ""));
85 }
86 break;
87 }
88 }
89 foreach ($respcondition->setvar as $setvar) {
90 if ((strcmp($setvar->getVarname(), "matches") == 0) && ($setvar->getAction() == ilQTISetvar::ACTION_ADD)) {
91 foreach ($responses[$respident] as $idx => $solutionarray) {
92 if (strlen($solutionarray["points"]) == 0) {
93 $responses[$respident][$idx]["points"] = $setvar->getContent();
94 }
95 }
96 }
97 }
98 foreach ($resprocessing->respcondition as $e_respcondition) {
99 foreach ($e_respcondition->displayfeedback as $feedbackpointer) {
100 if (strlen($feedbackpointer->getLinkrefid())) {
101 foreach ($item->itemfeedback as $ifb) {
102 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
103 // found a feedback for the identifier
104 if (count($ifb->material)) {
105 foreach ($ifb->material as $material) {
106 $feedbacksgeneric[1] = $material;
107 }
108 }
109 if ((count($ifb->flow_mat) > 0)) {
110 foreach ($ifb->flow_mat as $fmat) {
111 if (count($fmat->material)) {
112 foreach ($fmat->material as $material) {
113 $feedbacksgeneric[1] = $material;
114 }
115 }
116 }
117 }
118 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
119 // found a feedback for the identifier
120 if (count($ifb->material)) {
121 foreach ($ifb->material as $material) {
122 $feedbacksgeneric[0] = $material;
123 }
124 }
125 if ((count($ifb->flow_mat) > 0)) {
126 foreach ($ifb->flow_mat as $fmat) {
127 if (count($fmat->material)) {
128 foreach ($fmat->material as $material) {
129 $feedbacksgeneric[0] = $material;
130 }
131 }
132 }
133 }
134 }
135 }
136 }
137 }
138 }
139 }
140 }
141 $this->addGeneralMetadata($item);
142 $this->object->setTitle($item->getTitle());
143 $this->object->setNrOfTries((int) $item->getMaxattempts());
144 $this->object->setComment($item->getComment());
145 $this->object->setAuthor($item->getAuthor());
146 $this->object->setOwner($ilUser->getId());
147 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
148 $this->object->setObjId($questionpool_id);
149 $textrating = $item->getMetadataEntry("textrating");
150 if (strlen($textrating) == 0) {
151 $textrating = "ci";
152 }
153 $this->object->setTextRating($textrating);
154 $this->object->setCorrectAnswers($item->getMetadataEntry("correctanswers"));
155 $response = current($responses);
156 $counter = 0;
157 if (is_array($response)) {
158 foreach ($response as $answer) {
159 $this->object->addAnswer($answer["solution"], $answer["points"], $counter);
160 $counter++;
161 }
162 }
163 // additional content editing mode information
164 $this->object->setAdditionalContentEditingMode(
166 );
167 $this->object->saveToDb();
168 if (count($item->suggested_solutions)) {
169 foreach ($item->suggested_solutions as $suggested_solution) {
170 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
171 }
172 $this->object->saveToDb();
173 }
174 foreach ($feedbacksgeneric as $correctness => $material) {
175 $m = $this->object->QTIMaterialToString($material);
176 $feedbacksgeneric[$correctness] = $m;
177 }
178 // handle the import of media objects in XHTML code
179 $questiontext = $this->object->getQuestion();
180 if (is_array(ilSession::get("import_mob_xhtml"))) {
181 foreach (ilSession::get("import_mob_xhtml") as $mob) {
182 if ($tst_id > 0) {
183 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
184 } else {
185 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
186 }
187
188 global $DIC; /* @var ILIAS\DI\Container $DIC */
189 $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
190
191 $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
192 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
193 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
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 }
199 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
200 foreach ($feedbacksgeneric as $correctness => $material) {
201 $this->object->feedbackOBJ->importGenericFeedback(
202 $this->object->getId(),
203 $correctness,
205 );
206 }
207 $this->object->saveToDb();
208 if ($tst_id > 0) {
209 $q_1_id = $this->object->getId();
210 $question_id = $this->object->duplicate(true, "", "", "", $tst_id);
211 $tst_object->questions[$question_counter++] = $question_id;
212 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
213 } else {
214 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
215 }
216 return $import_mapping;
217 }
218}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping)
Creates a question from a QTI file.
static _saveTempFileAsMediaObject(string $name, string $tmp_name, bool $upload=true)
Create new media object and update page in db and return new media object.
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.
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)
static clear(string $a_var)
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
int $created
Timestamp for when the object was created.
Definition: System.php:151
$response