32 $image = base64_decode(
$data);
33 $imagepath = $this->
object->getImagePath();
34 if (!file_exists($imagepath)) {
38 $fh = fopen($imagepath,
"wb");
41 $imagefile = fwrite($fh, $image);
59 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping): array
66 $presentation = $item->getPresentation();
69 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
70 $definitions = array();
73 foreach ($presentation->order as $entry) {
74 switch ($entry[
"type"]) {
76 $response = $presentation->response[$entry[
"index"]];
78 switch (strtolower(get_class($rendertype))) {
79 case "ilqtirenderchoice":
80 $shuffle = $rendertype->getShuffle();
82 foreach ($rendertype->response_labels as $response_label) {
83 $ident = $response_label->getIdent();
85 $answerimage = array();
86 foreach ($response_label->material as $mat) {
87 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
88 $foundmat = $mat->getMaterial($m);
89 if (strcmp($foundmat[
"type"],
"mattext") == 0) {
90 $answertext .= $foundmat[
"material"]->getContent();
92 if (strcmp($foundmat[
"type"],
"matimage") == 0) {
95 "imagetype" => $foundmat[
"material"]->getImageType(),
96 "label" => $foundmat[
"material"]->getLabel(),
97 "content" => $foundmat[
"material"]->
getContent()
102 if (($response_label->getMatchMax() == 1) && (strlen($response_label->getMatchGroup()))) {
103 $definitions[$ident] = array(
104 "answertext" => $answertext,
105 "answerimage" => $answerimage,
107 "answerorder" => $ident,
111 $terms[$ident] = array(
112 "term" => $answertext,
113 "answerimage" => $answerimage,
125 $responses = array();
126 $feedbacksgeneric = array();
127 foreach ($item->resprocessing as $resprocessing) {
128 foreach ($resprocessing->respcondition as $respcondition) {
131 $conditionvar = $respcondition->getConditionvar();
132 foreach ($conditionvar->order as $order) {
133 switch ($order[
"field"]) {
135 $subset = explode(
",", $conditionvar->varsubset[$order[
"index"]]->getContent());
139 foreach ($respcondition->setvar as $setvar) {
140 array_push($responses, array(
"subset" => $subset,
"action" => $setvar->getAction(),
"points" => $setvar->getContent()));
143 if (count($respcondition->displayfeedback)) {
144 foreach ($respcondition->displayfeedback as $feedbackpointer) {
145 if (strlen($feedbackpointer->getLinkrefid())) {
146 foreach ($item->itemfeedback as $ifb) {
147 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0) {
149 if (count($ifb->material)) {
150 foreach ($ifb->material as $material) {
151 $feedbacksgeneric[1] = $material;
154 if ((count($ifb->flow_mat) > 0)) {
155 foreach ($ifb->flow_mat as $fmat) {
156 if (count($fmat->material)) {
157 foreach ($fmat->material as $material) {
158 $feedbacksgeneric[1] = $material;
163 } elseif (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0) {
165 if (count($ifb->material)) {
166 foreach ($ifb->material as $material) {
167 $feedbacksgeneric[0] = $material;
170 if ((count($ifb->flow_mat) > 0)) {
171 foreach ($ifb->flow_mat as $fmat) {
172 if (count($fmat->material)) {
173 foreach ($fmat->material as $material) {
174 $feedbacksgeneric[0] = $material;
187 $this->
object->createNewQuestion();
189 $this->
object->setTitle($item->getTitle());
190 $this->
object->setNrOfTries((
int) $item->getMaxattempts());
191 $this->
object->setComment($item->getComment());
192 $this->
object->setAuthor($item->getAuthor());
193 $this->
object->setOwner(
$ilUser->getId());
194 $this->
object->setQuestion($this->
object->QTIMaterialToString($item->getQuestiontext()));
195 $this->
object->setObjId($questionpool_id);
196 $extended_shuffle = $item->getMetadataEntry(
'shuffle');
197 $this->
object->setThumbGeometry(
201 if (strlen($item->getMetadataEntry(
'matching_mode'))) {
202 $this->
object->setMatchingMode($item->getMetadataEntry(
'matching_mode'));
208 foreach ($terms as $term) {
209 if (count($term[
'answerimage'])) {
210 $this->
saveImage($term[
'answerimage'][
'content'], $term[
'answerimage'][
'label']);
213 foreach ($definitions as $definition) {
214 if (count($definition[
'answerimage'])) {
215 $this->
saveImage($definition[
'answerimage'][
'content'], $definition[
'answerimage'][
'label']);
219 foreach ($terms as $termindex => $term) {
223 $this->
object->addTerm(
new assAnswerMatchingTerm($term[
"term"], $term[
'answerimage'][
'label'] ??
'', $term[
"ident"]));
225 foreach ($definitions as $definitionindex => $definition) {
226 $this->
object->addDefinition(
new assAnswerMatchingDefinition($definition[
"answertext"], $definition[
'answerimage'][
'label'] ??
'', $definition[
"answerorder"]));
229 if (strlen($extended_shuffle) > 0) {
230 $shuffle = $extended_shuffle;
232 $this->
object->setShuffle($shuffle);
235 $subset = $response[
"subset"];
236 foreach ($subset as $ident) {
237 if (array_key_exists($ident, $definitions)) {
238 $definition = $definitions[$ident];
240 if (array_key_exists($ident, $terms)) {
241 $term = $terms[$ident];
247 $this->
object->setAdditionalContentEditingMode(
250 $this->
object->saveToDb();
251 if (count($item->suggested_solutions)) {
252 foreach ($item->suggested_solutions as $suggested_solution) {
253 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->
getContent(), $suggested_solution[
"gap_index"],
true);
255 $this->
object->saveToDb();
257 foreach ($responses as $response) {
258 $subset = $response[
"subset"];
259 foreach ($subset as $ident) {
260 if (array_key_exists($ident, $definitions)) {
261 $definition = $definitions[$ident];
263 if (array_key_exists($ident, $terms)) {
264 $term = $terms[$ident];
269 foreach ($feedbacksgeneric as $correctness => $material) {
270 $m = $this->
object->QTIMaterialToString($material);
271 $feedbacksgeneric[$correctness] = $m;
277 $questiontext = $this->
object->getQuestion();
287 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
291 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
292 foreach ($feedbacks as $ident => $material) {
293 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
295 foreach ($feedbacksgeneric as $correctness => $material) {
296 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
301 foreach ($feedbacks as $ident => $material) {
304 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
311 foreach ($feedbacksgeneric as $correctness => $material) {
312 $this->
object->feedbackOBJ->importGenericFeedback(
318 $this->
object->saveToDb();
320 $q_1_id = $this->
object->getId();
321 $question_id = $this->
object->duplicate(
true,
"",
"",
"", $tst_id);
322 $tst_object->questions[$question_counter++] = $question_id;
323 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
325 $import_mapping[$item->getIdent()] = array(
"pool" => $this->
object->getId(),
"test" => 0);
327 return $import_mapping;
337 list($termId, $definitionId) = explode(
'_', str_replace($prefix,
'', $feedbackIdent));
339 foreach ($this->
object->getMatchingPairs() as
$index => $pair) {
342 if ($pair->getTerm()->getIdentifier() != $termId) {
346 if ($pair->getDefinition()->getIdentifier() != $definitionId) {
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static get(string $a_var)
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
deduceThumbSizeFromImportValue(?int $size)
addGeneralMetadata(ilQTIItem $item)
const MATCHING_MODE_1_ON_1
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir) ...
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping)
Creates a question from a QTI file.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
saveImage($data, $filename)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static clear(string $a_var)