ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
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

readonly GeneralQuestionPropertiesRepository $questionrepository
 
readonly ilDBInterface $db
 
readonly TestLogger $logger
 
readonly ilTree $tree
 
readonly 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

Deprecated:
12: Use ILIAS\Test\ExportImport\TestImporter instead

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

Constructor & Destructor Documentation

◆ __construct()

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

Reimplemented from ilSaxParser.

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

53 {
54 global $DIC;
55 $this->db = $DIC['ilDB'];
56 $local_dic = TestDIC::dic();
57 $this->logger = $local_dic['logging.logger'];
58 $this->questionrepository = $local_dic['question.general_properties.repository'];
59 $this->tree = $DIC['tree'];
60 $this->component_repository = $DIC['component.repository'];
62 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26

References $DIC, ilSaxParser\$throw_exception, ILIAS\GlobalScreen\Provider\__construct(), and ILIAS\Repository\logger().

+ Here is the call graph for this function:

Member Function Documentation

◆ getImportMapping()

ilObjTestXMLParser::getImportMapping ( )

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

75 {
77 }

References $import_mapping.

◆ getTestOBJ()

ilObjTestXMLParser::getTestOBJ ( )

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

References $test_obj.

◆ handlerBeginTag()

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

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

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

Referenced by setHandlers().

+ Here is the caller graph for this function:

◆ handlerCharacterData()

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

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

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

Referenced by setHandlers().

+ Here is the caller graph for this function:

◆ handlerEndTag()

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

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

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

Referenced by setHandlers().

+ Here is the caller graph for this function:

◆ importRandomQuestionSetSettings()

ilObjTestXMLParser::importRandomQuestionSetSettings (   $attr)
protected

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

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

References ILIAS\Repository\lng(), and ILIAS\Repository\logger().

+ Here is the call graph for this function:

◆ importRandomQuestionSourcePoolDefinition()

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

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

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

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

+ Here is the call graph for this function:

◆ importRandomQuestionStagingPool()

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

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

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

References ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ setHandlers()

ilObjTestXMLParser::setHandlers (   $a_xml_parser)
Parameters
XMLParser | resource$a_xml_parser
Returns
void

Reimplemented from ilSaxParser.

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

84 : void
85 {
86 xml_set_element_handler($xml_parser, $this->handlerBeginTag(...), $this->handlerEndTag(...));
87 xml_set_character_data_handler($xml_parser, $this->handlerCharacterData(...));
88 }
handlerCharacterData($xml_parser, string $char_data)
handlerBeginTag( $xml_parser, string $tag_name, array $tag_attributes)
handlerEndTag($xml_parser, string $tag_name)

References handlerBeginTag(), handlerCharacterData(), and handlerEndTag().

+ Here is the call graph for this function:

◆ setImportMapping()

ilObjTestXMLParser::setImportMapping ( \ilImportMapping  $import_mapping)

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

79 : void
80 {
81 $this->import_mapping = $import_mapping;
82 }

References $import_mapping.

◆ setTestOBJ()

ilObjTestXMLParser::setTestOBJ ( \ilObjTest  $test_obj)

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

69 : void
70 {
71 $this->test_obj = $test_obj;
72 }

References $test_obj.

Field Documentation

◆ $attr

array ilObjTestXMLParser::$attr = null
protected

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

◆ $cdata

string ilObjTestXMLParser::$cdata = ''
protected

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

◆ $component_repository

readonly ilComponentRepository ilObjTestXMLParser::$component_repository
private

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

◆ $db

readonly ilDBInterface ilObjTestXMLParser::$db
private

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

◆ $import_mapping

ilImportMapping ilObjTestXMLParser::$import_mapping = null
protected

Definition at line 39 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 47 of file class.ilObjTestXMLParser.php.

◆ $in_random_question_set_config

bool ilObjTestXMLParser::$in_random_question_set_config = null
private

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

◆ $in_random_question_set_settings

bool ilObjTestXMLParser::$in_random_question_set_settings = null
private

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

◆ $in_random_question_stage

bool ilObjTestXMLParser::$in_random_question_stage = null
private

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

◆ $logger

readonly TestLogger ilObjTestXMLParser::$logger
private

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

◆ $questionrepository

readonly GeneralQuestionPropertiesRepository ilObjTestXMLParser::$questionrepository
private

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

◆ $source_pool_definition

ilTestRandomQuestionSetSourcePoolDefinition ilObjTestXMLParser::$source_pool_definition = null
private

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

◆ $test_obj

ilObjTest ilObjTestXMLParser::$test_obj = null
protected

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

Referenced by getTestOBJ(), and setTestOBJ().

◆ $tree

readonly ilTree ilObjTestXMLParser::$tree
private

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


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