ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 (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...
 

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)
 
 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)
 
 addQuestionToParentObjectAndBuildMappingEntry (int $questionpool_id, ?int $tst_id, int &$question_counter, ?ilObjTest &$tst_object)
 

Additional Inherited Members

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

220 : array
221 {
222 $termScoringString = $item->getMetadataEntry('termscoring');
223
224 if (!strlen($termScoringString)) {
225 return [];
226 }
227
228 $termScoring = @unserialize($termScoringString, ['allowed_classes' => [ASS_AnswerMultipleResponseImage::class]]);
229
230 if (is_array($termScoring)) {
231 return $termScoring;
232 }
233
234 $termScoringString = base64_decode($termScoringString);
235 $termScoring = unserialize($termScoringString, ['allowed_classes' => [ASS_AnswerMultipleResponseImage::class]]);
236
237 if (is_array($termScoring)) {
238 return $termScoring;
239 }
240
241 return [];
242 }

References ilQTIItem\getMetadataEntry().

+ Here is the call graph for this function:

◆ fromXML()

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

Reimplemented from assQuestionImport.

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

44 : array {
45 // empty session variable for imported xhtml mobs
46 ilSession::clear('import_mob_xhtml');
47
48 $presentation = $item->getPresentation();
49 $maxchars = 0;
50 $maxpoints = 0;
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 $feedbacksgeneric = [];
66 foreach ($item->resprocessing as $resprocessing) {
67 $outcomes = $resprocessing->getOutcomes();
68 foreach ($outcomes->decvar as $decvar) {
69 $maxpoints = $decvar->getMaxvalue();
70 }
71
72 foreach ($resprocessing->respcondition as $respcondition) {
73 foreach ($respcondition->displayfeedback as $feedbackpointer) {
74 if (strlen($feedbackpointer->getLinkrefid())) {
75 foreach ($item->itemfeedback as $ifb) {
76 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
77 // found a feedback for the identifier
78 if (count($ifb->material)) {
79 foreach ($ifb->material as $material) {
80 $feedbacksgeneric[1] = $material;
81 }
82 }
83 if ((count($ifb->flow_mat) > 0)) {
84 foreach ($ifb->flow_mat as $fmat) {
85 if (count($fmat->material)) {
86 foreach ($fmat->material as $material) {
87 $feedbacksgeneric[1] = $material;
88 }
89 }
90 }
91 }
92 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
93 // found a feedback for the identifier
94 if (count($ifb->material)) {
95 foreach ($ifb->material as $material) {
96 $feedbacksgeneric[0] = $material;
97 }
98 }
99 if ((count($ifb->flow_mat) > 0)) {
100 foreach ($ifb->flow_mat as $fmat) {
101 if (count($fmat->material)) {
102 foreach ($fmat->material as $material) {
103 $feedbacksgeneric[0] = $material;
104 }
105 }
106 }
107 }
108 }
109 }
110 }
111 }
112 }
113 }
114 $this->addGeneralMetadata($item);
115 $this->object->setTitle($item->getTitle());
116 $this->object->setNrOfTries((int) $item->getMaxattempts());
117 $this->object->setComment($item->getComment());
118 $this->object->setAuthor($item->getAuthor());
119 $this->object->setOwner($user_id);
120 $this->object->setQuestion($this->QTIMaterialToString($item->getQuestiontext()));
121 $this->object->setObjId($questionpool_id);
122 $this->object->setPoints($maxpoints);
123 $this->object->setMaxNumOfChars($maxchars ?? 0);
124 $this->object->setWordCounterEnabled((bool) $item->getMetadataEntry('wordcounter'));
125 $textrating = $item->getMetadataEntry("textrating");
126 if (strlen($textrating)) {
127 $this->object->setTextRating($textrating);
128 }
129 $this->object->setMatchcondition((strlen($item->getMetadataEntry('matchcondition'))) ? (int) $item->getMetadataEntry('matchcondition') : 0);
130
131 $no_keywords_found = true;
132
133 if ($item->getMetadataEntry('termrelation') !== 'non'
134 && $item->getMetadataEntry('termrelation') !== null) {
135 $termscoring = $this->fetchTermScoring($item);
136 for ($i = 0, $iMax = count($termscoring); $i < $iMax; $i++) {
137 $this->object->addAnswer($termscoring[$i]->getAnswertext(), $termscoring[$i]->getPoints());
138 $no_keywords_found = false;
139 }
140 }
141
142 if ($item->getMetadataEntry('termrelation') !== null) {
143 $this->object->setKeywordRelation($item->getMetadataEntry('termrelation'));
144 }
145
146 $keywords = $item->getMetadataEntry("keywords");
147 if ($keywords !== null) {
148 $answers = explode(' ', $keywords);
149 foreach ($answers as $answer) {
150 $this->object->addAnswer($answer, 0);
151 }
152 $this->object->setKeywordRelation('one');
153 $no_keywords_found = false;
154 }
155 if ($no_keywords_found) {
156 $this->object->setKeywordRelation('non');
157 }
158
159 // additional content editing mode information
160 $this->object->setAdditionalContentEditingMode(
162 );
163 $this->object->saveToDb();
164 $this->importSuggestedSolutions($this->object->getId(), $item->suggested_solutions);
165 foreach ($feedbacksgeneric as $correctness => $material) {
166 $m = $this->QTIMaterialToString($material);
167 $feedbacksgeneric[$correctness] = $m;
168 }
169 // handle the import of media objects in XHTML code
170 $questiontext = $this->object->getQuestion();
171
172 $feedbacks = $this->getFeedbackAnswerSpecific($item);
173
174 if (is_array(ilSession::get("import_mob_xhtml"))) {
175 foreach (ilSession::get("import_mob_xhtml") as $mob) {
176 $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob["uri"];
177
178 global $DIC; /* @var ILIAS\DI\Container $DIC */
179 $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
180
181 $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
182 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
183 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
184 foreach ($feedbacks as $ident => $material) {
185 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
186 }
187 foreach ($feedbacksgeneric as $correctness => $material) {
188 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
189 }
190 }
191 }
192 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
193 foreach ($feedbacks as $ident => $material) {
194 $index = $this->fetchIndexFromFeedbackIdent($ident);
195
196 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
197 $this->object->getId(),
198 0,
199 $index,
201 );
202 }
203 foreach ($feedbacksgeneric as $correctness => $material) {
204 $this->object->feedbackOBJ->importGenericFeedback(
205 $this->object->getId(),
206 $correctness,
208 );
209 }
210 $this->object->saveToDb();
211 $import_mapping[$item->getIdent()] = $this->addQuestionToParentObjectAndBuildMappingEntry(
212 $questionpool_id,
213 $tst_id,
214 $question_counter,
215 $tst_object
216 );
217 return $import_mapping;
218 }
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
addQuestionToParentObjectAndBuildMappingEntry(int $questionpool_id, ?int $tst_id, int &$question_counter, ?ilObjTest &$tst_object)
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
addGeneralMetadata(ilQTIItem $item)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')
importSuggestedSolutions(int $question_id, array $solution_from_import)
static _saveTempFileAsMediaObject(string $name, string $tmp_name, bool $upload=true)
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.
getMetadataEntry(string $a_label)
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: shib_login.php:26
$response
Definition: xapitoken.php:93

References $response.

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: