ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 ilLogger $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 24 of file class.ilTestResultsImportParser.php.

Constructor & Destructor Documentation

◆ __construct()

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

Constructor.

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

References ILIAS\MetaData\Repository\Validation\Data\__construct().

45  {
46  parent::__construct($a_xml_file, true);
47  $this->table = '';
48  $this->active_id_mapping = [];
49  $this->question_id_mapping = [];
50  $this->src_pool_def_id_mapping = [];
51  $this->import_directory = dirname($a_xml_file);
52  }
__construct(VocabulariesInterface $vocabularies)
+ Here is the call graph for this function:

Member Function Documentation

◆ fetchAttribute()

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

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

Referenced by handlerBeginTag().

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

◆ fetchLastFinishedPass()

ilTestResultsImportParser::fetchLastFinishedPass (   $attribs)
private

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

Referenced by handlerBeginTag().

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

◆ fetchLastStartedPass()

ilTestResultsImportParser::fetchLastStartedPass (   $attribs)
private

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

Referenced by handlerBeginTag().

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

◆ getFirstFileName()

ilTestResultsImportParser::getFirstFileName ( string  $resource_directory)
private

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

Referenced by importParticipantsUploadedFiles().

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

◆ getQuestionIdMapping()

ilTestResultsImportParser::getQuestionIdMapping ( )
Returns
array

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

References $question_id_mapping.

57  : array
58  {
60  }

◆ getSrcPoolDefIdMapping()

ilTestResultsImportParser::getSrcPoolDefIdMapping ( )
Returns
array

Definition at line 73 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 101 of file class.ilTestResultsImportParser.php.

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

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

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

◆ handlerParseCharacterData()

ilTestResultsImportParser::handlerParseCharacterData (   $a_xml_parser,
  $a_data 
)

handler for character data

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

283  : void
284  {
285  // do nothing
286  }

◆ importParticipantsUploadedFiles()

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

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

References getFirstFileName().

Referenced by handlerBeginTag().

327  : ?string
328  {
329  ['value1' => $value1, 'value2' => $value2] = $a_attribs;
330 
331  if ($value2 !== 'rid') {
332  return $value1 !== '' ? $value1 : null;
333  }
334 
335  $resource_directory = "$this->import_directory/objects/resources/$value1";
336  $file_name = $this->getFirstFileName($resource_directory);
337  if (!is_string($file_name)) {
338  return $value1 !== '' ? $value1 : null;
339  }
340 
341  $file_path = "$resource_directory/$file_name";
342  $new_rid = $this->irss->manage()->stream(
343  new Stream(fopen($file_path, 'rwb')),
345  basename($file_path),
346  );
347  return $new_rid->serialize();
348  }
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 91 of file class.ilTestResultsImportParser.php.

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

◆ setQuestionIdMapping()

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

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

References $question_id_mapping.

65  : void
66  {
67  $this->question_id_mapping = $question_id_mapping;
68  }

◆ setSrcPoolDefIdMapping()

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

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

References $src_pool_def_id_mapping.

81  : void
82  {
83  $this->src_pool_def_id_mapping = $src_pool_def_id_mapping;
84  }

Field Documentation

◆ $active_id_mapping

ilTestResultsImportParser::$active_id_mapping
private

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

◆ $import_directory

string ilTestResultsImportParser::$import_directory
private

Definition at line 34 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 26 of file class.ilTestResultsImportParser.php.

◆ $user_criteria_checked

bool ilTestResultsImportParser::$user_criteria_checked = false
private

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

◆ $user_criteria_field

string ilTestResultsImportParser::$user_criteria_field = ''
private

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

◆ $user_criteria_type

string ilTestResultsImportParser::$user_criteria_type = ''
private

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


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