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
62 $ilUser = $DIC[
'ilUser'];
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']);
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();
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] = [
104 "answertext" => $answertext,
105 "answerimage" => $answerimage,
107 "answerorder" => $ident,
112 "term" => $answertext,
113 "answerimage" => $answerimage,
126 $feedbacksgeneric = [];
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, [
"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());
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();
252 foreach ($responses as $response) {
253 $subset = $response[
"subset"];
254 foreach ($subset as $ident) {
255 if (array_key_exists($ident, $definitions)) {
256 $definition = $definitions[$ident];
258 if (array_key_exists($ident, $terms)) {
259 $term = $terms[$ident];
264 foreach ($feedbacksgeneric as $correctness => $material) {
266 $feedbacksgeneric[$correctness] = $m;
272 $questiontext = $this->
object->getQuestion();
282 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
286 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
287 foreach ($feedbacks as $ident => $material) {
288 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
290 foreach ($feedbacksgeneric as $correctness => $material) {
291 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
296 foreach ($feedbacks as $ident => $material) {
299 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
306 foreach ($feedbacksgeneric as $correctness => $material) {
307 $this->
object->feedbackOBJ->importGenericFeedback(
313 $this->
object->saveToDb();
315 $q_1_id = $this->
object->getId();
316 $question_id = $this->
object->duplicate(
true,
"",
"", -1, $tst_id);
317 $tst_object->questions[$question_counter++] = $question_id;
318 $import_mapping[$item->getIdent()] = [
"pool" => $q_1_id,
"test" => $question_id];
320 $import_mapping[$item->getIdent()] = [
"pool" => $this->
object->getId(),
"test" => 0];
322 return $import_mapping;
332 list($termId, $definitionId) = explode(
'_', str_replace($prefix,
'', $feedbackIdent));
334 foreach ($this->
object->getMatchingPairs() as $index => $pair) {
337 if ($pair->getTerm()->getIdentifier() != $termId) {
341 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)
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
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_')
importSuggestedSolutions(int $question_id, array $solution_from_import)
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) ...
Class for question imports.
static clear(string $a_var)