ILIAS  release_8 Revision v8.24
assFormulaQuestionImport 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 assFormulaQuestionImport:
+ Collaboration diagram for assFormulaQuestionImport:

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)
 

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...
 
 deduceThumbSizeFromImportValue (?int $size)
 

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 formula question imports

assFormulaQuestionImport is a class for formula 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
class.assFormulaQuestionImport.php 1185 2010-02-02 08:36:26Z hschottm

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

Member Function Documentation

◆ fromXML()

assFormulaQuestionImport::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 @access public

Reimplemented from assQuestionImport.

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

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 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
54
55 $feedbacksgeneric = array();
56
57 $this->object->setTitle($item->getTitle());
58 $this->object->setComment($item->getComment());
59 $this->object->setAuthor($item->getAuthor());
60 $this->object->setOwner($ilUser->getId());
61 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
62 $this->object->setObjId($questionpool_id);
63 if (preg_match_all("/(\\\$v\\d+)/ims", $this->object->getQuestion(), $matches)) {
64 foreach ($matches[1] as $variable) {
65 $data = unserialize($item->getMetadataEntry($variable), ["allowed_classes" => false]);
66 $unit = $this->object->getUnitRepository()->getUnit((int) $data["unitvalue"]);
67 $varObj = new assFormulaQuestionVariable($variable, $data["rangemin"], $data["rangemax"], $unit, $data["precision"], $data["intprecision"]);
68 $this->object->addVariable($varObj);
69 }
70 }
71 if (preg_match_all("/(\\\$r\\d+)/ims", $this->object->getQuestion(), $rmatches)) {
72 foreach ($rmatches[1] as $result) {
73 $data = unserialize($item->getMetadataEntry($result), ["allowed_classes" => false]);
74 $unit = $this->object->getUnitRepository()->getUnit((int) $data["unitvalue"]);
75 if (!is_array($data["rating"])) {
76 $resObj = new assFormulaQuestionResult($result, $data["rangemin"], $data["rangemax"], $data["tolerance"], $unit, $data["formula"], $data["points"], $data["precision"], true);
77 } else {
78 $resObj = new assFormulaQuestionResult($result, $data["rangemin"], $data["rangemax"], $data["tolerance"], $unit, $data["formula"], $data["points"], $data["precision"], false, $data["rating"]["sign"], $data["rating"]["value"], $data["rating"]["unit"]);
79 }
80 if (array_key_exists('resulttype', $data)) {
81 $resObj->setResultType($data["resulttype"]);
82 }
83 $this->object->addResult($resObj);
84 if (is_array($data["resultunits"])) {
85 foreach ($data["resultunits"] as $resu) {
86 $ru = $this->object->getUnitRepository()->getUnit($resu["unitvalue"]);
87 if (is_object($ru)) {
88 $this->object->addResultUnit($resObj, $ru);
89 }
90 }
91 }
92 }
93 }
94 $this->object->setPoints($item->getMetadataEntry("points"));
95 $this->addGeneralMetadata($item);
96 // additional content editing mode information
97 $this->object->setAdditionalContentEditingMode(
99 );
100 $this->object->saveToDb();
101 // handle the import of media objects in XHTML code
102 $questiontext = $this->object->getQuestion();
103 $feedbacksgeneric = $this->getFeedbackGeneric($item);
104
105 if (is_array(ilSession::get("import_mob_xhtml"))) {
106 foreach (ilSession::get("import_mob_xhtml") as $mob) {
107 if ($tst_id > 0) {
108 $importfile = ilObjTest::_getImportDirectory() . "/" . ilSession::get("tst_import_subdir") . "/" . $mob["uri"];
109 } else {
110 $importfile = ilObjQuestionPool::_getImportDirectory() . "/" . ilSession::get("qpl_import_subdir") . "/" . $mob["uri"];
111 }
112 $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
113 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
114 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
115
116 foreach ($feedbacksgeneric as $correctness => $material) {
117 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
118 }
119 }
120 }
121 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
122
123 foreach ($feedbacksgeneric as $correctness => $material) {
124 $this->object->feedbackOBJ->importGenericFeedback(
125 $this->object->getId(),
126 $correctness,
128 );
129 }
130
131 // additional content editing mode information
132 $this->object->setAdditionalContentEditingMode(
134 );
135
136 $this->object->saveToDb();
137 if (count($item->suggested_solutions)) {
138 foreach ($item->suggested_solutions as $suggested_solution) {
139 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
140 }
141 $this->object->saveToDb();
142 }
143 if ($tst_id > 0) {
144 $q_1_id = $this->object->getId();
145 $question_id = $this->object->duplicate();
146 $tst_object->questions[$question_counter++] = $question_id;
147 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
148 } else {
149 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
150 }
151 return $import_mapping;
152 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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_...
addGeneralMetadata(ilQTIItem $item)
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 _getImportDirectory()
get import directory of lm
static _getImportDirectory()
Get the import directory location of the test.
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

References ILIAS\LTI\ToolProvider\$created, $data, $DIC, $ilUser, ilObjTest\_getImportDirectory(), ilObjQuestionPool\_getImportDirectory(), ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), assQuestionImport\addGeneralMetadata(), ilSession\clear(), assQuestionImport\fetchAdditionalContentEditingModeInformation(), ilSession\get(), ILIAS\UI\Implementation\Component\Input\ViewControl\getContent(), assQuestionImport\getFeedbackGeneric(), IL_INST_ID, and ILIAS\Repository\object().

+ Here is the call graph for this function:

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