ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
assQuestionImport Class Reference

Class for question imports. More...

+ Inheritance diagram for assQuestionImport:
+ Collaboration diagram for assQuestionImport:

Public Member Functions

 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
 

Protected Member Functions

 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)
 

Protected Attributes

SuggestedSolutionsDatabaseRepository $suggestedsolution_repo = null
 

Private Attributes

Filesystem $filesystem
 

Detailed Description

Class for question imports.

assQuestionImport is a basis class 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$ \
Deprecated:
Use normalized question import instead

Definition at line 36 of file class.assQuestionImport.php.

Member Function Documentation

◆ addGeneralMetadata()

assQuestionImport::addGeneralMetadata ( ilQTIItem  $item)
protected
Parameters
ilQTIItem$item

Definition at line 196 of file class.assQuestionImport.php.

196 : void
197 {
198 if ($item->getMetadataEntry('externalID')) {
199 $this->object->setExternalId($item->getMetadataEntry('externalID'));
200 } else {
201 $this->object->setExternalId($item->getMetadataEntry('externalId'));
202 }
203
204 $this->object->setLifecycle($this->fetchLifecycle($item));
205 }
fetchLifecycle(ilQTIItem $item)
getMetadataEntry(string $a_label)

References ilQTIItem\getMetadataEntry().

+ Here is the call graph for this function:

◆ addQuestionToParentObjectAndBuildMappingEntry()

assQuestionImport::addQuestionToParentObjectAndBuildMappingEntry ( int  $questionpool_id,
?int  $tst_id,
int &  $question_counter,
?ilObjTest &  $tst_object 
)
protected

Definition at line 390 of file class.assQuestionImport.php.

395 : array {
396 if ($tst_id !== null && $tst_id === $questionpool_id) {
397 $tst_object->questions[$question_counter++] = $this->object->getId();
398 return ['pool' => 0, 'test' => $this->object->getId()];
399 }
400
401 if ($tst_id > 0) {
402 $question_id = $this->object->duplicate(true, '', '', -1, $tst_id);
403 $tst_object->questions[$question_counter++] = $question_id;
404 return ['pool' => $this->object->getId(), 'test' => $question_id];
405 }
406 return ['pool' => $this->object->getId(), 'test' => 0];
407 }

References ilObject\getId().

+ Here is the call graph for this function:

◆ deduceThumbSizeFromImportValue()

assQuestionImport::deduceThumbSizeFromImportValue ( ?int  $size)
protected

Definition at line 373 of file class.assQuestionImport.php.

373 : int
374 {
375 if ($size === null) {
376 return $this->object->getThumbSize();
377 }
378
379 if ($size < $this->object->getMinimumThumbSize()) {
380 return $this->object->getMinimumThumbSize();
381 }
382
383 if ($size > $this->object->getMaximumThumbSize()) {
384 return $this->object->getMaximumThumbSize();
385 }
386
387 return $size;
388 }

References ILIAS\Repository\object().

+ Here is the call graph for this function:

◆ fetchAdditionalContentEditingModeInformation()

assQuestionImport::fetchAdditionalContentEditingModeInformation (   $qtiItem)
finalprotected

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

@final @access protected

Returns
string $additionalContentEditingMode

Definition at line 263 of file class.assQuestionImport.php.

263 : string
264 {
265 $additionalContentEditingMode = $qtiItem->getMetadataEntry('additional_cont_edit_mode');
266
267 if (!$this->object->isValidAdditionalContentEditingMode($additionalContentEditingMode ?? '')) {
268 $additionalContentEditingMode = assQuestion::ADDITIONAL_CONTENT_EDITING_MODE_RTE;
269 }
270
271 return $additionalContentEditingMode;
272 }
const ADDITIONAL_CONTENT_EDITING_MODE_RTE

References assQuestion\ADDITIONAL_CONTENT_EDITING_MODE_RTE, and ILIAS\Repository\object().

+ Here is the call graph for this function:

◆ fetchIndexFromFeedbackIdent()

assQuestionImport::fetchIndexFromFeedbackIdent (   $feedbackIdent,
  $prefix = 'response_' 
)
protected
Parameters
$feedbackIdent
string$prefix
Returns
int

Reimplemented in assMatchingQuestionImport.

Definition at line 124 of file class.assQuestionImport.php.

124 : int
125 {
126 return (int) str_replace($prefix, '', $feedbackIdent);
127 }

◆ fetchLifecycle()

assQuestionImport::fetchLifecycle ( ilQTIItem  $item)
protected
Parameters
ilQTIItem$item
Returns
ilAssQuestionLifecycle

Definition at line 211 of file class.assQuestionImport.php.

212 {
213 try {
215 $item->getMetadataEntry('ilias_lifecycle')
216 );
218 try {
219 $lomLifecycle = new ilAssQuestionLomLifecycle(
220 $item->getMetadataEntry('lifecycle')
221 );
222
224 $lomLifecycle->getMappedIliasLifecycleIdentifer()
225 );
228 }
229 }
230
231 return $lifecycle;
232 }
$lifecycle

References Vendor\Package\$e, $lifecycle, and ilQTIItem\getMetadataEntry().

+ Here is the call graph for this function:

◆ findSolutionTypeByValue()

assQuestionImport::findSolutionTypeByValue ( string  $value)
protected

Definition at line 324 of file class.assQuestionImport.php.

324 : ?string
325 {
326 foreach (array_keys(SuggestedSolution::TYPES) as $type) {
327 $search_type = '_' . $type . '_';
328 if (strpos($value, $search_type) !== false) {
329 return $type;
330 }
331 }
332 return null;
333 }

◆ fromXML()

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

◆ getFeedbackAnswerSpecific()

assQuestionImport::getFeedbackAnswerSpecific ( ilQTIItem  $item,
  $prefix = 'response_' 
)
protected
Parameters
ilQTIItem$item
string$prefix
Returns
array

Definition at line 134 of file class.assQuestionImport.php.

134 : array
135 {
136 $feedbacks = [];
137
138 foreach ($item->itemfeedback as $ifb) {
139 if ($ifb->getIdent() == 'response_allcorrect' || $ifb->getIdent() == 'response_onenotcorrect') {
140 continue;
141 }
142
143 if ($ifb->getIdent() == $prefix . 'allcorrect' || $ifb->getIdent() == $prefix . 'onenotcorrect') {
144 continue;
145 }
146
147 if (substr($ifb->getIdent(), 0, strlen($prefix)) != $prefix) {
148 continue;
149 }
150
151 $ident = $ifb->getIdent();
152
153 // found a feedback for the identifier
154
155 if (count($ifb->material)) {
156 foreach ($ifb->material as $material) {
157 $feedbacks[$ident] = $material;
158 }
159 }
160
161 if ((count($ifb->flow_mat) > 0)) {
162 foreach ($ifb->flow_mat as $fmat) {
163 if (count($fmat->material)) {
164 foreach ($fmat->material as $material) {
165 $feedbacks[$ident] = $material;
166 }
167 }
168 }
169 }
170 }
171
172 foreach ($feedbacks as $ident => $material) {
173 $m = $this->QTIMaterialToString($material);
174 $feedbacks[$ident] = $m;
175 }
176
177 return $feedbacks;
178 }
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.

References QTIMaterialToString().

+ Here is the call graph for this function:

◆ getFeedbackGeneric()

assQuestionImport::getFeedbackGeneric (   $item)

Definition at line 65 of file class.assQuestionImport.php.

65 : array
66 {
67 $feedbacksgeneric = [];
68 foreach ($item->resprocessing as $resprocessing) {
69 foreach ($resprocessing->respcondition as $respcondition) {
70 foreach ($respcondition->displayfeedback as $feedbackpointer) {
71 if (strlen($feedbackpointer->getLinkrefid())) {
72 foreach ($item->itemfeedback as $ifb) {
73 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
74 // found a feedback for the identifier
75 if (count($ifb->material)) {
76 foreach ($ifb->material as $material) {
77 $feedbacksgeneric[1] = $material;
78 }
79 }
80 if ((count($ifb->flow_mat) > 0)) {
81 foreach ($ifb->flow_mat as $fmat) {
82 if (count($fmat->material)) {
83 foreach ($fmat->material as $material) {
84 $feedbacksgeneric[1] = $material;
85 }
86 }
87 }
88 }
89 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
90 // found a feedback for the identifier
91 if (count($ifb->material)) {
92 foreach ($ifb->material as $material) {
93 $feedbacksgeneric[0] = $material;
94 }
95 }
96 if ((count($ifb->flow_mat) > 0)) {
97 foreach ($ifb->flow_mat as $fmat) {
98 if (count($fmat->material)) {
99 foreach ($fmat->material as $material) {
100 $feedbacksgeneric[0] = $material;
101 }
102 }
103 }
104 }
105 }
106 }
107 }
108 }
109 }
110 }
111 // handle the import of media objects in XHTML code
112 foreach ($feedbacksgeneric as $correctness => $material) {
113 $m = $this->QTIMaterialToString($material);
114 $feedbacksgeneric[$correctness] = $m;
115 }
116 return $feedbacksgeneric;
117 }

References QTIMaterialToString().

+ Here is the call graph for this function:

◆ getQuestionId()

assQuestionImport::getQuestionId ( )

Definition at line 60 of file class.assQuestionImport.php.

60 : int
61 {
62 return (int) $this->object->getId();
63 }

◆ getSuggestedSolutionsRepo()

assQuestionImport::getSuggestedSolutionsRepo ( )
protected

Definition at line 337 of file class.assQuestionImport.php.

338 {
339 if (is_null($this->suggestedsolution_repo)) {
340 $dic = QuestionPoolDIC::dic();
341 $this->suggestedsolution_repo = $dic['question.repo.suggestedsolutions'];
342 }
344 }
SuggestedSolutionsDatabaseRepository $suggestedsolution_repo

References XapiProxy\$dic.

◆ importSuggestedSolutions()

assQuestionImport::importSuggestedSolutions ( int  $question_id,
array  $solution_from_import 
)

Definition at line 274 of file class.assQuestionImport.php.

277 : void {
278 if (!$solution_from_import === []
279 || !isset($solution_from_import[0]['solution'])) {
280 return;
281 }
282
283 $solution_item = $solution_from_import[0]['solution'];
284 $content = $solution_item->getContent();
285 if ($solution_item->getTexttype() === 'application/json') {
286 $content = json_decode($content, true);
287 if (!isset($content['type']) || !isset($content['value'])) {
288 return;
289 }
290 $type = $content['type'];
291 } else {
292 $type = $this->findSolutionTypeByValue($solution_item->getContent());
293 if ($type === null) {
294 return;
295 }
296 }
297
298 $repo = $this->getSuggestedSolutionsRepo();
299 $solution_object = $repo->create($question_id, $type);
300
301 if ($type !== SuggestedSolution::TYPE_FILE) {
302 $link = is_string($content) ? $content : $content['value'];
303 $adapted_link = $this->object->resolveInternalLink($link);
304 if ($adapted_link === '') {
305 return;
306 }
307 $solution_object = $solution_object
308 ->withInternalLink($adapted_link)
309 ->withImportId($link);
310 } else {
311 if (!isset($content['title']) || !isset($content['filename'])) {
312 return;
313 }
314 $path = str_replace(CLIENT_WEB_DIR . DIRECTORY_SEPARATOR, '', $this->object->getSuggestedSolutionPath() . $content['filename']);
315 $this->filesystem->put($path, base64_decode($content['value']));
316 $solution_object = $solution_object->withTitle($content['title'])
317 ->withFilename($content['filename'])
318 ->withSize((int) $this->filesystem->getSize($path, DataSize::Byte)->inBytes())
319 ->withMime($this->filesystem->getMimeType($path));
320 }
321 $repo->update([$solution_object]);
322 }
findSolutionTypeByValue(string $value)
const CLIENT_WEB_DIR
Definition: constants.php:47

◆ processNonAbstractedImageReferences()

assQuestionImport::processNonAbstractedImageReferences (   $text,
  $sourceNic 
)
protected

Definition at line 234 of file class.assQuestionImport.php.

234 : string
235 {
236 $reg = '/<img.*src=".*\\/mm_(\\d+)\\/(.*?)".*>/m';
237 $matches = null;
238
239 if (preg_match_all($reg, $text, $matches)) {
240 $mobs = [];
241 for ($i = 0, $max = count($matches[1]); $i < $max; $i++) {
242 $mobSrcId = $matches[1][$i];
243 $mobSrcName = $matches[2][$i];
244 $mobSrcLabel = 'il_' . $sourceNic . '_mob_' . $mobSrcId;
245 $mobs[] = [
246 "mob" => $mobSrcLabel, "uri" => 'objects/' . $mobSrcLabel . '/' . $mobSrcName
247 ];
248 }
249 ilSession::set('import_mob_xhtml', $mobs);
250 }
251
252 return ilRTE::_replaceMediaObjectImageSrc($text, 0, $sourceNic);
253 }
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 set(string $a_var, $a_val)
Set a value.
$text
Definition: xapiexit.php:21

References $text, ilRTE\_replaceMediaObjectImageSrc(), and ilSession\set().

+ Here is the call graph for this function:

◆ QTIMaterialToString()

assQuestionImport::QTIMaterialToString ( ilQTIMaterial  $a_material)

Reads an QTI material tag and creates a text or XHTML string.

Returns
string text or xhtml string

Definition at line 350 of file class.assQuestionImport.php.

350 : string
351 {
352 $result = '';
353 $mobs = ilSession::get('import_mob_xhtml') ?? [];
354 for ($i = 0; $i < $a_material->getMaterialCount(); $i++) {
355 $material = $a_material->getMaterial($i);
356 switch ($material['type']) {
357 case 'mattext':
358 $result .= $material['material']->getContent();
359 break;
360 case 'matimage':
361 $matimage = $material['material'];
362 if (preg_match('/^il_[0-9]+_mob_[0-9]+\z/', $matimage->getLabel()) === 1) {
363 $mobs[] = ["mob" => $matimage->getLabel(),
364 "uri" => $matimage->getUri()
365 ];
366 }
367 }
368 }
369 ilSession::set('import_mob_xhtml', $mobs);
370 return $result;
371 }
getMaterial(int $a_index)
static get(string $a_var)

References ilSession\get(), ilQTIMaterial\getMaterial(), ilQTIMaterial\getMaterialCount(), and ilSession\set().

Referenced by assImagemapQuestionImport\fromXML(), assKprimChoiceImport\fromXML(), assSingleChoiceImport\fromXML(), getFeedbackAnswerSpecific(), and getFeedbackGeneric().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $filesystem

Filesystem assQuestionImport::$filesystem
private

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

◆ $object

assQuestionImport::$object

Definition at line 41 of file class.assQuestionImport.php.

◆ $suggestedsolution_repo

SuggestedSolutionsDatabaseRepository assQuestionImport::$suggestedsolution_repo = null
protected

Definition at line 336 of file class.assQuestionImport.php.


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