ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilObjTestXMLParser Class Reference
+ Inheritance diagram for ilObjTestXMLParser:
+ Collaboration diagram for ilObjTestXMLParser:

Public Member Functions

 __construct (?string $path_to_file='', ?bool $throw_exception=false)
 
 getTestOBJ ()
 
 setTestOBJ (\ilObjTest $test_obj)
 
 getImportMapping ()
 
 setImportMapping (\ilImportMapping $import_mapping)
 
 setHandlers ($xml_parser)
 
 handlerBeginTag ( $xml_parser, string $tag_name, array $tag_attributes)
 
 handlerEndTag ($xml_parser, string $tag_name)
 
 handlerCharacterData ($xml_parser, string $char_data)
 
- Public Member Functions inherited from ilSaxParser
 __construct (?string $path_to_file='', ?bool $throw_exception=false)
 
 setXMLContent (string $a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 
 setHandlers ($a_xml_parser)
 
 parse ($a_xml_parser, $a_fp=null)
 

Protected Member Functions

 importRandomQuestionSetSettings ($attr)
 
 importRandomQuestionStagingPool (array $attr, string $cdata)
 
 importRandomQuestionSourcePoolDefinition (ilTestRandomQuestionSetSourcePoolDefinition $source_pool_definition, $attr)
 
- Protected Member Functions inherited from ilSaxParser
 openXMLFile ()
 
 handleError (string $message)
 
 setThrowException (bool $throw_exception)
 

Protected Attributes

ilObjTest $test_obj = null
 
ilImportMapping $import_mapping = null
 
string $cdata = ''
 
array $attr = null
 
- Protected Attributes inherited from ilSaxParser
ilLanguage $lng = null
 

Private Attributes

ILIAS TestQuestionPool QuestionInfoService $questioninfo
 
ilDBInterface $db
 
ilLogger $log
 
ilTree $tree
 
ilComponentRepository $component_repository
 
bool $in_random_question_set_config = null
 
bool $in_random_question_set_settings = null
 
bool $in_random_question_stage = null
 
bool $in_random_question_selection_definitions = null
 
ilTestRandomQuestionSetSourcePoolDefinition $source_pool_definition = null
 

Additional Inherited Members

- Data Fields inherited from ilSaxParser
string $xml_file
 
bool $throw_exception = false
 

Detailed Description

Definition at line 27 of file class.ilObjTestXMLParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilObjTestXMLParser::__construct ( ?string  $path_to_file = '',
?bool  $throw_exception = false 
)

Definition at line 48 of file class.ilObjTestXMLParser.php.

References $DIC, ilSaxParser\$throw_exception, and ILIAS\MetaData\Repository\Validation\Data\__construct().

51  {
52  global $DIC;
53  $this->db = $DIC['ilDB'];
54  $this->log = $DIC['ilLog'];
55  $this->tree = $DIC['tree'];
56  $this->component_repository = $DIC['component.repository'];
57  $this->questioninfo = $DIC->testQuestionPool()->questionInfo();
58  parent::__construct($path_to_file, $throw_exception);
59  }
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
+ Here is the call graph for this function:

Member Function Documentation

◆ getImportMapping()

ilObjTestXMLParser::getImportMapping ( )

Definition at line 71 of file class.ilObjTestXMLParser.php.

References $import_mapping.

Referenced by handlerEndTag(), importRandomQuestionSourcePoolDefinition(), and importRandomQuestionStagingPool().

72  {
73  return $this->import_mapping;
74  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the caller graph for this function:

◆ getTestOBJ()

ilObjTestXMLParser::getTestOBJ ( )

Definition at line 61 of file class.ilObjTestXMLParser.php.

References $test_obj.

61  : ?\ilObjTest
62  {
63  return $this->test_obj;
64  }

◆ handlerBeginTag()

ilObjTestXMLParser::handlerBeginTag (   $xml_parser,
string  $tag_name,
array  $tag_attributes 
)

Definition at line 88 of file class.ilObjTestXMLParser.php.

92  : void {
93  switch ($tag_name) {
94  case 'RandomQuestionSetConfig':
95  $this->in_random_question_set_config = true;
96  break;
97 
98  case 'RandomQuestionSetSettings':
99  if ($this->in_random_question_set_config !== null) {
100  $this->in_random_question_set_settings = true;
101  $this->cdata = '';
102  $this->attr = $tag_attributes;
103  }
104  break;
105 
106  case 'RandomQuestionStage':
107  if ($this->in_random_question_set_config !== null) {
108  $this->in_random_question_stage = true;
109  }
110  break;
111 
112  case 'RandomQuestionStagingPool':
113  if ($this->in_random_question_stage !== null) {
114  $this->cdata = '';
115  $this->attr = $tag_attributes;
116  }
117  break;
118 
119  case 'RandomQuestionSelectionDefinitions':
120  if ($this->in_random_question_set_config !== null) {
121  $this->in_random_question_selection_definitions = true;
122  }
123  break;
124 
125  case 'RandomQuestionSelectionDefinition':
126  if ($this->in_random_question_selection_definitions !== null) {
127  $this->source_pool_definition = new ilTestRandomQuestionSetSourcePoolDefinition($this->db, $this->test_obj);
128  ;
129  $this->attr = $tag_attributes;
130  }
131  break;
132 
133  case 'RandomQuestionSourcePoolTitle':
134  case 'RandomQuestionSourcePoolPath':
135  if ($this->source_pool_definition !== null) {
136  $this->cdata = '';
137  }
138  break;
139  }
140  }

◆ handlerCharacterData()

ilObjTestXMLParser::handlerCharacterData (   $xml_parser,
string  $char_data 
)

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

211  : void
212  {
213  if ($char_data != "\n") {
214  // Replace multiple tabs with one space
215  $char_data = preg_replace("/\t+/", " ", $char_data);
216 
217  $this->cdata .= $char_data;
218  }
219  }

◆ handlerEndTag()

ilObjTestXMLParser::handlerEndTag (   $xml_parser,
string  $tag_name 
)

Definition at line 142 of file class.ilObjTestXMLParser.php.

References getImportMapping(), importRandomQuestionSetSettings(), importRandomQuestionSourcePoolDefinition(), and importRandomQuestionStagingPool().

142  : void
143  {
144  switch ($tag_name) {
145  case 'RandomQuestionSetConfig':
146  $this->in_random_question_set_config = false;
147  break;
148 
149  case 'RandomQuestionSetSettings':
150  if ($this->in_random_question_set_config) {
151  $this->importRandomQuestionSetSettings($this->attr);
152  $this->attr = null;
153  }
154  break;
155 
156  case 'RandomQuestionStage':
157  if ($this->in_random_question_set_config) {
158  $this->in_random_question_stage = false;
159  }
160  break;
161 
162  case 'RandomQuestionStagingPool':
163  if ($this->in_random_question_set_config !== null
164  && $this->in_random_question_stage !== null) {
165  $this->importRandomQuestionStagingPool($this->attr, $this->cdata);
166  $this->attr = null;
167  $this->cdata = '';
168  }
169  break;
170 
171  case 'RandomQuestionSelectionDefinitions':
172  if ($this->in_random_question_set_config) {
173  $this->in_random_question_selection_definitions = false;
174  }
175  break;
176 
177  case 'RandomQuestionSelectionDefinition':
178  if ($this->in_random_question_set_config !== null
179  && $this->in_random_question_selection_definitions !== null) {
180  $this->importRandomQuestionSourcePoolDefinition($this->source_pool_definition, $this->attr);
181  $this->source_pool_definition->saveToDb();
182 
183  $this->getImportMapping()->addMapping(
184  'Modules/Test',
185  'rnd_src_pool_def',
186  (string) $this->attr['id'],
187  (string) $this->source_pool_definition->getId()
188  );
189 
190  $this->source_pool_definition = null;
191  $this->attr = null;
192  }
193  break;
194 
195  case 'RandomQuestionSourcePoolTitle':
196  if ($this->source_pool_definition !== null) {
197  $this->source_pool_definition->setPoolTitle($this->cdata);
198  $this->cdata = '';
199  }
200  break;
201 
202  case 'RandomQuestionSourcePoolPath':
203  if ($this->source_pool_definition !== null) {
204  $this->source_pool_definition->setPoolPath($this->cdata);
205  $this->cdata = '';
206  }
207  break;
208  }
209  }
importRandomQuestionStagingPool(array $attr, string $cdata)
importRandomQuestionSourcePoolDefinition(ilTestRandomQuestionSetSourcePoolDefinition $source_pool_definition, $attr)
+ Here is the call graph for this function:

◆ importRandomQuestionSetSettings()

ilObjTestXMLParser::importRandomQuestionSetSettings (   $attr)
protected

Definition at line 221 of file class.ilObjTestXMLParser.php.

References ILIAS\Repository\lng().

Referenced by handlerEndTag().

221  : void
222  {
223  $question_set_config = new ilTestRandomQuestionSetConfig(
224  $this->tree,
225  $this->db,
226  $this->lng,
227  $this->log,
228  $this->component_repository,
229  $this->test_obj,
230  $this->questioninfo
231  );
232 
233  if (!$question_set_config->isValidQuestionAmountConfigurationMode($attr['amountMode'])) {
234  throw new ilTestException(
235  'invalid random test question set config amount mode given: "' . $attr['amountMode'] . '"'
236  );
237  }
238 
239  $question_set_config->setQuestionAmountConfigurationMode($attr['amountMode']);
240  $question_set_config->setQuestionAmountPerTest((int) $attr['questAmount']);
241  $question_set_config->setPoolsWithHomogeneousScoredQuestionsRequired((bool) $attr['homogeneous']);
242  $question_set_config->setLastQuestionSyncTimestamp((int) $attr['synctimestamp']);
243 
244  $question_set_config->saveToDb();
245  }
Base Exception for all Exceptions relating to Modules/Test.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importRandomQuestionSourcePoolDefinition()

ilObjTestXMLParser::importRandomQuestionSourcePoolDefinition ( ilTestRandomQuestionSetSourcePoolDefinition  $source_pool_definition,
  $attr 
)
protected

Definition at line 277 of file class.ilObjTestXMLParser.php.

References $ref_id, ilObject\_getAllReferences(), getImportMapping(), ILIAS\Repository\int(), ilTestRandomQuestionSetSourcePoolDefinition\setMappedTaxonomyFilter(), ilTestRandomQuestionSetSourcePoolDefinition\setPoolId(), ilTestRandomQuestionSetSourcePoolDefinition\setPoolQuestionCount(), ilTestRandomQuestionSetSourcePoolDefinition\setPoolRefId(), ilTestRandomQuestionSetSourcePoolDefinition\setQuestionAmount(), ilTestRandomQuestionSetSourcePoolDefinition\setSequencePosition(), and ilTestRandomQuestionSetSourcePoolDefinition\setTypeFilterFromTypeTags().

Referenced by handlerEndTag().

277  : void
278  {
279  $source_pool_id = (int) $attr['poolId'];
280  $effective_pool_id = (int) $this->getImportMapping()->getMapping(
281  'Modules/Test',
282  'pool',
283  (string) $source_pool_id
284  );
285  $source_pool_definition->setPoolId($effective_pool_id);
286 
287  $derive_from_obj_id = true;
288  // The ref_id might not be given in old export files, so we have to check for existence
289  if (isset($attr['ref_id']) && is_numeric($attr['ref_id'])) {
290  if ($source_pool_id === $effective_pool_id) {
291  $derive_from_obj_id = false;
292  $source_pool_definition->setPoolRefId((int) $attr['ref_id']);
293  }
294  }
295 
296  if ($derive_from_obj_id) {
297  $ref_ids = ilObject::_getAllReferences($effective_pool_id);
298  $ref_id = current($ref_ids);
299  $source_pool_definition->setPoolRefId($ref_id ? $ref_id : null);
300  }
301 
302  $source_pool_definition->setPoolQuestionCount((int) $attr['poolQuestCount']);
303  $source_pool_definition->setQuestionAmount((int) $attr['questAmount']);
304  $source_pool_definition->setSequencePosition((int) $attr['position']);
305 
306  if (isset($attr['typeFilter']) && strlen($attr['typeFilter']) > 0) {
307  $source_pool_definition->setTypeFilterFromTypeTags(explode(',', $attr['typeFilter']));
308  }
309 
310  // #21330
311  if (isset($attr['tax']) && isset($attr['taxNode'])) {
312  $mappedTaxFilter = [
313  (int) $attr['tax'] => [
314  (int) $attr['taxNode']
315  ]
316  ];
317  $source_pool_definition->setMappedTaxonomyFilter($mappedTaxFilter);
318  } elseif (isset($attr['taxFilter']) && strlen($attr['taxFilter']) > 0) {
319  $mappedTaxFilter = unserialize($attr['taxFilter']);
320  $source_pool_definition->setMappedTaxonomyFilter($mappedTaxFilter);
321  }
322  }
static _getAllReferences(int $id)
get all reference ids for object ID
setMappedTaxonomyFilter(array $filter=[])
set the original taxonomy filter condition
$ref_id
Definition: ltiauth.php:67
setTypeFilterFromTypeTags(array $tags)
Set the type filter from a list of type tags.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importRandomQuestionStagingPool()

ilObjTestXMLParser::importRandomQuestionStagingPool ( array  $attr,
string  $cdata 
)
protected

Definition at line 247 of file class.ilObjTestXMLParser.php.

References getImportMapping(), and ILIAS\Repository\int().

Referenced by handlerEndTag().

247  : void
248  {
249  $old_pool_id = $attr['poolId'];
250  $new_pool_id = $this->db->nextId('object_data'); // yes !!
251 
252  $this->getImportMapping()->addMapping(
253  'Modules/Test',
254  'pool',
255  (string) $old_pool_id,
256  (string) $new_pool_id
257  );
258 
259  $old_question_ids = explode(',', $cdata);
260 
261  foreach ($old_question_ids as $old_question_id) {
262  $new_question_id = (int) $this->getImportMapping()->getMapping(
263  'Modules/Test',
264  'quest',
265  $old_question_id
266  );
267 
268  $staging_question = new ilTestRandomQuestionSetStagingPoolQuestion($this->db);
269  $staging_question->setTestId($this->test_obj->getTestId());
270  $staging_question->setPoolId($new_pool_id);
271  $staging_question->setQuestionId($new_question_id);
272 
273  $staging_question->saveQuestionStaging();
274  }
275  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlers()

ilObjTestXMLParser::setHandlers (   $xml_parser)

Definition at line 81 of file class.ilObjTestXMLParser.php.

81  : void
82  {
83  xml_set_object($xml_parser, $this);
84  xml_set_element_handler($xml_parser, 'handlerBeginTag', 'handlerEndTag');
85  xml_set_character_data_handler($xml_parser, 'handlerCharacterData');
86  }

◆ setImportMapping()

ilObjTestXMLParser::setImportMapping ( \ilImportMapping  $import_mapping)

Definition at line 76 of file class.ilObjTestXMLParser.php.

References $import_mapping.

76  : void
77  {
78  $this->import_mapping = $import_mapping;
79  }

◆ setTestOBJ()

ilObjTestXMLParser::setTestOBJ ( \ilObjTest  $test_obj)

Definition at line 66 of file class.ilObjTestXMLParser.php.

References $test_obj.

66  : void
67  {
68  $this->test_obj = $test_obj;
69  }

Field Documentation

◆ $attr

array ilObjTestXMLParser::$attr = null
protected

Definition at line 40 of file class.ilObjTestXMLParser.php.

◆ $cdata

string ilObjTestXMLParser::$cdata = ''
protected

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

◆ $component_repository

ilComponentRepository ilObjTestXMLParser::$component_repository
private

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

◆ $db

ilDBInterface ilObjTestXMLParser::$db
private

Definition at line 32 of file class.ilObjTestXMLParser.php.

◆ $import_mapping

ilImportMapping ilObjTestXMLParser::$import_mapping = null
protected

Definition at line 37 of file class.ilObjTestXMLParser.php.

Referenced by getImportMapping(), and setImportMapping().

◆ $in_random_question_selection_definitions

bool ilObjTestXMLParser::$in_random_question_selection_definitions = null
private

Definition at line 45 of file class.ilObjTestXMLParser.php.

◆ $in_random_question_set_config

bool ilObjTestXMLParser::$in_random_question_set_config = null
private

Definition at line 42 of file class.ilObjTestXMLParser.php.

◆ $in_random_question_set_settings

bool ilObjTestXMLParser::$in_random_question_set_settings = null
private

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

◆ $in_random_question_stage

bool ilObjTestXMLParser::$in_random_question_stage = null
private

Definition at line 44 of file class.ilObjTestXMLParser.php.

◆ $log

ilLogger ilObjTestXMLParser::$log
private

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

◆ $questioninfo

ILIAS TestQuestionPool QuestionInfoService ilObjTestXMLParser::$questioninfo
private

Definition at line 29 of file class.ilObjTestXMLParser.php.

◆ $source_pool_definition

ilTestRandomQuestionSetSourcePoolDefinition ilObjTestXMLParser::$source_pool_definition = null
private

Definition at line 46 of file class.ilObjTestXMLParser.php.

◆ $test_obj

ilObjTest ilObjTestXMLParser::$test_obj = null
protected

Definition at line 30 of file class.ilObjTestXMLParser.php.

Referenced by getTestOBJ(), and setTestOBJ().

◆ $tree

ilTree ilObjTestXMLParser::$tree
private

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


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