ILIAS  trunk Revision v5.2.0beta1-34132-g2d4d73d4a0
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 (&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping)
 Creates a question from a QTI file. More...
 
- Public Member Functions inherited from assQuestionImport
 __construct ($a_object)
 assQuestionImport constructor More...
 
 getQuestionId ()
 
 getFeedbackGeneric ($item)
 
 fromXML (&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping)
 Creates a question from a QTI file. More...
 
 importSuggestedSolution (int $question_id, string $value="", int $subquestion_index=0)
 
 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)
 
 getQplImportArchivDirectory ()
 returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir) More...
 
 getTstImportArchivDirectory ()
 returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) More...
 
 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 ()
 
- Protected Attributes inherited from assQuestionImport
assQuestionSuggestedSolutionsDatabaseRepository $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 ( $item,
  $questionpool_id,
$tst_id,
$tst_object,
$question_counter,
  $import_mapping 
)

Creates a question from a QTI file.

Receives parameters from a QTI parser and creates a valid ILIAS question object

Parameters
ilQtiItem$itemThe QTI item object
integer$questionpool_idThe id of the parent questionpool
integer$tst_idThe id of the parent test if the question is part of a test
object$tst_objectA reference to the parent test object
integer$question_counterA reference to a question counter to count the questions of an imported question pool
array$import_mappingAn array containing references to included ILIAS objects public

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

References ILIAS\LTI\ToolProvider\$created, $DIC, $response, ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), assQuestionImport\addGeneralMetadata(), ilSession\clear(), assQuestionImport\fetchAdditionalContentEditingModeInformation(), ilSession\get(), assQuestionImport\getQplImportArchivDirectory(), assQuestionImport\getTstImportArchivDirectory(), IL_INST_ID, assQuestionImport\importSuggestedSolution(), ILIAS\Repository\object(), and assQuestionImport\QTIMaterialToString().

43  : 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  $now = getdate();
53  $maxchars = 0;
54  $points = 0;
55  $upperlimit = 0;
56  $lowerlimit = 0;
57  $feedbacksgeneric = [];
58  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
59  foreach ($presentation->order as $entry) {
60  switch ($entry["type"]) {
61  case "response":
62  $response = $presentation->response[$entry["index"]];
63  $rendertype = $response->getRenderType();
64  switch (strtolower(get_class($rendertype))) {
65  case "ilqtirenderfib":
66  $maxchars = $rendertype->getMaxchars();
67  break;
68  }
69  break;
70  }
71  }
72 
73  foreach ($item->resprocessing as $resprocessing) {
74  foreach ($resprocessing->respcondition as $respcondition) {
75  $conditionvar = $respcondition->getConditionvar();
76  foreach ($conditionvar->order as $order) {
77  switch ($order["field"]) {
78  case "varlte":
79  $upperlimit = $conditionvar->varlte[$order["index"]]->getContent();
80  break;
81  case "vargte":
82  $lowerlimit = $conditionvar->vargte[$order["index"]]->getContent();
83  break;
84  }
85  }
86  foreach ($respcondition->setvar as $setvar) {
87  $points = $setvar->getContent();
88  }
89  if (count($respcondition->displayfeedback)) {
90  foreach ($respcondition->displayfeedback as $feedbackpointer) {
91  if (strlen($feedbackpointer->getLinkrefid())) {
92  foreach ($item->itemfeedback as $ifb) {
93  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
94  // found a feedback for the identifier
95  if (count($ifb->material)) {
96  foreach ($ifb->material as $material) {
97  $feedbacksgeneric[1] = $material;
98  }
99  }
100  if ((count($ifb->flow_mat) > 0)) {
101  foreach ($ifb->flow_mat as $fmat) {
102  if (count($fmat->material)) {
103  foreach ($fmat->material as $material) {
104  $feedbacksgeneric[1] = $material;
105  }
106  }
107  }
108  }
109  } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
110  // found a feedback for the identifier
111  if (count($ifb->material)) {
112  foreach ($ifb->material as $material) {
113  $feedbacksgeneric[0] = $material;
114  }
115  }
116  if ((count($ifb->flow_mat) > 0)) {
117  foreach ($ifb->flow_mat as $fmat) {
118  if (count($fmat->material)) {
119  foreach ($fmat->material as $material) {
120  $feedbacksgeneric[0] = $material;
121  }
122  }
123  }
124  }
125  }
126  }
127  }
128  }
129  }
130  }
131  }
132 
133  $this->addGeneralMetadata($item);
134  $this->object->setTitle($item->getTitle());
135  $this->object->setNrOfTries((int) $item->getMaxattempts());
136  $this->object->setComment($item->getComment());
137  $this->object->setAuthor($item->getAuthor());
138  $this->object->setOwner($ilUser->getId());
139  $this->object->setQuestion($this->QTIMaterialToString($item->getQuestiontext()));
140  $this->object->setObjId($questionpool_id);
141  $this->object->setMaxChars($maxchars);
142  $this->object->setPoints($points);
143  $this->object->setLowerLimit($lowerlimit);
144  $this->object->setUpperLimit($upperlimit);
145  // additional content editing mode information
146  $this->object->setAdditionalContentEditingMode(
148  );
149  $this->object->saveToDb();
150  if (count($item->suggested_solutions)) {
151  foreach ($item->suggested_solutions as $suggested_solution) {
153  $this->object->getId(),
154  $suggested_solution["solution"]->getContent(),
155  $suggested_solution["gap_index"]
156  );
157  }
158  }
159  foreach ($feedbacksgeneric as $correctness => $material) {
160  $m = $this->QTIMaterialToString($material);
161  $feedbacksgeneric[$correctness] = $m;
162  }
163  // handle the import of media objects in XHTML code
164  $questiontext = $this->object->getQuestion();
165  if (is_array(ilSession::get("import_mob_xhtml"))) {
166  foreach (ilSession::get("import_mob_xhtml") as $mob) {
167  if ($tst_id > 0) {
168  $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
169  } else {
170  $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
171  }
172 
173  global $DIC; /* @var ILIAS\DI\Container $DIC */
174  $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
175 
176  $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
177  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
178  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
179  foreach ($feedbacksgeneric as $correctness => $material) {
180  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
181  }
182  }
183  }
184  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
185  foreach ($feedbacksgeneric as $correctness => $material) {
186  $this->object->feedbackOBJ->importGenericFeedback(
187  $this->object->getId(),
188  $correctness,
190  );
191  }
192  $this->object->saveToDb();
193  if ($tst_id > 0) {
194  $q_1_id = $this->object->getId();
195  $question_id = $this->object->duplicate(true, "", "", -1, $tst_id);
196  $tst_object->questions[$question_counter++] = $question_id;
197  $import_mapping[$item->getIdent()] = ["pool" => $q_1_id, "test" => $question_id];
198  } else {
199  $import_mapping[$item->getIdent()] = ["pool" => $this->object->getId(), "test" => 0];
200  }
201  return $import_mapping;
202  }
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
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir) ...
$DIC
Definition: xapitoken.php:62
static _saveTempFileAsMediaObject(string $name, string $tmp_name, bool $upload=true)
Create new media object and update page in db and return new media object.
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
importSuggestedSolution(int $question_id, string $value="", int $subquestion_index=0)
static clear(string $a_var)
int $created
Timestamp for when the object was created.
Definition: System.php:151
+ Here is the call graph for this function:

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