ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilTestResultsImportParser Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilTestResultsImportParser:
+ Collaboration diagram for ilTestResultsImportParser:

Public Member Functions

 __construct (?string $a_xml_file, &$test_object)
 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)
 

Private Attributes

 $tst_obj
 
 $table
 
 $active_id_mapping
 
 $question_id_mapping
 
 $user_criteria_field
 
 $user_criteria_type
 
bool $user_criteria_checked = false
 
 $depth
 

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

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

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

Constructor & Destructor Documentation

◆ __construct()

ilTestResultsImportParser::__construct ( ?string  $a_xml_file,
$test_object 
)

Constructor.

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

References ILIAS\GlobalScreen\Provider\__construct().

37  {
38  parent::__construct($a_xml_file, true);
39  $this->tst_obj = &$test_object;
40  $this->table = '';
41  $this->active_id_mapping = array();
42  $this->question_id_mapping = array();
43  $this->user_criteria_checked = false;
44  $this->src_pool_def_id_mapping = array();
45  }
__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 286 of file class.ilTestResultsImportParser.php.

References $attributes, and $name.

Referenced by handlerBeginTag().

287  {
288  if (isset($attributes[$name])) {
289  return $attributes[$name];
290  }
291 
292  return null;
293  }
$attributes
Definition: metadata.php:248
if($format !==null) $name
Definition: metadata.php:247
+ Here is the caller graph for this function:

◆ fetchLastFinishedPass()

ilTestResultsImportParser::fetchLastFinishedPass (   $attribs)
private

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

Referenced by handlerBeginTag().

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

◆ fetchLastStartedPass()

ilTestResultsImportParser::fetchLastStartedPass (   $attribs)
private

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

Referenced by handlerBeginTag().

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

◆ getQuestionIdMapping()

ilTestResultsImportParser::getQuestionIdMapping ( )
Returns
array

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

References $question_id_mapping.

50  : array
51  {
53  }

◆ getSrcPoolDefIdMapping()

ilTestResultsImportParser::getSrcPoolDefIdMapping ( )
Returns
array

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

References $DIC, $ilDB, ANONYMOUS_USER_ID, fetchAttribute(), fetchLastFinishedPass(), and fetchLastStartedPass().

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

◆ handlerEndTag()

ilTestResultsImportParser::handlerEndTag (   $a_xml_parser,
  $a_name 
)

handler for end of element

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

References $DIC.

262  : void
263  {
264  switch (strtolower($a_name)) {
265  case "tst_active":
266  global $DIC;
267  $ilLog = $DIC['ilLog'];
268  $ilLog->write("active id mapping: " . print_r($this->active_id_mapping, true));
269  break;
270  case "tst_test_question":
271  global $DIC;
272  $ilLog = $DIC['ilLog'];
273  $ilLog->write("question id mapping: " . print_r($this->question_id_mapping, true));
274  break;
275  }
276  }
global $DIC
Definition: feed.php:28

◆ handlerParseCharacterData()

ilTestResultsImportParser::handlerParseCharacterData (   $a_xml_parser,
  $a_data 
)

handler for character data

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

281  : void
282  {
283  // do nothing
284  }

◆ setHandlers()

ilTestResultsImportParser::setHandlers (   $a_xml_parser)

set event handler should be overwritten by inherited class private

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

84  : void
85  {
86  xml_set_object($a_xml_parser, $this);
87  xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
88  xml_set_character_data_handler($a_xml_parser, 'handlerParseCharacterData');
89  }

◆ setQuestionIdMapping()

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

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

References $question_id_mapping.

58  : void
59  {
60  $this->question_id_mapping = $question_id_mapping;
61  }

◆ setSrcPoolDefIdMapping()

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

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

References $src_pool_def_id_mapping.

74  : void
75  {
76  $this->src_pool_def_id_mapping = $src_pool_def_id_mapping;
77  }

Field Documentation

◆ $active_id_mapping

ilTestResultsImportParser::$active_id_mapping
private

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

◆ $depth

ilTestResultsImportParser::$depth
private

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

◆ $tst_obj

ilTestResultsImportParser::$tst_obj
private

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

◆ $user_criteria_checked

bool ilTestResultsImportParser::$user_criteria_checked = false
private

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

◆ $user_criteria_field

ilTestResultsImportParser::$user_criteria_field
private

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

◆ $user_criteria_type

ilTestResultsImportParser::$user_criteria_type
private

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


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