ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
assQuestionImport Class Reference

Class for question imports. More...

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

Public Member Functions

 getQuestionId ()
 
 getFeedbackGeneric ($item)
 
 fromXML (&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping)
 Creates a question from a QTI file. More...
 
 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)
 
 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 ()
 
 deduceThumbSizeFromImportValue (?int $size)
 

Protected Attributes

assQuestionSuggestedSolutionsDatabaseRepository $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$

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

Member Function Documentation

◆ addGeneralMetadata()

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

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

References fetchLifecycle(), and ilQTIItem\getMetadataEntry().

Referenced by assKprimChoiceImport\fromXML(), assLongMenuImport\fromXML(), assFileUploadImport\fromXML(), assErrorTextImport\fromXML(), assClozeTestImport\fromXML(), assOrderingHorizontalImport\fromXML(), assNumericImport\fromXML(), assFormulaQuestionImport\fromXML(), assMultipleChoiceImport\fromXML(), assTextSubsetImport\fromXML(), assImagemapQuestionImport\fromXML(), assSingleChoiceImport\fromXML(), assOrderingQuestionImport\fromXML(), assTextQuestionImport\fromXML(), and assMatchingQuestionImport\fromXML().

197  : void
198  {
199  if ($item->getMetadataEntry('externalID')) {
200  $this->object->setExternalId($item->getMetadataEntry('externalID'));
201  } else {
202  $this->object->setExternalId($item->getMetadataEntry('externalId'));
203  }
204 
205  $this->object->setLifecycle($this->fetchLifecycle($item));
206  }
getMetadataEntry(string $a_label)
fetchLifecycle(ilQTIItem $item)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deduceThumbSizeFromImportValue()

assQuestionImport::deduceThumbSizeFromImportValue ( ?int  $size)
protected

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

References ILIAS\Repository\object().

Referenced by assKprimChoiceImport\fromXML(), assSingleChoiceImport\fromXML(), assMultipleChoiceImport\fromXML(), assOrderingQuestionImport\fromXML(), and assMatchingQuestionImport\fromXML().

399  : int
400  {
401  if ($size === null) {
402  return $this->object->getThumbSize();
403  }
404 
405  if ($size < $this->object->getMinimumThumbSize()) {
406  return $this->object->getMinimumThumbSize();
407  }
408 
409  if ($size > $this->object->getMaximumThumbSize()) {
410  return $this->object->getMaximumThumbSize();
411  }
412 
413  return $size;
414  }
+ Here is the call graph for this function:
+ Here is the caller 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

protected

Returns
string $additionalContentEditingMode

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

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

Referenced by assKprimChoiceImport\fromXML(), assLongMenuImport\fromXML(), assFileUploadImport\fromXML(), assErrorTextImport\fromXML(), assClozeTestImport\fromXML(), assOrderingHorizontalImport\fromXML(), assNumericImport\fromXML(), assFormulaQuestionImport\fromXML(), assMultipleChoiceImport\fromXML(), assTextSubsetImport\fromXML(), assImagemapQuestionImport\fromXML(), assSingleChoiceImport\fromXML(), assOrderingQuestionImport\fromXML(), assTextQuestionImport\fromXML(), and assMatchingQuestionImport\fromXML().

286  : string
287  {
288  $additionalContentEditingMode = $qtiItem->getMetadataEntry('additional_cont_edit_mode');
289 
290  if (!$this->object->isValidAdditionalContentEditingMode($additionalContentEditingMode ?? '')) {
291  $additionalContentEditingMode = assQuestion::ADDITIONAL_CONTENT_EDITING_MODE_RTE;
292  }
293 
294  return $additionalContentEditingMode;
295  }
const ADDITIONAL_CONTENT_EDITING_MODE_RTE
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fetchIndexFromFeedbackIdent()

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

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

Referenced by assErrorTextImport\fromXML(), assOrderingHorizontalImport\fromXML(), assOrderingQuestionImport\fromXML(), and assTextQuestionImport\fromXML().

121  : int
122  {
123  return (int) str_replace($prefix, '', $feedbackIdent);
124  }
+ Here is the caller graph for this function:

◆ fetchLifecycle()

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

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

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

Referenced by addGeneralMetadata().

213  {
214  try {
216  $item->getMetadataEntry('ilias_lifecycle')
217  );
219  try {
220  $lomLifecycle = new ilAssQuestionLomLifecycle(
221  $item->getMetadataEntry('lifecycle')
222  );
223 
225  $lomLifecycle->getMappedIliasLifecycleIdentifer()
226  );
229  }
230  }
231 
232  return $lifecycle;
233  }
getMetadataEntry(string $a_label)
$lifecycle
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findSolutionTypeByValue()

assQuestionImport::findSolutionTypeByValue ( string  $value)
protected

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

Referenced by importSuggestedSolutions().

347  : ?string
348  {
349  foreach (array_keys(assQuestionSuggestedSolution::TYPES) as $type) {
350  $search_type = '_' . $type . '_';
351  if (strpos($value, $search_type) !== false) {
352  return $type;
353  }
354  }
355  return null;
356  }
+ Here is the caller graph for this function:

◆ fromXML()

assQuestionImport::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 190 of file class.assQuestionImport.php.

190  : array
191  {
192  }

◆ getFeedbackAnswerSpecific()

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

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

References QTIMaterialToString().

Referenced by assErrorTextImport\fromXML(), assOrderingHorizontalImport\fromXML(), assOrderingQuestionImport\fromXML(), assTextQuestionImport\fromXML(), and assMatchingQuestionImport\fromXML().

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

◆ getFeedbackGeneric()

assQuestionImport::getFeedbackGeneric (   $item)

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

References QTIMaterialToString().

Referenced by assFileUploadImport\fromXML(), assErrorTextImport\fromXML(), assFormulaQuestionImport\fromXML(), and assOrderingHorizontalImport\fromXML().

62  : array
63  {
64  $feedbacksgeneric = [];
65  foreach ($item->resprocessing as $resprocessing) {
66  foreach ($resprocessing->respcondition as $respcondition) {
67  foreach ($respcondition->displayfeedback as $feedbackpointer) {
68  if (strlen($feedbackpointer->getLinkrefid())) {
69  foreach ($item->itemfeedback as $ifb) {
70  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
71  // found a feedback for the identifier
72  if (count($ifb->material)) {
73  foreach ($ifb->material as $material) {
74  $feedbacksgeneric[1] = $material;
75  }
76  }
77  if ((count($ifb->flow_mat) > 0)) {
78  foreach ($ifb->flow_mat as $fmat) {
79  if (count($fmat->material)) {
80  foreach ($fmat->material as $material) {
81  $feedbacksgeneric[1] = $material;
82  }
83  }
84  }
85  }
86  } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
87  // found a feedback for the identifier
88  if (count($ifb->material)) {
89  foreach ($ifb->material as $material) {
90  $feedbacksgeneric[0] = $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[0] = $material;
98  }
99  }
100  }
101  }
102  }
103  }
104  }
105  }
106  }
107  }
108  // handle the import of media objects in XHTML code
109  foreach ($feedbacksgeneric as $correctness => $material) {
110  $m = $this->QTIMaterialToString($material);
111  $feedbacksgeneric[$correctness] = $m;
112  }
113  return $feedbacksgeneric;
114  }
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getQplImportArchivDirectory()

assQuestionImport::getQplImportArchivDirectory ( )
protected

returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir)

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

References ilObjQuestionPool\_getImportDirectory(), and ilSession\get().

Referenced by assKprimChoiceImport\fromXML(), assLongMenuImport\fromXML(), assFileUploadImport\fromXML(), assErrorTextImport\fromXML(), assImagemapQuestionImport\fromXML(), assOrderingHorizontalImport\fromXML(), assMultipleChoiceImport\fromXML(), assNumericImport\fromXML(), assTextSubsetImport\fromXML(), assClozeTestImport\fromXML(), assSingleChoiceImport\fromXML(), assOrderingQuestionImport\fromXML(), assTextQuestionImport\fromXML(), and assMatchingQuestionImport\fromXML().

238  : string
239  {
240  return ilObjQuestionPool::_getImportDirectory() . '/' . ilSession::get("qpl_import_subdir");
241  }
static get(string $a_var)
static _getImportDirectory()
get import directory of lm
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getQuestionId()

assQuestionImport::getQuestionId ( )

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

57  : int
58  {
59  return (int) $this->object->getId();
60  }

◆ getSuggestedSolutionsRepo()

assQuestionImport::getSuggestedSolutionsRepo ( )
protected

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

References $dic, $suggestedsolution_repo, and ilQuestionPoolDIC\dic().

Referenced by importSuggestedSolutions().

361  {
362  if (is_null($this->suggestedsolution_repo)) {
364  $this->suggestedsolution_repo = $dic['question.repo.suggestedsolutions'];
365  }
367  }
assQuestionSuggestedSolutionsDatabaseRepository $suggestedsolution_repo
$dic
Definition: result.php:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTstImportArchivDirectory()

assQuestionImport::getTstImportArchivDirectory ( )
protected

returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir)

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

References ilObjTest\_getImportDirectory(), and ilSession\get().

Referenced by assKprimChoiceImport\fromXML(), assLongMenuImport\fromXML(), assFileUploadImport\fromXML(), assErrorTextImport\fromXML(), assImagemapQuestionImport\fromXML(), assOrderingHorizontalImport\fromXML(), assMultipleChoiceImport\fromXML(), assNumericImport\fromXML(), assTextSubsetImport\fromXML(), assClozeTestImport\fromXML(), assSingleChoiceImport\fromXML(), assOrderingQuestionImport\fromXML(), assTextQuestionImport\fromXML(), and assMatchingQuestionImport\fromXML().

246  : string
247  {
248  return ilObjTest::_getImportDirectory() . '/' . ilSession::get("tst_import_subdir");
249  }
static get(string $a_var)
static _getImportDirectory()
Get the import directory location of the test.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importSuggestedSolutions()

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

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

References $path, CLIENT_WEB_DIR, ILIAS\Repository\filesystem(), findSolutionTypeByValue(), getSuggestedSolutionsRepo(), and ILIAS\Repository\object().

Referenced by assKprimChoiceImport\fromXML(), assLongMenuImport\fromXML(), assFileUploadImport\fromXML(), assErrorTextImport\fromXML(), assClozeTestImport\fromXML(), assOrderingHorizontalImport\fromXML(), assNumericImport\fromXML(), assFormulaQuestionImport\fromXML(), assMultipleChoiceImport\fromXML(), assTextSubsetImport\fromXML(), assImagemapQuestionImport\fromXML(), assSingleChoiceImport\fromXML(), assOrderingQuestionImport\fromXML(), assTextQuestionImport\fromXML(), and assMatchingQuestionImport\fromXML().

300  : void {
301  if (!$solution_from_import === []
302  || !isset($solution_from_import[0]['solution'])) {
303  return;
304  }
305 
306  $solution_item = $solution_from_import[0]['solution'];
307  $content = $solution_item->getContent();
308  if ($solution_item->getTexttype() === 'application/json') {
309  $content = json_decode($content, true);
310  if (!isset($content['type']) || !isset($content['value'])) {
311  return;
312  }
313  $type = $content['type'];
314  } else {
315  $type = $this->findSolutionTypeByValue($solution_item->getContent());
316  if ($type === null) {
317  return;
318  }
319  }
320 
321  $repo = $this->getSuggestedSolutionsRepo();
322  $solution_object = $repo->create($question_id, $type);
323 
324  if ($type !== assQuestionSuggestedSolution::TYPE_FILE) {
325  $link = is_string($content) ? $content : $content['value'];
326  $adapted_link = $this->object->resolveInternalLink($link);
327  if ($adapted_link === '') {
328  return;
329  }
330  $solution_object = $solution_object
331  ->withInternalLink($adapted_link)
332  ->withImportId($link);
333  } else {
334  if (!isset($content['title']) || !isset($content['filename'])) {
335  return;
336  }
337  $path = str_replace(CLIENT_WEB_DIR . DIRECTORY_SEPARATOR, '', $this->object->getSuggestedSolutionPath() . $content['filename']);
338  $this->filesystem->put($path, base64_decode($content['value']));
339  $solution_object = $solution_object->withTitle($content['title'])
340  ->withFilename($content['filename'])
341  ->withSize((int) $this->filesystem->getSize($path, DataSize::Byte)->inBytes())
342  ->withMime($this->filesystem->getMimeType($path));
343  }
344  $repo->update([$solution_object]);
345  }
$path
Definition: ltiservices.php:32
const CLIENT_WEB_DIR
Definition: constants.php:47
findSolutionTypeByValue(string $value)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processNonAbstractedImageReferences()

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

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

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

Referenced by assClozeTestImport\fromXML().

251  : string
252  {
253  $reg = '/<img.*src=".*\\/mm_(\\d+)\\/(.*?)".*>/m';
254  $matches = null;
255 
256  if (preg_match_all($reg, $text, $matches)) {
257  $mobs = [];
258  for ($i = 0, $max = count($matches[1]); $i < $max; $i++) {
259  $mobSrcId = $matches[1][$i];
260  $mobSrcName = $matches[2][$i];
261  $mobSrcLabel = 'il_' . $sourceNic . '_mob_' . $mobSrcId;
262 
263  //if (!is_array(ilSession::get("import_mob_xhtml"))) {
264  // ilSession::set("import_mob_xhtml", array());
265  //}
266 
267  //$_SESSION["import_mob_xhtml"][] = array(
268  $mobs[] = [
269  "mob" => $mobSrcLabel, "uri" => 'objects/' . $mobSrcLabel . '/' . $mobSrcName
270  ];
271  }
272  ilSession::set('import_mob_xhtml', $mobs);
273  }
274 
275  return ilRTE::_replaceMediaObjectImageSrc($text, 0, $sourceNic);
276  }
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.
+ Here is the call graph for this function:
+ Here is the caller 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 373 of file class.assQuestionImport.php.

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

Referenced by assKprimChoiceImport\fromXML(), assLongMenuImport\fromXML(), assFileUploadImport\fromXML(), assErrorTextImport\fromXML(), assClozeTestImport\fromXML(), assFormulaQuestionImport\fromXML(), assTextSubsetImport\fromXML(), assOrderingHorizontalImport\fromXML(), assNumericImport\fromXML(), assMultipleChoiceImport\fromXML(), assImagemapQuestionImport\fromXML(), assSingleChoiceImport\fromXML(), assOrderingQuestionImport\fromXML(), assTextQuestionImport\fromXML(), assMatchingQuestionImport\fromXML(), getFeedbackAnswerSpecific(), and getFeedbackGeneric().

373  : string
374  {
375  $result = "";
376  $mobs = ilSession::get('import_mob_xhtml') ?? [];
377  for ($i = 0; $i < $a_material->getMaterialCount(); $i++) {
378  $material = $a_material->getMaterial($i);
379  if (strcmp($material["type"], "mattext") === 0) {
380  $result .= $material["material"]->getContent();
381  }
382  if (strcmp($material["type"], "matimage") === 0) {
383  $matimage = $material["material"];
384  if (preg_match("/(il_([0-9]+)_mob_([0-9]+))/", $matimage->getLabel(), $matches)) {
385  // import an mediaobject which was inserted using tiny mce
386  //if (!is_array(ilSession::get("import_mob_xhtml"))) {
387  // ilSession::set("import_mob_xhtml", array());
388  //}
389  $mobs[] = ["mob" => $matimage->getLabel(),
390  "uri" => $matimage->getUri()
391  ];
392  }
393  }
394  }
395  ilSession::set('import_mob_xhtml', $mobs);
396  return $result;
397  }
static get(string $a_var)
getMaterial(int $a_index)
static set(string $a_var, $a_val)
Set a value.
+ 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 40 of file class.assQuestionImport.php.

◆ $object

assQuestionImport::$object

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

◆ $suggestedsolution_repo

assQuestionSuggestedSolutionsDatabaseRepository assQuestionImport::$suggestedsolution_repo = null
protected

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

Referenced by getSuggestedSolutionsRepo().


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