ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
assNumericImport Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for assNumericImport:
+ Collaboration diagram for assNumericImport:

Public Member Functions

 fromXML (string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
 
- Public Member Functions inherited from assQuestionImport
 getQuestionId ()
 
 getFeedbackGeneric ($item)
 
 fromXML (string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
 
 importSuggestedSolutions (int $question_id, array $solution_from_import)
 
 QTIMaterialToString (ilQTIMaterial $a_material)
 Reads an QTI material tag and creates a text or XHTML string. More...
 

Additional Inherited Members

- Data Fields inherited from assQuestionImport
 $object
 
- Protected Member Functions inherited from assQuestionImport
 fetchIndexFromFeedbackIdent ($feedbackIdent, $prefix='response_')
 
 getFeedbackAnswerSpecific (ilQTIItem $item, $prefix='response_')
 
 addGeneralMetadata (ilQTIItem $item)
 
 fetchLifecycle (ilQTIItem $item)
 
 processNonAbstractedImageReferences ($text, $sourceNic)
 
 fetchAdditionalContentEditingModeInformation ($qtiItem)
 fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_CONTENT_EDITING_MODE_RTE when no or invalid information is given More...
 
 findSolutionTypeByValue (string $value)
 
 getSuggestedSolutionsRepo ()
 
 deduceThumbSizeFromImportValue (?int $size)
 
- Protected Attributes inherited from assQuestionImport
SuggestedSolutionsDatabaseRepository $suggestedsolution_repo = null
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class for numeric question imports

assNumericImport is a class for numeric question imports

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
$Id$ \

Definition at line 28 of file class.assNumericImport.php.

Member Function Documentation

◆ fromXML()

assNumericImport::fromXML ( string  $importdirectory,
int  $user_id,
ilQTIItem  $item,
int  $questionpool_id,
?int  $tst_id,
?ilObject $tst_object,
int &  $question_counter,
array  $import_mapping 
)

Definition at line 30 of file class.assNumericImport.php.

References $DIC, $response, ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), assQuestionImport\addGeneralMetadata(), ilSession\clear(), assQuestionImport\fetchAdditionalContentEditingModeInformation(), ilSession\get(), ilQTIItem\getAuthor(), ilQTIItem\getComment(), ilQTIItem\getIdent(), ilQTIItem\getMaxattempts(), ilQTIItem\getPresentation(), ilQTIItem\getQuestiontext(), ilQTIItem\getTitle(), IL_INST_ID, assQuestionImport\importSuggestedSolutions(), ILIAS\Repository\object(), and assQuestionImport\QTIMaterialToString().

39  : array {
40  // empty session variable for imported xhtml mobs
41  ilSession::clear('import_mob_xhtml');
42 
43  $presentation = $item->getPresentation();
44  $now = getdate();
45  $maxchars = 0;
46  $points = 0;
47  $upperlimit = 0;
48  $lowerlimit = 0;
49  $feedbacksgeneric = [];
50  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
51  foreach ($presentation->order as $entry) {
52  switch ($entry["type"]) {
53  case "response":
54  $response = $presentation->response[$entry["index"]];
55  $rendertype = $response->getRenderType();
56  switch (strtolower(get_class($rendertype))) {
57  case "ilqtirenderfib":
58  $maxchars = $rendertype->getMaxchars();
59  break;
60  }
61  break;
62  }
63  }
64 
65  foreach ($item->resprocessing as $resprocessing) {
66  foreach ($resprocessing->respcondition as $respcondition) {
67  $conditionvar = $respcondition->getConditionvar();
68  foreach ($conditionvar->order as $order) {
69  switch ($order["field"]) {
70  case "varlte":
71  $upperlimit = $conditionvar->varlte[$order["index"]]->getContent();
72  break;
73  case "vargte":
74  $lowerlimit = $conditionvar->vargte[$order["index"]]->getContent();
75  break;
76  }
77  }
78  foreach ($respcondition->setvar as $setvar) {
79  $points = $setvar->getContent();
80  }
81  if (count($respcondition->displayfeedback)) {
82  foreach ($respcondition->displayfeedback as $feedbackpointer) {
83  if (strlen($feedbackpointer->getLinkrefid())) {
84  foreach ($item->itemfeedback as $ifb) {
85  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
86  // found a feedback for the identifier
87  if (count($ifb->material)) {
88  foreach ($ifb->material as $material) {
89  $feedbacksgeneric[1] = $material;
90  }
91  }
92  if ((count($ifb->flow_mat) > 0)) {
93  foreach ($ifb->flow_mat as $fmat) {
94  if (count($fmat->material)) {
95  foreach ($fmat->material as $material) {
96  $feedbacksgeneric[1] = $material;
97  }
98  }
99  }
100  }
101  } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
102  // found a feedback for the identifier
103  if (count($ifb->material)) {
104  foreach ($ifb->material as $material) {
105  $feedbacksgeneric[0] = $material;
106  }
107  }
108  if ((count($ifb->flow_mat) > 0)) {
109  foreach ($ifb->flow_mat as $fmat) {
110  if (count($fmat->material)) {
111  foreach ($fmat->material as $material) {
112  $feedbacksgeneric[0] = $material;
113  }
114  }
115  }
116  }
117  }
118  }
119  }
120  }
121  }
122  }
123  }
124 
125  $this->addGeneralMetadata($item);
126  $this->object->setTitle($item->getTitle());
127  $this->object->setNrOfTries((int) $item->getMaxattempts());
128  $this->object->setComment($item->getComment());
129  $this->object->setAuthor($item->getAuthor());
130  $this->object->setOwner($user_id);
131  $this->object->setQuestion($this->QTIMaterialToString($item->getQuestiontext()));
132  $this->object->setObjId($questionpool_id);
133  $this->object->setMaxChars($maxchars);
134  $this->object->setPoints($points);
135  $this->object->setLowerLimit($lowerlimit);
136  $this->object->setUpperLimit($upperlimit);
137  // additional content editing mode information
138  $this->object->setAdditionalContentEditingMode(
140  );
141  $this->object->saveToDb();
142  $this->importSuggestedSolutions($this->object->getId(), $item->suggested_solutions);
143  foreach ($feedbacksgeneric as $correctness => $material) {
144  $m = $this->QTIMaterialToString($material);
145  $feedbacksgeneric[$correctness] = $m;
146  }
147  // handle the import of media objects in XHTML code
148  $questiontext = $this->object->getQuestion();
149  if (is_array(ilSession::get("import_mob_xhtml"))) {
150  foreach (ilSession::get("import_mob_xhtml") as $mob) {
151  $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob["uri"];
152 
153  global $DIC; /* @var ILIAS\DI\Container $DIC */
154  $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
155 
156  $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
157  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
158  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
159  foreach ($feedbacksgeneric as $correctness => $material) {
160  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
161  }
162  }
163  }
164  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
165  foreach ($feedbacksgeneric as $correctness => $material) {
166  $this->object->feedbackOBJ->importGenericFeedback(
167  $this->object->getId(),
168  $correctness,
170  );
171  }
172  $this->object->saveToDb();
173  if ($tst_id > 0) {
174  $q_1_id = $this->object->getId();
175  $question_id = $this->object->duplicate(true, "", "", -1, $tst_id);
176  $tst_object->questions[$question_counter++] = $question_id;
177  $import_mapping[$item->getIdent()] = ["pool" => $q_1_id, "test" => $question_id];
178  } else {
179  $import_mapping[$item->getIdent()] = ["pool" => $this->object->getId(), "test" => 0];
180  }
181  return $import_mapping;
182  }
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)
addGeneralMetadata(ilQTIItem $item)
const IL_INST_ID
Definition: constants.php:40
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
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.
$response
Definition: xapitoken.php:93
global $DIC
Definition: shib_login.php:22
importSuggestedSolutions(int $question_id, array $solution_from_import)
static _saveTempFileAsMediaObject(string $name, string $tmp_name, bool $upload=true)
static clear(string $a_var)
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: