ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilTestResultsImportParser Class Reference

Test results import parser. More...

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

Public Member Functions

 __construct ($a_xml_file, &$test_object)
 Constructor. More...
 
 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
 ilSaxParser ($a_xml_file='', $throwException=false)
 Constructor setup ILIAS global object public. More...
 
 setXMLContent ($a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 create parser More...
 
 setOptions ($a_xml_parser)
 set parser options More...
 
 setHandlers ($a_xml_parser)
 set event handler should be overwritten by inherited class private More...
 
 openXMLFile ()
 open xml file More...
 
 parse ($a_xml_parser, $a_fp=null)
 parse xml file More...
 
 freeParser ($a_xml_parser)
 free xml parser handle More...
 
 setThrowException ($throwException)
 set error handling More...
 
- Public Member Functions inherited from PEAR
 PEAR ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). More...
 
getStaticProperty ($class, $var)
 If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them. More...
 
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes. More...
 
 isError ($data, $code=null)
 Tell whether a value is a PEAR error. More...
 
 setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. More...
 
 expectError ($code=' *')
 This method is used to tell which errors you expect to get. More...
 
 popExpect ()
 This method pops one element off the expected error codes stack. More...
 
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available. More...
 
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack. More...
 
raiseError ($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
 This method is a wrapper that returns an instance of the configured error class with this object's default error handling applied. More...
 
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options. More...
 
 staticPushErrorHandling ($mode, $options=null)
 
 staticPopErrorHandling ()
 
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack. More...
 
 popErrorHandling ()
 Pop the last error handler used. More...
 
 loadExtension ($ext)
 OS independant PHP extension load. More...
 

Private Member Functions

 fetchAttribute ($attributes, $name)
 
 fetchLastFinishedPass ($attribs)
 

Private Attributes

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

Additional Inherited Members

- Data Fields inherited from ilSaxParser
 $input_type = null
 
 $xml_content = ''
 
 $ilias
 
 $lng
 
 $xml_file
 
 $throwException = false
 
- Data Fields inherited from PEAR
 $_debug = false
 
 $_default_error_mode = null
 
 $_default_error_options = null
 
 $_default_error_handler = ''
 
 $_error_class = 'PEAR_Error'
 
 $_expected_errors = array()
 
- Protected Member Functions inherited from ilSaxParser
 handleError ($message, $code)
 use given error handler to handle error message or internal ilias error message handle More...
 

Detailed Description

Test results import parser.

Author
Helmut Schottmüller ilias.nosp@m.@aur.nosp@m.ealis.nosp@m..de
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

ilTestResultsImportParser::__construct (   $a_xml_file,
$test_object 
)

Constructor.

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

27  {
28  parent::__construct($a_xml_file, true);
29  $this->tst_obj = &$test_object;
30  $this->table = '';
31  $this->active_id_mapping = array();
32  $this->question_id_mapping = array();
33  $this->user_criteria_checked = false;
34  }

Member Function Documentation

◆ fetchAttribute()

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

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

Referenced by handlerBeginTag().

248  {
249  if( isset($attributes[$name]) )
250  {
251  return $attributes[$name];
252  }
253 
254  return null;
255  }
+ Here is the caller graph for this function:

◆ fetchLastFinishedPass()

ilTestResultsImportParser::fetchLastFinishedPass (   $attribs)
private

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

Referenced by handlerBeginTag().

258  {
259  if( isset($attribs['last_finished_pass']) )
260  {
261  return $attribs['last_finished_pass'];
262  }
263 
264  if( $attribs['tries'] > 0 )
265  {
266  return $attribs['tries'] - 1;
267  }
268 
269  return null;
270  }
+ Here is the caller graph for this function:

◆ handlerBeginTag()

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

handler for begin of element parser

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

References $ilDB, $ilLog, $info, $result, $row, fetchAttribute(), and fetchLastFinishedPass().

52  {
53  global $ilDB;
54 
55  $this->sametag = FALSE;
56  $this->characterbuffer = "";
57  $this->depth[$a_xml_parser]++;
58  $this->path[$this->depth[$a_xml_parser]] = strtolower($a_name);
59  $this->qti_element = $a_name;
60 
61  switch (strtolower($a_name))
62  {
63  case "results":
64  break;
65  case "row":
66  switch ($this->table)
67  {
68  case 'tst_active':
69  if (!$this->user_criteria_checked)
70  {
71  $this->user_criteria_checked = true;
72  if ($ilDB->tableColumnExists('usr_data', $a_attribs['user_criteria']))
73  {
74  include_once './Services/Database/classes/class.ilDBAnalyzer.php';
75  $analyzer = new ilDBAnalyzer();
76  $info = $analyzer->getFieldInformation('usr_data');
77  $this->user_criteria_field = $a_attribs['user_criteria'];
78  $this->user_criteria_type = $info[$a_attribs['user_criteria']]['type'];
79  }
80  }
81  $usr_id = ANONYMOUS_USER_ID;
82  if (strlen($this->user_criteria_field))
83  {
84  $result = $ilDB->queryF("SELECT usr_id FROM usr_data WHERE " . $this->user_criteria_field . " = %s",
85  array($this->user_criteria_type),
86  array($a_attribs[$this->user_criteria_field])
87  );
88  if ($result->numRows())
89  {
90  $row = $ilDB->fetchAssoc($result);
91  $usr_id = $row['usr_id'];
92  }
93  }
94  $next_id = $ilDB->nextId('tst_active');
95 
96  $ilDB->insert('tst_active', array(
97  'active_id' => array('integer', $next_id),
98  'user_fi' => array('integer', $usr_id),
99  'anonymous_id' => array('text', strlen($a_attribs['anonymous_id']) ? $a_attribs['anonymous_id'] : NULL),
100  'test_fi' => array('integer', $this->tst_obj->getTestId()),
101  'lastindex' => array('integer', $a_attribs['lastindex']),
102  'tries' => array('integer', $a_attribs['tries']),
103  'submitted' => array('integer', $a_attribs['submitted']),
104  'submittimestamp' => array('timestamp', strlen($a_attribs['submittimestamp']) ? $a_attribs['submittimestamp'] : NULL),
105  'tstamp' => array('integer', $a_attribs['tstamp']),
106  'importname' => array('text', $a_attribs['fullname']),
107  'last_finished_pass' => array('integer', $this->fetchLastFinishedPass($a_attribs)),
108  'answerstatusfilter' => array('integer', $this->fetchAttribute($a_attribs, 'answer_status_filter')),
109  'objective_container' => array('integer', $this->fetchAttribute($a_attribs, 'objective_container'))
110  ));
111  $this->active_id_mapping[$a_attribs['active_id']] = $next_id;
112  break;
113  case 'tst_test_question':
114  $questions = $this->tst_obj->getQuestions();
115  $id = $questions[$a_attribs['sequence']];
116  if ($id > 0)
117  {
118  $this->question_id_mapping[$a_attribs['question_fi']] = $id;
119  }
120  else
121  {
122  $this->question_id_mapping[$a_attribs['question_fi']] = $a_attribs['question_fi'];
123  global $ilLog;
124  $ilLog->write("Error: Could not find question for sequence " . $a_attribs['sequence'] . " of test id " . $this->tst_obj->getTestId());
125  }
126  break;
127  case 'tst_pass_result':
128  $affectedRows = $ilDB->manipulateF("INSERT INTO tst_pass_result (active_fi, pass, points, maxpoints, questioncount, answeredquestions, workingtime, tstamp) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",
129  array(
130  'integer',
131  'integer',
132  'float',
133  'float',
134  'integer',
135  'integer',
136  'integer',
137  'integer'
138  ),
139  array(
140  $this->active_id_mapping[$a_attribs['active_fi']],
141  strlen($a_attribs['pass']) ? $a_attribs['pass'] : 0,
142  ($a_attribs["points"]) ? $a_attribs["points"] : 0,
143  ($a_attribs["maxpoints"]) ? $a_attribs["maxpoints"] : 0,
144  $a_attribs["questioncount"],
145  $a_attribs["answeredquestions"],
146  ($a_attribs["workingtime"]) ? $a_attribs["workingtime"] : 0,
147  $a_attribs["tstamp"]
148  )
149  );
150  break;
151  case 'tst_result_cache':
152  $affectedRows = $ilDB->manipulateF("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)",
153  array(
154  'integer',
155  'integer',
156  'float',
157  'float',
158  'text',
159  'text',
160  'integer',
161  'integer',
162  'integer'
163  ),
164  array(
165  $this->active_id_mapping[$a_attribs['active_fi']],
166  strlen($a_attribs['pass']) ? $a_attribs['pass'] : 0,
167  ($a_attribs["max_points"]) ? $a_attribs["max_points"] : 0,
168  ($a_attribs["reached_points"]) ? $a_attribs["reached_points"] : 0,
169  strlen($a_attribs["mark_short"]) ? $a_attribs["mark_short"] : " ",
170  strlen($a_attribs["mark_official"]) ? $a_attribs["mark_official"] : " ",
171  ($a_attribs["passed"]) ? 1 : 0,
172  ($a_attribs["failed"]) ? 1 : 0,
173  $a_attribs["tstamp"]
174  )
175  );
176  break;
177  case 'tst_sequence':
178  $affectedRows = $ilDB->insert("tst_sequence", array(
179  "active_fi" => array("integer", $this->active_id_mapping[$a_attribs['active_fi']]),
180  "pass" => array("integer", $a_attribs['pass']),
181  "sequence" => array("clob", $a_attribs['sequence']),
182  "postponed" => array("text", (strlen($a_attribs['postponed'])) ? $a_attribs['postponed'] : NULL),
183  "hidden" => array("text", (strlen($a_attribs['hidden'])) ? $a_attribs['hidden'] : NULL),
184  "tstamp" => array("integer", $a_attribs['tstamp'])
185  ));
186  break;
187  case 'tst_solutions':
188  $next_id = $ilDB->nextId('tst_solutions');
189  $affectedRows = $ilDB->insert("tst_solutions", array(
190  "solution_id" => array("integer", $next_id),
191  "active_fi" => array("integer", $this->active_id_mapping[$a_attribs['active_fi']]),
192  "question_fi" => array("integer", $this->question_id_mapping[$a_attribs['question_fi']]),
193  "value1" => array("clob", (strlen($a_attribs['value1'])) ? $a_attribs['value1'] : NULL),
194  "value2" => array("clob", (strlen($a_attribs['value2'])) ? $a_attribs['value2'] : NULL),
195  "pass" => array("integer", $a_attribs['pass']),
196  "tstamp" => array("integer", $a_attribs['tstamp'])
197  ));
198  break;
199  case 'tst_test_result':
200  $next_id = $ilDB->nextId('tst_test_result');
201  $affectedRows = $ilDB->manipulateF("INSERT INTO tst_test_result (test_result_id, active_fi, question_fi, points, pass, manual, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
202  array('integer', 'integer','integer', 'float', 'integer', 'integer','integer'),
203  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'])
204  );
205  break;
206  case 'tst_times':
207  $next_id = $ilDB->nextId('tst_times');
208  $affectedRows = $ilDB->manipulateF("INSERT INTO tst_times (times_id, active_fi, started, finished, pass, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
209  array('integer', 'integer', 'timestamp', 'timestamp', 'integer', 'integer'),
210  array($next_id, $this->active_id_mapping[$a_attribs['active_fi']], $a_attribs['started'], $a_attribs['finished'], $a_attribs['pass'], $a_attribs['tstamp'])
211  );
212  break;
213  }
214  break;
215  default:
216  $this->table = $a_name;
217  break;
218  }
219  }
$result
$info
Definition: example_052.php:80
global $ilDB
This class gives all kind of DB information using the MDB2 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 224 of file class.ilTestResultsImportParser.php.

References $ilLog.

225  {
226  switch (strtolower($a_name))
227  {
228  case "tst_active":
229  global $ilLog;
230  $ilLog->write("active id mapping: " . print_r($this->active_id_mapping, true));
231  break;
232  case "tst_test_question":
233  global $ilLog;
234  $ilLog->write("question id mapping: " . print_r($this->question_id_mapping, true));
235  break;
236  }
237  }

◆ handlerParseCharacterData()

ilTestResultsImportParser::handlerParseCharacterData (   $a_xml_parser,
  $a_data 
)

handler for character data

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

243  {
244  // do nothing
245  }

◆ setHandlers()

ilTestResultsImportParser::setHandlers (   $a_xml_parser)

set event handler should be overwritten by inherited class private

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

42  {
43  xml_set_object($a_xml_parser,$this);
44  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
45  xml_set_character_data_handler($a_xml_parser,'handlerParseCharacterData');
46  }

Field Documentation

◆ $active_id_mapping

ilTestResultsImportParser::$active_id_mapping
private

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

◆ $question_id_mapping

ilTestResultsImportParser::$question_id_mapping
private

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

◆ $table

ilTestResultsImportParser::$table
private

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

◆ $tst_obj

ilTestResultsImportParser::$tst_obj
private

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

◆ $user_criteria_checked

ilTestResultsImportParser::$user_criteria_checked = false
private

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

◆ $user_criteria_field

ilTestResultsImportParser::$user_criteria_field
private

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

◆ $user_criteria_type

ilTestResultsImportParser::$user_criteria_type
private

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


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