ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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

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

56 {
57 global $DIC;
58 $this->db = $DIC['ilDB'];
59 $local_dic = TestDIC::dic();
60 $this->logger = $local_dic['logging.logger'];
61 $this->questionrepository = $local_dic['question.general_properties.repository'];
62 $this->tree = $DIC['tree'];
63 $this->component_repository = $DIC['component.repository'];
65 }
__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 77 of file class.ilObjTestXMLParser.php.

78 {
80 }

References $import_mapping.

◆ getTestOBJ()

ilObjTestXMLParser::getTestOBJ ( )

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

References $test_obj.

◆ handlerBeginTag()

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

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

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

Referenced by setHandlers().

+ Here is the caller graph for this function:

◆ handlerCharacterData()

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

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

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

Referenced by setHandlers().

+ Here is the caller graph for this function:

◆ handlerEndTag()

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

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

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

226 : void
227 {
228 $question_set_config = new ilTestRandomQuestionSetConfig(
229 $this->tree,
230 $this->db,
231 $this->lng,
232 $this->logger,
233 $this->component_repository,
234 $this->test_obj,
235 $this->questionrepository
236 );
237
238 if (!$question_set_config->isValidQuestionAmountConfigurationMode($attr['amountMode'])) {
239 throw new ilTestException(
240 'invalid random test question set config amount mode given: "' . $attr['amountMode'] . '"'
241 );
242 }
243
244 $question_set_config->setQuestionAmountConfigurationMode($attr['amountMode']);
245 $question_set_config->setQuestionAmountPerTest((int) $attr['questAmount']);
246 $question_set_config->setPoolsWithHomogeneousScoredQuestionsRequired((bool) $attr['homogeneous']);
247 $question_set_config->setLastQuestionSyncTimestamp((int) $attr['synctimestamp']);
248
249 $question_set_config->saveToDb();
250 }
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 282 of file class.ilObjTestXMLParser.php.

282 : void
283 {
284 $source_pool_id = (int) $attr['poolId'];
285 $effective_pool_id = (int) $this->getImportMapping()->getMapping(
286 'components/ILIAS/Test',
287 'pool',
288 (string) $source_pool_id
289 );
290 $source_pool_definition->setPoolId($effective_pool_id);
291
292 $derive_from_obj_id = true;
293 // The ref_id might not be given in old export files, so we have to check for existence
294 if (isset($attr['ref_id']) && is_numeric($attr['ref_id'])) {
295 if ($source_pool_id === $effective_pool_id) {
296 $derive_from_obj_id = false;
298 }
299 }
300
301 if ($derive_from_obj_id) {
302 $ref_ids = ilObject::_getAllReferences($effective_pool_id);
303 $ref_id = current($ref_ids);
305 }
306
307 $source_pool_definition->setPoolQuestionCount((int) $attr['poolQuestCount']);
308 $source_pool_definition->setQuestionAmount((int) $attr['questAmount']);
310
311 if (isset($attr['typeFilter']) && strlen($attr['typeFilter']) > 0) {
312 $source_pool_definition->setTypeFilterFromTypeTags(explode(',', $attr['typeFilter']));
313 }
314
315 // #21330
316 if (isset($attr['tax']) && isset($attr['taxNode'])) {
317 $mappedTaxFilter = [
318 (int) $attr['tax'] => [
319 (int) $attr['taxNode']
320 ]
321 ];
323 } elseif (isset($attr['taxFilter']) && strlen($attr['taxFilter']) > 0) {
324 $mappedTaxFilter = unserialize($attr['taxFilter'], ['allowed_classes' => false]);
326 }
327 }
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
$ref_id
Definition: ltiauth.php:66

References $ref_id, 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 252 of file class.ilObjTestXMLParser.php.

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

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 87 of file class.ilObjTestXMLParser.php.

87 : void
88 {
89 xml_set_element_handler($xml_parser, $this->handlerBeginTag(...), $this->handlerEndTag(...));
90 xml_set_character_data_handler($xml_parser, $this->handlerCharacterData(...));
91 }
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 82 of file class.ilObjTestXMLParser.php.

82 : void
83 {
84 $this->import_mapping = $import_mapping;
85 }

References $import_mapping.

◆ setTestOBJ()

ilObjTestXMLParser::setTestOBJ ( \ilObjTest  $test_obj)

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

72 : void
73 {
74 $this->test_obj = $test_obj;
75 }

References $test_obj.

Field Documentation

◆ $attr

array ilObjTestXMLParser::$attr = null
protected

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

◆ $cdata

string ilObjTestXMLParser::$cdata = ''
protected

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

◆ $component_repository

readonly ilComponentRepository ilObjTestXMLParser::$component_repository
private

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

◆ $db

readonly ilDBInterface ilObjTestXMLParser::$db
private

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

◆ $import_mapping

ilImportMapping ilObjTestXMLParser::$import_mapping = null
protected

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

◆ $in_random_question_set_config

bool ilObjTestXMLParser::$in_random_question_set_config = null
private

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

◆ $in_random_question_set_settings

bool ilObjTestXMLParser::$in_random_question_set_settings = null
private

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

◆ $in_random_question_stage

bool ilObjTestXMLParser::$in_random_question_stage = null
private

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

◆ $logger

readonly TestLogger ilObjTestXMLParser::$logger
private

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

◆ $questionrepository

readonly GeneralQuestionPropertiesRepository ilObjTestXMLParser::$questionrepository
private

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

◆ $source_pool_definition

ilTestRandomQuestionSetSourcePoolDefinition ilObjTestXMLParser::$source_pool_definition = null
private

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

◆ $test_obj

ilObjTest ilObjTestXMLParser::$test_obj = null
protected

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

Referenced by getTestOBJ(), and setTestOBJ().

◆ $tree

readonly ilTree ilObjTestXMLParser::$tree
private

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


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