ILIAS  release_8 Revision v8.24
ilObjTestXMLParser Class Reference
+ Inheritance diagram for ilObjTestXMLParser:
+ Collaboration diagram for ilObjTestXMLParser:

Public Member Functions

 getTestOBJ ()
 
 setTestOBJ (\ilObjTest $testOBJ)
 
 getImportMapping ()
 
 setImportMapping (\ilImportMapping $importMapping)
 
 setHandlers ($a_xml_parser)
 
 handlerBeginTag ($xmlParser, $tagName, $tagAttributes)
 
 handlerEndTag ($xmlParser, $tagName)
 
 handlerCharacterData ($xmlParser, $charData)
 
- 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 ($attr, $cdata)
 
 getRandomQuestionSourcePoolDefinitionInstance ()
 
 importRandomQuestionSourcePoolDefinition (ilTestRandomQuestionSetSourcePoolDefinition $sourcePoolDefinition, $attr)
 
- Protected Member Functions inherited from ilSaxParser
 openXMLFile ()
 
 handleError (string $message)
 
 setThrowException (bool $throw_exception)
 

Protected Attributes

ilObjTest $testOBJ = null
 
ilImportMapping $importMapping = null
 
String $cdata = ''
 
- Protected Attributes inherited from ilSaxParser
ilLanguage $lng = null
 

Additional Inherited Members

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

Detailed Description

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

Member Function Documentation

◆ getImportMapping()

ilObjTestXMLParser::getImportMapping ( )

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

44 {
46 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $importMapping.

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

+ Here is the caller graph for this function:

◆ getRandomQuestionSourcePoolDefinitionInstance()

ilObjTestXMLParser::getRandomQuestionSourcePoolDefinitionInstance ( )
protected

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

References $DIC, and $ilDB.

Referenced by handlerBeginTag().

+ Here is the caller graph for this function:

◆ getTestOBJ()

ilObjTestXMLParser::getTestOBJ ( )

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

References $testOBJ.

◆ handlerBeginTag()

ilObjTestXMLParser::handlerBeginTag (   $xmlParser,
  $tagName,
  $tagAttributes 
)

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

60 : void
61 {
62 switch ($tagName) {
63 case 'RandomQuestionSetConfig':
64 $this->inRandomQuestionSetConfig = true;
65 break;
66
67 case 'RandomQuestionSetSettings':
68 if ($this->inRandomQuestionSetConfig) {
69 $this->inRandomQuestionSetSettings = true;
70 $this->cdata = '';
71 $this->attr = $tagAttributes;
72 }
73 break;
74
75 case 'RandomQuestionStage':
76 if ($this->inRandomQuestionSetConfig) {
77 $this->inRandomQuestionStage = true;
78 }
79 break;
80
81 case 'RandomQuestionStagingPool':
82 if ($this->inRandomQuestionStage) {
83 $this->cdata = '';
84 $this->attr = $tagAttributes;
85 }
86 break;
87
88 case 'RandomQuestionSelectionDefinitions':
89 if ($this->inRandomQuestionSetConfig) {
90 $this->inRandomQuestionSelectionDefinitions = true;
91 }
92 break;
93
94 case 'RandomQuestionSelectionDefinition':
95 if ($this->inRandomQuestionSelectionDefinitions) {
96 $this->sourcePoolDefinition = $this->getRandomQuestionSourcePoolDefinitionInstance();
97 $this->attr = $tagAttributes;
98 }
99 break;
100
101 case 'RandomQuestionSourcePoolTitle':
102 case 'RandomQuestionSourcePoolPath':
103 if ($this->sourcePoolDefinition instanceof ilTestRandomQuestionSetSourcePoolDefinition) {
104 $this->cdata = '';
105 }
106 break;
107 }
108 }

References getRandomQuestionSourcePoolDefinitionInstance().

+ Here is the call graph for this function:

◆ handlerCharacterData()

ilObjTestXMLParser::handlerCharacterData (   $xmlParser,
  $charData 
)

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

177 : void
178 {
179 if ($charData != "\n") {
180 // Replace multiple tabs with one space
181 $charData = preg_replace("/\t+/", " ", $charData);
182
183 $this->cdata .= $charData;
184 }
185 }

◆ handlerEndTag()

ilObjTestXMLParser::handlerEndTag (   $xmlParser,
  $tagName 
)

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

110 : void
111 {
112 switch ($tagName) {
113 case 'RandomQuestionSetConfig':
114 $this->inRandomQuestionSetConfig = false;
115 break;
116
117 case 'RandomQuestionSetSettings':
118 if ($this->inRandomQuestionSetConfig) {
119 $this->importRandomQuestionSetSettings($this->attr);
120 $this->attr = null;
121 }
122 break;
123
124 case 'RandomQuestionStage':
125 if ($this->inRandomQuestionSetConfig) {
126 $this->inRandomQuestionStage = false;
127 }
128 break;
129
130 case 'RandomQuestionStagingPool':
131 if ($this->inRandomQuestionSetConfig && $this->inRandomQuestionStage) {
132 $this->importRandomQuestionStagingPool($this->attr, $this->cdata);
133 $this->attr = null;
134 $this->cdata = '';
135 }
136 break;
137
138 case 'RandomQuestionSelectionDefinitions':
139 if ($this->inRandomQuestionSetConfig) {
140 $this->inRandomQuestionSelectionDefinitions = false;
141 }
142 break;
143
144 case 'RandomQuestionSelectionDefinition':
145 if ($this->inRandomQuestionSetConfig && $this->inRandomQuestionSelectionDefinitions) {
146 $this->importRandomQuestionSourcePoolDefinition($this->sourcePoolDefinition, $this->attr);
147 $this->sourcePoolDefinition->saveToDb();
148
149 $this->getImportMapping()->addMapping(
150 'Modules/Test',
151 'rnd_src_pool_def',
152 $this->attr['id'],
153 $this->sourcePoolDefinition->getId()
154 );
155
156 $this->sourcePoolDefinition = null;
157 $this->attr = null;
158 }
159 break;
160
161 case 'RandomQuestionSourcePoolTitle':
162 if ($this->sourcePoolDefinition instanceof ilTestRandomQuestionSetSourcePoolDefinition) {
163 $this->sourcePoolDefinition->setPoolTitle($this->cdata);
164 $this->cdata = '';
165 }
166 break;
167
168 case 'RandomQuestionSourcePoolPath':
169 if ($this->sourcePoolDefinition instanceof ilTestRandomQuestionSetSourcePoolDefinition) {
170 $this->sourcePoolDefinition->setPoolPath($this->cdata);
171 $this->cdata = '';
172 }
173 break;
174 }
175 }
importRandomQuestionStagingPool($attr, $cdata)
importRandomQuestionSourcePoolDefinition(ilTestRandomQuestionSetSourcePoolDefinition $sourcePoolDefinition, $attr)

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

+ Here is the call graph for this function:

◆ importRandomQuestionSetSettings()

ilObjTestXMLParser::importRandomQuestionSetSettings (   $attr)
protected

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

187 : void
188 {
189 global $DIC;
190 $tree = $DIC['tree'];
191 $ilDB = $DIC['ilDB'];
192 $component_repository = $DIC['component.repository'];
193 $questionSetConfig = new ilTestRandomQuestionSetConfig($tree, $ilDB, $component_repository, $this->testOBJ);
194
195 if (!$questionSetConfig->isValidQuestionAmountConfigurationMode($attr['amountMode'])) {
196 throw new ilTestException(
197 'invalid random test question set config amount mode given: "' . $attr['amountMode'] . '"'
198 );
199 }
200
201 $questionSetConfig->setQuestionAmountConfigurationMode($attr['amountMode']);
202 $questionSetConfig->setQuestionAmountPerTest((int) $attr['questAmount']);
203 $questionSetConfig->setPoolsWithHomogeneousScoredQuestionsRequired((bool) $attr['homogeneous']);
204 $questionSetConfig->setLastQuestionSyncTimestamp((int) $attr['synctimestamp']);
205
206 $questionSetConfig->saveToDb();
207 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $DIC, and $ilDB.

Referenced by handlerEndTag().

+ Here is the caller graph for this function:

◆ importRandomQuestionSourcePoolDefinition()

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

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

250 : void
251 {
252 $source_pool_id = (int) $attr['poolId'];
253 $effective_pool_id = (int) $this->getImportMapping()->getMapping(
254 'Modules/Test',
255 'pool',
256 $source_pool_id
257 );
258 $sourcePoolDefinition->setPoolId($effective_pool_id);
259
260 $derive_from_obj_id = true;
261 // The ref_id might not be given in old export files, so we have to check for existence
262 if (isset($attr['ref_id']) && is_numeric($attr['ref_id'])) {
263 if ($source_pool_id === $effective_pool_id) {
264 $derive_from_obj_id = false;
265 $sourcePoolDefinition->setPoolRefId((int) $attr['ref_id']);
266 }
267 }
268
269 if ($derive_from_obj_id) {
270 $ref_ids = ilObject::_getAllReferences($effective_pool_id);
271 $ref_id = current($ref_ids);
272 $sourcePoolDefinition->setPoolRefId($ref_id ? $ref_id : null);
273 }
274
275 $sourcePoolDefinition->setPoolQuestionCount((int) $attr['poolQuestCount']);
276 $sourcePoolDefinition->setQuestionAmount((int) $attr['questAmount']);
277 $sourcePoolDefinition->setSequencePosition((int) $attr['position']);
278
279 if (isset($attr['typeFilter']) && strlen($attr['typeFilter']) > 0) {
280 $sourcePoolDefinition->setTypeFilterFromTypeTags(explode(',', $attr['typeFilter']));
281 }
282
283 // #21330
284 if (isset($attr['tax']) && isset($attr['taxNode'])) {
285 $mappedTaxFilter = array(
286 (int) $attr['tax'] => array(
287 (int) $attr['taxNode']
288 )
289 );
290 $sourcePoolDefinition->setMappedTaxonomyFilter($mappedTaxFilter);
291 } elseif (isset($attr['taxFilter']) && strlen($attr['taxFilter']) > 0) {
292 $mappedTaxFilter = unserialize($attr['taxFilter'], ['allowed_classes' => false]);
293 $sourcePoolDefinition->setMappedTaxonomyFilter($mappedTaxFilter);
294 }
295 }
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($filter=array())
set the original taxonomy filter condition
$ref_id
Definition: ltiauth.php:67

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importRandomQuestionStagingPool()

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

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

209 : void
210 {
211 global $DIC;
212 $ilDB = $DIC['ilDB'];
213
214 $oldPoolId = $attr['poolId'];
215 $newPoolId = $ilDB->nextId('object_data'); // yes !!
216
217 $this->getImportMapping()->addMapping(
218 'Modules/Test',
219 'pool',
220 $oldPoolId,
221 $newPoolId
222 );
223
224 $oldQuestionIds = explode(',', $cdata);
225
226 foreach ($oldQuestionIds as $oldQuestionId) {
227 $newQuestionId = $this->getImportMapping()->getMapping(
228 'Modules/Test',
229 'quest',
230 $oldQuestionId
231 );
232
234 $stagingQuestion->setTestId($this->testOBJ->getTestId());
235 $stagingQuestion->setPoolId($newPoolId);
236 $stagingQuestion->setQuestionId($newQuestionId);
237
238 $stagingQuestion->saveQuestionStaging();
239 }
240 }

References $cdata, $DIC, $ilDB, and getImportMapping().

Referenced by handlerEndTag().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlers()

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

Reimplemented from ilSaxParser.

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

53 : void
54 {
55 xml_set_object($a_xml_parser, $this);
56 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
57 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
58 }

◆ setImportMapping()

ilObjTestXMLParser::setImportMapping ( \ilImportMapping  $importMapping)

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

48 : void
49 {
50 $this->importMapping = $importMapping;
51 }

References $importMapping.

◆ setTestOBJ()

ilObjTestXMLParser::setTestOBJ ( \ilObjTest  $testOBJ)

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

38 : void
39 {
40 $this->testOBJ = $testOBJ;
41 }

References $testOBJ.

Field Documentation

◆ $cdata

String ilObjTestXMLParser::$cdata = ''
protected

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

Referenced by importRandomQuestionStagingPool().

◆ $importMapping

ilImportMapping ilObjTestXMLParser::$importMapping = null
protected

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

Referenced by getImportMapping(), and setImportMapping().

◆ $testOBJ

ilObjTest ilObjTestXMLParser::$testOBJ = null
protected

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

Referenced by getTestOBJ(), and setTestOBJ().


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