19 declare(strict_types=1);
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);
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');
103 switch (strtolower($a_name)) {
107 switch ($this->table) {
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'])) {
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'];
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])
127 if ($result->numRows()) {
128 $row = $this->db->fetchAssoc($result);
129 $usr_id = $row[
'usr_id'];
132 $next_id = $this->db->nextId(
'tst_active');
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']),
147 'answerstatusfilter' => array(
'integer', $this->
fetchAttribute($a_attribs,
'answer_status_filter')),
148 'objective_container' => array(
'integer', $this->
fetchAttribute($a_attribs,
'objective_container'))
150 $this->active_id_mapping[$a_attribs[
'active_id']] = $next_id;
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)
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)",
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,
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)",
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,
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'])
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']]),
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'])
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'])
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'])
260 $this->table = $a_name;
270 switch (strtolower($a_name)) {
272 $this->log->write(
"active id mapping: " . print_r($this->active_id_mapping,
true));
274 case "tst_test_question":
275 $this->log->write(
"question id mapping: " . print_r($this->question_id_mapping,
true));
290 if (isset($attributes[$name])) {
291 return $attributes[$name];
299 if (isset($attribs[
'last_finished_pass'])) {
300 return (
int) $attribs[
'last_finished_pass'];
303 if ($attribs[
'tries'] > 0) {
304 return $attribs[
'tries'] - 1;
312 if (isset($attribs[
'last_started_pass'])) {
313 return (
int) $attribs[
'last_started_pass'];
316 if ($attribs[
'tries'] > 0) {
317 return (
int) $attribs[
'tries'] - 1;
329 [
'value1' => $value1,
'value2' => $value2] = $a_attribs;
331 if ($value2 !==
'rid') {
332 return $value1 !==
'' ? $value1 : null;
335 $resource_directory =
"$this->import_directory/objects/resources/$value1";
337 if (!is_string($file_name)) {
338 return $value1 !==
'' ? $value1 : null;
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),
347 return $new_rid->serialize();
352 $entries = array_filter(
353 scandir($resource_directory),
354 static fn(
string $entry):
bool => is_file(
"$resource_directory/$entry") && !in_array($entry, [
'.',
'..']),
356 return array_shift($entries);
bool $user_criteria_checked
handlerParseCharacterData($a_xml_parser, $a_data)
handler for character data
importParticipantsUploadedFiles(array $a_attribs)
__construct(?string $a_xml_file, private ilObjTest $test_obj, private ilDBInterface $db, private ilLogger $log, private ResourceStorage $irss)
Constructor.
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element parser
string $user_criteria_type
fetchLastFinishedPass($attribs)
fetchLastStartedPass($attribs)
fetchAttribute($attributes, $name)
This class gives all kind of DB information using the database manager and reverse module...
setQuestionIdMapping(array $question_id_mapping)
setSrcPoolDefIdMapping(array $src_pool_def_id_mapping)
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class private
getFirstFileName(string $resource_directory)
string $user_criteria_field