ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilTestResultsImportParser Class Reference
+ Inheritance diagram for ilTestResultsImportParser:
+ Collaboration diagram for ilTestResultsImportParser:

Public Member Functions

 __construct (?string $a_xml_file, private ilObjTest $test_obj, private ilDBInterface $db, private TestLogger $log, private ResourceStorage $irss)
 Constructor. More...
 
 getQuestionIdMapping ()
 
 setQuestionIdMapping (array $question_id_mapping)
 
 getSrcPoolDefIdMapping ()
 
 setSrcPoolDefIdMapping (array $src_pool_def_id_mapping)
 
 setHandlers ($a_xml_parser)
 set event handler should be overwritten by inherited class private More...
 
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element parser More...
 
 handlerEndTag ($a_xml_parser, $a_name)
 handler for end of element More...
 
 handlerParseCharacterData ($a_xml_parser, $a_data)
 handler for character data More...
 
- 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 Attributes

 $src_pool_def_id_mapping
 
- Protected Attributes inherited from ilSaxParser
ilLanguage $lng = null
 

Private Member Functions

 fetchAttribute ($attributes, $name)
 
 fetchLastFinishedPass ($attribs)
 
 fetchLastStartedPass ($attribs)
 
 importParticipantsUploadedFiles (array $a_attribs)
 
 getFirstFileName (string $resource_directory)
 

Private Attributes

 $table
 
 $active_id_mapping
 
 $question_id_mapping
 
string $user_criteria_field = ''
 
string $user_criteria_type = ''
 
bool $user_criteria_checked = false
 
string $import_directory
 

Additional Inherited Members

- Data Fields inherited from ilSaxParser
string $xml_file
 
bool $throw_exception = false
 
- Protected Member Functions inherited from ilSaxParser
 openXMLFile ()
 
 handleError (string $message)
 
 setThrowException (bool $throw_exception)
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilTestResultsImportParser::__construct ( ?string  $a_xml_file,
private ilObjTest  $test_obj,
private ilDBInterface  $db,
private TestLogger  $log,
private ResourceStorage  $irss 
)

Constructor.

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

References ILIAS\GlobalScreen\Provider\__construct().

47  {
48  parent::__construct($a_xml_file, true);
49  $this->table = '';
50  $this->active_id_mapping = [];
51  $this->question_id_mapping = [];
52  $this->src_pool_def_id_mapping = [];
53  $this->import_directory = dirname($a_xml_file);
54  }
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ fetchAttribute()

ilTestResultsImportParser::fetchAttribute (   $attributes,
  $name 
)
private

Definition at line 290 of file class.ilTestResultsImportParser.php.

Referenced by handlerBeginTag().

291  {
292  if (isset($attributes[$name])) {
293  return $attributes[$name];
294  }
295 
296  return null;
297  }
+ Here is the caller graph for this function:

◆ fetchLastFinishedPass()

ilTestResultsImportParser::fetchLastFinishedPass (   $attribs)
private

Definition at line 299 of file class.ilTestResultsImportParser.php.

Referenced by handlerBeginTag().

299  : ?int
300  {
301  if (isset($attribs['last_finished_pass'])) {
302  return (int) $attribs['last_finished_pass'];
303  }
304 
305  if ($attribs['tries'] > 0) {
306  return $attribs['tries'] - 1;
307  }
308 
309  return null;
310  }
+ Here is the caller graph for this function:

◆ fetchLastStartedPass()

ilTestResultsImportParser::fetchLastStartedPass (   $attribs)
private

Definition at line 312 of file class.ilTestResultsImportParser.php.

Referenced by handlerBeginTag().

312  : ?int
313  {
314  if (isset($attribs['last_started_pass'])) {
315  return (int) $attribs['last_started_pass'];
316  }
317 
318  if ($attribs['tries'] > 0) {
319  return (int) $attribs['tries'] - 1;
320  }
321 
322  return null;
323  }
+ Here is the caller graph for this function:

◆ getFirstFileName()

ilTestResultsImportParser::getFirstFileName ( string  $resource_directory)
private

Definition at line 352 of file class.ilTestResultsImportParser.php.

Referenced by importParticipantsUploadedFiles().

352  : mixed
353  {
354  $entries = array_filter(
355  scandir($resource_directory),
356  static fn(string $entry): bool => is_file("$resource_directory/$entry") && !in_array($entry, ['.', '..']),
357  );
358  return array_shift($entries);
359  }
+ Here is the caller graph for this function:

◆ getQuestionIdMapping()

ilTestResultsImportParser::getQuestionIdMapping ( )
Returns
array

Definition at line 59 of file class.ilTestResultsImportParser.php.

References $question_id_mapping.

59  : array
60  {
62  }

◆ getSrcPoolDefIdMapping()

ilTestResultsImportParser::getSrcPoolDefIdMapping ( )
Returns
array

Definition at line 75 of file class.ilTestResultsImportParser.php.

References $src_pool_def_id_mapping.

◆ handlerBeginTag()

ilTestResultsImportParser::handlerBeginTag (   $a_xml_parser,
  $a_name,
  $a_attribs 
)

handler for begin of element parser

Definition at line 103 of file class.ilTestResultsImportParser.php.

References ANONYMOUS_USER_ID, fetchAttribute(), fetchLastFinishedPass(), fetchLastStartedPass(), and importParticipantsUploadedFiles().

103  : void
104  {
105  switch (strtolower($a_name)) {
106  case "results":
107  break;
108  case "row":
109  switch ($this->table) {
110  case 'tst_active':
111  if (!$this->user_criteria_checked) {
112  $this->user_criteria_checked = true;
113  if (isset($a_attribs['user_criteria'])
114  && $this->db->tableColumnExists('usr_data', $a_attribs['user_criteria'])) {
115  $analyzer = new ilDBAnalyzer();
116  $info = $analyzer->getFieldInformation('usr_data');
117  $this->user_criteria_field = $a_attribs['user_criteria'];
118  $this->user_criteria_type = $info[$a_attribs['user_criteria']]['type'];
119  }
120  }
121  $usr_id = ANONYMOUS_USER_ID;
122  if ($this->user_criteria_field !== '') {
123  $result = $this->db->queryF(
124  'SELECT usr_id FROM usr_data WHERE '
125  . $this->user_criteria_field . ' = %s',
126  [$this->user_criteria_type],
127  [$a_attribs[$this->user_criteria_field]]
128  );
129  if ($result->numRows()) {
130  $row = $this->db->fetchAssoc($result);
131  $usr_id = $row['usr_id'];
132  }
133  }
134  $next_id = $this->db->nextId('tst_active');
135 
136  $this->db->insert('tst_active', [
137  'active_id' => ['integer', $next_id],
138  'user_fi' => ['integer', $usr_id],
139  'anonymous_id' => ['text', strlen($a_attribs['anonymous_id']) ? $a_attribs['anonymous_id'] : null],
140  'test_fi' => ['integer', $this->test_obj->getTestId()],
141  'lastindex' => ['integer', $a_attribs['lastindex']],
142  'tries' => ['integer', $a_attribs['tries']],
143  'submitted' => ['integer', $a_attribs['submitted']],
144  'submittimestamp' => ['timestamp', strlen($a_attribs['submittimestamp']) ? $a_attribs['submittimestamp'] : null],
145  'tstamp' => ['integer', $a_attribs['tstamp']],
146  'importname' => ['text', $a_attribs['fullname']],
147  'last_finished_pass' => ['integer', $this->fetchLastFinishedPass($a_attribs)],
148  'last_started_pass' => ['integer', $this->fetchLastStartedPass($a_attribs)],
149  'answerstatusfilter' => ['integer', $this->fetchAttribute($a_attribs, 'answer_status_filter')],
150  'objective_container' => ['integer', $this->fetchAttribute($a_attribs, 'objective_container')]
151  ]);
152  $this->active_id_mapping[$a_attribs['active_id']] = $next_id;
153  break;
154  case 'tst_test_rnd_qst':
155  $nextId = $this->db->nextId('tst_test_rnd_qst');
156  $newActiveId = $this->active_id_mapping[$a_attribs['active_fi']];
157  $newQuestionId = $this->question_id_mapping[$a_attribs['question_fi']];
158  $newSrcPoolDefId = $this->src_pool_def_id_mapping[$a_attribs['src_pool_def_fi']];
159  $this->db->insert('tst_test_rnd_qst', [
160  'test_random_question_id' => ['integer', $nextId],
161  'active_fi' => ['integer', $newActiveId],
162  'question_fi' => ['integer', $newQuestionId],
163  'sequence' => ['integer', $a_attribs['sequence']],
164  'pass' => ['integer', $a_attribs['pass']],
165  'tstamp' => ['integer', $a_attribs['tstamp']],
166  'src_pool_def_fi' => ['integer', $newSrcPoolDefId]
167  ]);
168  break;
169  case 'tst_pass_result':
170  $affectedRows = $this->db->manipulateF(
171  "INSERT INTO tst_pass_result (active_fi, pass, points, maxpoints, questioncount, answeredquestions, workingtime, tstamp) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",
172  [
173  'integer',
174  'integer',
175  'float',
176  'float',
177  'integer',
178  'integer',
179  'integer',
180  'integer'
181  ],
182  [
183  $this->active_id_mapping[$a_attribs['active_fi']],
184  strlen($a_attribs['pass']) ? $a_attribs['pass'] : 0,
185  ($a_attribs["points"]) ? $a_attribs["points"] : 0,
186  ($a_attribs["maxpoints"]) ? $a_attribs["maxpoints"] : 0,
187  $a_attribs["questioncount"],
188  $a_attribs["answeredquestions"],
189  ($a_attribs["workingtime"]) ? $a_attribs["workingtime"] : 0,
190  $a_attribs["tstamp"]
191  ]
192  );
193  break;
194  case 'tst_result_cache':
195  $affectedRows = $this->db->manipulateF(
196  "INSERT INTO tst_result_cache (active_fi, pass, max_points, reached_points, mark_short, mark_official, passed, failed, tstamp) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s)",
197  [
198  'integer',
199  'integer',
200  'float',
201  'float',
202  'text',
203  'text',
204  'integer',
205  'integer',
206  'integer'
207  ],
208  [
209  $this->active_id_mapping[$a_attribs['active_fi']],
210  strlen($a_attribs['pass']) ? $a_attribs['pass'] : 0,
211  ($a_attribs["max_points"]) ? $a_attribs["max_points"] : 0,
212  ($a_attribs["reached_points"]) ? $a_attribs["reached_points"] : 0,
213  strlen($a_attribs["mark_short"]) ? $a_attribs["mark_short"] : " ",
214  strlen($a_attribs["mark_official"]) ? $a_attribs["mark_official"] : " ",
215  ($a_attribs["passed"]) ? 1 : 0,
216  ($a_attribs["failed"]) ? 1 : 0,
217  $a_attribs["tstamp"]
218  ]
219  );
220  break;
221  case 'tst_sequence':
222  $affectedRows = $this->db->insert("tst_sequence", [
223  "active_fi" => ["integer", $this->active_id_mapping[$a_attribs['active_fi']]],
224  "pass" => ["integer", $a_attribs['pass']],
225  "sequence" => ["clob", $a_attribs['sequence']],
226  "postponed" => ["text", (strlen($a_attribs['postponed'])) ? $a_attribs['postponed'] : null],
227  "hidden" => ["text", (strlen($a_attribs['hidden'])) ? $a_attribs['hidden'] : null],
228  "tstamp" => ["integer", $a_attribs['tstamp']]
229  ]);
230  break;
231  case 'tst_solutions':
232  $next_id = $this->db->nextId('tst_solutions');
233  $affectedRows = $this->db->insert("tst_solutions", [
234  "solution_id" => ["integer", $next_id],
235  "active_fi" => ["integer", $this->active_id_mapping[$a_attribs['active_fi']]],
236  "question_fi" => ["integer", $this->question_id_mapping[$a_attribs['question_fi']]],
237  "value1" => ["clob", $this->importParticipantsUploadedFiles($a_attribs)],
238  "value2" => ["clob", (strlen($a_attribs['value2'])) ? $a_attribs['value2'] : null],
239  "pass" => ["integer", $a_attribs['pass']],
240  "tstamp" => ["integer", $a_attribs['tstamp']]
241  ]);
242  break;
243  case 'tst_test_result':
244  $next_id = $this->db->nextId('tst_test_result');
245  $affectedRows = $this->db->manipulateF(
246  "INSERT INTO tst_test_result (test_result_id, active_fi, question_fi, points, pass, manual, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
247  ['integer', 'integer','integer', 'float', 'integer', 'integer','integer'],
248  [$next_id, $this->active_id_mapping[$a_attribs['active_fi']], $this->question_id_mapping[$a_attribs['question_fi']], $a_attribs['points'], $a_attribs['pass'], (strlen($a_attribs['manual'])) ? $a_attribs['manual'] : 0, $a_attribs['tstamp']]
249  );
250  break;
251  case 'tst_times':
252  $next_id = $this->db->nextId('tst_times');
253  $affectedRows = $this->db->manipulateF(
254  "INSERT INTO tst_times (times_id, active_fi, started, finished, pass, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
255  ['integer', 'integer', 'timestamp', 'timestamp', 'integer', 'integer'],
256  [$next_id, $this->active_id_mapping[$a_attribs['active_fi']], $a_attribs['started'], $a_attribs['finished'], $a_attribs['pass'], $a_attribs['tstamp']]
257  );
258  break;
259  }
260  break;
261  default:
262  $this->table = $a_name;
263  break;
264  }
265  }
const ANONYMOUS_USER_ID
Definition: constants.php:27
This class gives all kind of DB information using the database manager and reverse module...
+ Here is the call graph for this function:

◆ handlerEndTag()

ilTestResultsImportParser::handlerEndTag (   $a_xml_parser,
  $a_name 
)

handler for end of element

Definition at line 270 of file class.ilTestResultsImportParser.php.

270  : void
271  {
272  switch (strtolower($a_name)) {
273  case 'tst_active':
274  $this->log->info('active id mapping: ' . print_r($this->active_id_mapping, true));
275  break;
276  case 'tst_test_question':
277  $this->log->info('question id mapping: ' . print_r($this->question_id_mapping, true));
278  break;
279  }
280  }

◆ handlerParseCharacterData()

ilTestResultsImportParser::handlerParseCharacterData (   $a_xml_parser,
  $a_data 
)

handler for character data

Definition at line 285 of file class.ilTestResultsImportParser.php.

285  : void
286  {
287  // do nothing
288  }

◆ importParticipantsUploadedFiles()

ilTestResultsImportParser::importParticipantsUploadedFiles ( array  $a_attribs)
private
Parameters
array{value1?string, value2: ?string} $a_attribs
Returns
?string

Definition at line 329 of file class.ilTestResultsImportParser.php.

References getFirstFileName().

Referenced by handlerBeginTag().

329  : ?string
330  {
331  ['value1' => $value1, 'value2' => $value2] = $a_attribs;
332 
333  if ($value2 !== 'rid') {
334  return $value1 !== '' ? $value1 : null;
335  }
336 
337  $resource_directory = "$this->import_directory/objects/resources/$value1";
338  $file_name = $this->getFirstFileName($resource_directory);
339  if (!is_string($file_name)) {
340  return $value1 !== '' ? $value1 : null;
341  }
342 
343  $file_path = "$resource_directory/$file_name";
344  $new_rid = $this->irss->manage()->stream(
345  new Stream(fopen($file_path, 'rwb')),
347  basename($file_path),
348  );
349  return $new_rid->serialize();
350  }
getFirstFileName(string $resource_directory)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlers()

ilTestResultsImportParser::setHandlers (   $a_xml_parser)

set event handler should be overwritten by inherited class private

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

93  : void
94  {
95  xml_set_object($a_xml_parser, $this);
96  xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
97  xml_set_character_data_handler($a_xml_parser, 'handlerParseCharacterData');
98  }

◆ setQuestionIdMapping()

ilTestResultsImportParser::setQuestionIdMapping ( array  $question_id_mapping)
Parameters
array$question_id_mapping

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

References $question_id_mapping.

67  : void
68  {
69  $this->question_id_mapping = $question_id_mapping;
70  }

◆ setSrcPoolDefIdMapping()

ilTestResultsImportParser::setSrcPoolDefIdMapping ( array  $src_pool_def_id_mapping)
Parameters
array$src_pool_def_id_mapping

Definition at line 83 of file class.ilTestResultsImportParser.php.

References $src_pool_def_id_mapping.

83  : void
84  {
85  $this->src_pool_def_id_mapping = $src_pool_def_id_mapping;
86  }

Field Documentation

◆ $active_id_mapping

ilTestResultsImportParser::$active_id_mapping
private

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

◆ $import_directory

string ilTestResultsImportParser::$import_directory
private

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

◆ $question_id_mapping

ilTestResultsImportParser::$question_id_mapping
private

◆ $src_pool_def_id_mapping

ilTestResultsImportParser::$src_pool_def_id_mapping
protected

◆ $table

ilTestResultsImportParser::$table
private

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

◆ $user_criteria_checked

bool ilTestResultsImportParser::$user_criteria_checked = false
private

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

◆ $user_criteria_field

string ilTestResultsImportParser::$user_criteria_field = ''
private

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

◆ $user_criteria_type

string ilTestResultsImportParser::$user_criteria_type = ''
private

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


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