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

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)
 

Data Fields

 $object
 
- Data Fields inherited from assQuestionImport
 $object
 

Protected Member Functions

 fetchTermScoring ($item)
 
- 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 essay question imports

assTextQuestionImport is a class for essay 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.assTextQuestionImport.php.

Member Function Documentation

◆ fetchTermScoring()

assTextQuestionImport::fetchTermScoring (   $item)
protected

Definition at line 242 of file class.assTextQuestionImport.php.

242 : array
243 {
244 $termScoringString = $item->getMetadataEntry('termscoring');
245
246 if (!strlen($termScoringString)) {
247 return array();
248 }
249
250 $termScoring = @unserialize($termScoringString, ['allowed_classes' => [ASS_AnswerMultipleResponseImage::class]]);
251
252 if (is_array($termScoring)) {
253 return $termScoring;
254 }
255
256 $termScoringString = base64_decode($termScoringString);
257 $termScoring = unserialize($termScoringString, ['allowed_classes' => [ASS_AnswerMultipleResponseImage::class]]);
258
259 if (is_array($termScoring)) {
260 return $termScoring;
261 }
262
263 return array();
264 }

Referenced by fromXML().

+ Here is the caller graph for this function:

◆ fromXML()

assTextQuestionImport::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 48 of file class.assTextQuestionImport.php.

48 : array
49 {
50 global $DIC;
51 $ilUser = $DIC['ilUser'];
52
53 // empty session variable for imported xhtml mobs
54 ilSession::clear('import_mob_xhtml');
55
56 $presentation = $item->getPresentation();
57 $now = getdate();
58 $maxchars = 0;
59 $maxpoints = 0;
60 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
61 foreach ($presentation->order as $entry) {
62 switch ($entry["type"]) {
63 case "response":
64 $response = $presentation->response[$entry["index"]];
65 $rendertype = $response->getRenderType();
66 switch (strtolower(get_class($rendertype))) {
67 case "ilqtirenderfib":
68 $maxchars = $rendertype->getMaxchars();
69 break;
70 }
71 break;
72 }
73 }
74
75 $feedbacksgeneric = array();
76 foreach ($item->resprocessing as $resprocessing) {
77 $outcomes = $resprocessing->getOutcomes();
78 foreach ($outcomes->decvar as $decvar) {
79 $maxpoints = $decvar->getMaxvalue();
80 }
81
82 foreach ($resprocessing->respcondition as $respcondition) {
83 foreach ($respcondition->displayfeedback as $feedbackpointer) {
84 if (strlen($feedbackpointer->getLinkrefid())) {
85 foreach ($item->itemfeedback as $ifb) {
86 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
87 // found a feedback for the identifier
88 if (count($ifb->material)) {
89 foreach ($ifb->material as $material) {
90 $feedbacksgeneric[1] = $material;
91 }
92 }
93 if ((count($ifb->flow_mat) > 0)) {
94 foreach ($ifb->flow_mat as $fmat) {
95 if (count($fmat->material)) {
96 foreach ($fmat->material as $material) {
97 $feedbacksgeneric[1] = $material;
98 }
99 }
100 }
101 }
102 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
103 // found a feedback for the identifier
104 if (count($ifb->material)) {
105 foreach ($ifb->material as $material) {
106 $feedbacksgeneric[0] = $material;
107 }
108 }
109 if ((count($ifb->flow_mat) > 0)) {
110 foreach ($ifb->flow_mat as $fmat) {
111 if (count($fmat->material)) {
112 foreach ($fmat->material as $material) {
113 $feedbacksgeneric[0] = $material;
114 }
115 }
116 }
117 }
118 }
119 }
120 }
121 }
122 }
123 }
124 $this->addGeneralMetadata($item);
125 $this->object->setTitle($item->getTitle());
126 $this->object->setNrOfTries((int) $item->getMaxattempts());
127 $this->object->setComment($item->getComment());
128 $this->object->setAuthor($item->getAuthor());
129 $this->object->setOwner($ilUser->getId());
130 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
131 $this->object->setObjId($questionpool_id);
132 $this->object->setPoints($maxpoints);
133 $this->object->setMaxNumOfChars($maxchars);
134 $this->object->setWordCounterEnabled((bool) $item->getMetadataEntry('wordcounter'));
135 $textrating = $item->getMetadataEntry("textrating");
136 if (strlen($textrating)) {
137 $this->object->setTextRating($textrating);
138 }
139 $this->object->setMatchcondition((strlen($item->getMetadataEntry('matchcondition'))) ? (int) $item->getMetadataEntry('matchcondition') : 0);
140
141 $no_keywords_found = true;
142
143 if ($item->getMetadataEntry('termrelation') !== 'non'
144 && $item->getMetadataEntry('termrelation') !== null) {
145 $termscoring = $this->fetchTermScoring($item);
146 for ($i = 0, $iMax = count($termscoring); $i < $iMax; $i++) {
147 $this->object->addAnswer($termscoring[$i]->getAnswertext(), $termscoring[$i]->getPoints());
148 $no_keywords_found = false;
149 }
150 }
151
152 if ($item->getMetadataEntry('termrelation') !== null) {
153 $this->object->setKeywordRelation($item->getMetadataEntry('termrelation'));
154 }
155
156 $keywords = $item->getMetadataEntry("keywords");
157 if (strlen($keywords)) {
158 #$this->object->setKeywords($keywords);
159 $answers = explode(' ', $keywords);
160 foreach ($answers as $answer) {
161 $this->object->addAnswer($answer, 0);
162 }
163 $this->object->setKeywordRelation('one');
164 $no_keywords_found = false;
165 }
166 if ($no_keywords_found) {
167 $this->object->setKeywordRelation('non');
168 }
169
170 // additional content editing mode information
171 $this->object->setAdditionalContentEditingMode(
173 );
174 $this->object->saveToDb();
175 if (count($item->suggested_solutions)) {
176 foreach ($item->suggested_solutions as $suggested_solution) {
177 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
178 }
179 $this->object->saveToDb();
180 }
181 foreach ($feedbacksgeneric as $correctness => $material) {
182 $m = $this->object->QTIMaterialToString($material);
183 $feedbacksgeneric[$correctness] = $m;
184 }
185 // handle the import of media objects in XHTML code
186 $questiontext = $this->object->getQuestion();
187
188 $feedbacks = $this->getFeedbackAnswerSpecific($item);
189
190 if (is_array(ilSession::get("import_mob_xhtml"))) {
191 foreach (ilSession::get("import_mob_xhtml") as $mob) {
192 if ($tst_id > 0) {
193 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
194 } else {
195 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
196 }
197
198 global $DIC; /* @var ILIAS\DI\Container $DIC */
199 $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
200
201 $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
202 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
203 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
204 foreach ($feedbacks as $ident => $material) {
205 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
206 }
207 foreach ($feedbacksgeneric as $correctness => $material) {
208 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
209 }
210 }
211 }
212 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
213 foreach ($feedbacks as $ident => $material) {
214 $index = $this->fetchIndexFromFeedbackIdent($ident);
215
216 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
217 $this->object->getId(),
218 0,
219 $index,
221 );
222 }
223 foreach ($feedbacksgeneric as $correctness => $material) {
224 $this->object->feedbackOBJ->importGenericFeedback(
225 $this->object->getId(),
226 $correctness,
228 );
229 }
230 $this->object->saveToDb();
231 if ($tst_id > 0) {
232 $q_1_id = $this->object->getId();
233 $question_id = $this->object->duplicate(true, "", "", "", $tst_id);
234 $tst_object->questions[$question_counter++] = $question_id;
235 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
236 } else {
237 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
238 }
239 return $import_mapping;
240 }
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir)
addGeneralMetadata(ilQTIItem $item)
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')
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 _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
$index
Definition: metadata.php:145
$i
Definition: metadata.php:41
int $created
Timestamp for when the object was created.
Definition: System.php:151
$response

References ILIAS\LTI\ToolProvider\$created, $DIC, $i, $ilUser, $index, $response, ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), assQuestionImport\addGeneralMetadata(), ilSession\clear(), assQuestionImport\fetchAdditionalContentEditingModeInformation(), assQuestionImport\fetchIndexFromFeedbackIdent(), fetchTermScoring(), ilSession\get(), ILIAS\UI\Implementation\Component\Input\ViewControl\getContent(), assQuestionImport\getFeedbackAnswerSpecific(), assQuestionImport\getQplImportArchivDirectory(), assQuestionImport\getTstImportArchivDirectory(), IL_INST_ID, and ILIAS\Repository\object().

+ Here is the call graph for this function:

Field Documentation

◆ $object

assTextQuestionImport::$object

Definition at line 33 of file class.assTextQuestionImport.php.


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