ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilTestResultsImportParser.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11include_once("./Services/Xml/classes/class.ilSaxParser.php");
12
14{
15 private $tst_obj;
16 private $table;
21 private $user_criteria_checked = false;
22
26 function __construct($a_xml_file, &$test_object)
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 }
35
41 function setHandlers($a_xml_parser)
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 }
47
51 function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
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 }
220
224 function handlerEndTag($a_xml_parser,$a_name)
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 }
238
242 function handlerParseCharacterData($a_xml_parser,$a_data)
243 {
244 // do nothing
245 }
246
247 private function fetchAttribute($attributes, $name)
248 {
249 if( isset($attributes[$name]) )
250 {
251 return $attributes[$name];
252 }
253
254 return null;
255 }
256
257 private function fetchLastFinishedPass($attribs)
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 }
271}
272?>
$result
This class gives all kind of DB information using the MDB2 manager and reverse module.
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class @access private
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element parser
handlerParseCharacterData($a_xml_parser, $a_data)
handler for character data
__construct($a_xml_file, &$test_object)
Constructor.
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
$info
Definition: example_052.php:80
global $ilDB