ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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)
 

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

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

Member Function Documentation

◆ addGeneralMetadata()

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

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

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

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

194  : void
195  {
196  if ($item->getMetadataEntry('externalID')) {
197  $this->object->setExternalId($item->getMetadataEntry('externalID'));
198  } else {
199  $this->object->setExternalId($item->getMetadataEntry('externalId'));
200  }
201 
202  $this->object->setLifecycle($this->fetchLifecycle($item));
203  }
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 371 of file class.assQuestionImport.php.

References null, and ILIAS\Repository\object().

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

371  : int
372  {
373  if ($size === null) {
374  return $this->object->getThumbSize();
375  }
376 
377  if ($size < $this->object->getMinimumThumbSize()) {
378  return $this->object->getMinimumThumbSize();
379  }
380 
381  if ($size > $this->object->getMaximumThumbSize()) {
382  return $this->object->getMaximumThumbSize();
383  }
384 
385  return $size;
386  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ 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 261 of file class.assQuestionImport.php.

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

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

261  : string
262  {
263  $additionalContentEditingMode = $qtiItem->getMetadataEntry('additional_cont_edit_mode');
264 
265  if (!$this->object->isValidAdditionalContentEditingMode($additionalContentEditingMode ?? '')) {
266  $additionalContentEditingMode = assQuestion::ADDITIONAL_CONTENT_EDITING_MODE_RTE;
267  }
268 
269  return $additionalContentEditingMode;
270  }
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 122 of file class.assQuestionImport.php.

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

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

◆ fetchLifecycle()

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

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

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

Referenced by addGeneralMetadata().

210  {
211  try {
213  $item->getMetadataEntry('ilias_lifecycle')
214  );
216  try {
217  $lomLifecycle = new ilAssQuestionLomLifecycle(
218  $item->getMetadataEntry('lifecycle')
219  );
220 
222  $lomLifecycle->getMappedIliasLifecycleIdentifer()
223  );
226  }
227  }
228 
229  return $lifecycle;
230  }
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 322 of file class.assQuestionImport.php.

References null.

Referenced by importSuggestedSolutions().

322  : ?string
323  {
324  foreach (array_keys(SuggestedSolution::TYPES) as $type) {
325  $search_type = '_' . $type . '_';
326  if (strpos($value, $search_type) !== false) {
327  return $type;
328  }
329  }
330  return null;
331  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

◆ 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 
)

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

187  : array {
188  return [];
189  }

◆ getFeedbackAnswerSpecific()

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

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

References QTIMaterialToString().

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

132  : array
133  {
134  $feedbacks = [];
135 
136  foreach ($item->itemfeedback as $ifb) {
137  if ($ifb->getIdent() == 'response_allcorrect' || $ifb->getIdent() == 'response_onenotcorrect') {
138  continue;
139  }
140 
141  if ($ifb->getIdent() == $prefix . 'allcorrect' || $ifb->getIdent() == $prefix . 'onenotcorrect') {
142  continue;
143  }
144 
145  if (substr($ifb->getIdent(), 0, strlen($prefix)) != $prefix) {
146  continue;
147  }
148 
149  $ident = $ifb->getIdent();
150 
151  // found a feedback for the identifier
152 
153  if (count($ifb->material)) {
154  foreach ($ifb->material as $material) {
155  $feedbacks[$ident] = $material;
156  }
157  }
158 
159  if ((count($ifb->flow_mat) > 0)) {
160  foreach ($ifb->flow_mat as $fmat) {
161  if (count($fmat->material)) {
162  foreach ($fmat->material as $material) {
163  $feedbacks[$ident] = $material;
164  }
165  }
166  }
167  }
168  }
169 
170  foreach ($feedbacks as $ident => $material) {
171  $m = $this->QTIMaterialToString($material);
172  $feedbacks[$ident] = $m;
173  }
174 
175  return $feedbacks;
176  }
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 63 of file class.assQuestionImport.php.

References QTIMaterialToString().

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

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

◆ getQuestionId()

assQuestionImport::getQuestionId ( )

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

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

◆ getSuggestedSolutionsRepo()

assQuestionImport::getSuggestedSolutionsRepo ( )
protected

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

References $dic, and $suggestedsolution_repo.

Referenced by importSuggestedSolutions().

336  {
337  if (is_null($this->suggestedsolution_repo)) {
338  $dic = QuestionPoolDIC::dic();
339  $this->suggestedsolution_repo = $dic['question.repo.suggestedsolutions'];
340  }
342  }
SuggestedSolutionsDatabaseRepository $suggestedsolution_repo
$dic
Definition: result.php:31
+ Here is the caller graph for this function:

◆ importSuggestedSolutions()

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

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

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

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

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

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

Referenced by assClozeTestImport\fromXML().

232  : string
233  {
234  $reg = '/<img.*src=".*\\/mm_(\\d+)\\/(.*?)".*>/m';
235  $matches = null;
236 
237  if (preg_match_all($reg, $text, $matches)) {
238  $mobs = [];
239  for ($i = 0, $max = count($matches[1]); $i < $max; $i++) {
240  $mobSrcId = $matches[1][$i];
241  $mobSrcName = $matches[2][$i];
242  $mobSrcLabel = 'il_' . $sourceNic . '_mob_' . $mobSrcId;
243  $mobs[] = [
244  "mob" => $mobSrcLabel, "uri" => 'objects/' . $mobSrcLabel . '/' . $mobSrcName
245  ];
246  }
247  ilSession::set('import_mob_xhtml', $mobs);
248  }
249 
250  return ilRTE::_replaceMediaObjectImageSrc($text, 0, $sourceNic);
251  }
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...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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 348 of file class.assQuestionImport.php.

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

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

348  : string
349  {
350  $result = '';
351  $mobs = ilSession::get('import_mob_xhtml') ?? [];
352  for ($i = 0; $i < $a_material->getMaterialCount(); $i++) {
353  $material = $a_material->getMaterial($i);
354  switch ($material['type']) {
355  case 'mattext':
356  $result .= $material['material']->getContent();
357  break;
358  case 'matimage':
359  $matimage = $material['material'];
360  if (preg_match("/(il_([0-9]+)_mob_([0-9]+))/", $matimage->getLabel(), $matches)) {
361  $mobs[] = ["mob" => $matimage->getLabel(),
362  "uri" => $matimage->getUri()
363  ];
364  }
365  }
366  }
367  ilSession::set('import_mob_xhtml', $mobs);
368  return $result;
369  }
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 41 of file class.assQuestionImport.php.

◆ $object

assQuestionImport::$object

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

◆ $suggestedsolution_repo

SuggestedSolutionsDatabaseRepository assQuestionImport::$suggestedsolution_repo = null
protected

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

Referenced by getSuggestedSolutionsRepo().


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