19 declare(strict_types=1);
50 $this->active_id_mapping = [];
51 $this->question_id_mapping = [];
52 $this->src_pool_def_id_mapping = [];
53 $this->import_directory = dirname($a_xml_file);
95 xml_set_object($a_xml_parser, $this);
96 xml_set_element_handler($a_xml_parser,
'handlerBeginTag',
'handlerEndTag');
97 xml_set_character_data_handler($a_xml_parser,
'handlerParseCharacterData');
105 switch (strtolower($a_name)) {
109 switch ($this->table) {
111 if (!$this->user_criteria_checked) {
112 $this->user_criteria_checked =
true;
113 if (isset($a_attribs[
'user_criteria'])
114 && $this->db->tableColumnExists(
'usr_data', $a_attribs[
'user_criteria'])) {
116 $info = $analyzer->getFieldInformation(
'usr_data');
117 $this->user_criteria_field = $a_attribs[
'user_criteria'];
118 $this->user_criteria_type = $info[$a_attribs[
'user_criteria']][
'type'];
122 if ($this->user_criteria_field !==
'') {
123 $result = $this->db->queryF(
124 'SELECT usr_id FROM usr_data WHERE ' 125 . $this->user_criteria_field .
' = %s',
126 [$this->user_criteria_type],
127 [$a_attribs[$this->user_criteria_field]]
129 if ($result->numRows()) {
130 $row = $this->db->fetchAssoc($result);
131 $usr_id = $row[
'usr_id'];
134 $next_id = $this->db->nextId(
'tst_active');
136 $this->db->insert(
'tst_active', [
137 'active_id' => [
'integer', $next_id],
138 'user_fi' => [
'integer', $usr_id],
139 'anonymous_id' => [
'text', strlen($a_attribs[
'anonymous_id']) ? $a_attribs[
'anonymous_id'] : null],
140 'test_fi' => [
'integer', $this->test_obj->getTestId()],
141 'lastindex' => [
'integer', $a_attribs[
'lastindex']],
142 'tries' => [
'integer', $a_attribs[
'tries']],
143 'submitted' => [
'integer', $a_attribs[
'submitted']],
144 'submittimestamp' => [
'timestamp', strlen($a_attribs[
'submittimestamp']) ? $a_attribs[
'submittimestamp'] : null],
145 'tstamp' => [
'integer', $a_attribs[
'tstamp']],
146 'importname' => [
'text', $a_attribs[
'fullname']],
149 'answerstatusfilter' => [
'integer', $this->
fetchAttribute($a_attribs,
'answer_status_filter')],
150 'objective_container' => [
'integer', $this->
fetchAttribute($a_attribs,
'objective_container')]
152 $this->active_id_mapping[$a_attribs[
'active_id']] = $next_id;
154 case 'tst_test_rnd_qst':
155 $nextId = $this->db->nextId(
'tst_test_rnd_qst');
156 $newActiveId = $this->active_id_mapping[$a_attribs[
'active_fi']];
157 $newQuestionId = $this->question_id_mapping[$a_attribs[
'question_fi']];
158 $newSrcPoolDefId = $this->src_pool_def_id_mapping[$a_attribs[
'src_pool_def_fi']];
159 $this->db->insert(
'tst_test_rnd_qst', [
160 'test_random_question_id' => [
'integer', $nextId],
161 'active_fi' => [
'integer', $newActiveId],
162 'question_fi' => [
'integer', $newQuestionId],
163 'sequence' => [
'integer', $a_attribs[
'sequence']],
164 'pass' => [
'integer', $a_attribs[
'pass']],
165 'tstamp' => [
'integer', $a_attribs[
'tstamp']],
166 'src_pool_def_fi' => [
'integer', $newSrcPoolDefId]
169 case 'tst_pass_result':
170 $affectedRows = $this->db->manipulateF(
171 "INSERT INTO tst_pass_result (active_fi, pass, points, maxpoints, questioncount, answeredquestions, workingtime, tstamp) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",
183 $this->active_id_mapping[$a_attribs[
'active_fi']],
184 strlen($a_attribs[
'pass']) ? $a_attribs[
'pass'] : 0,
185 ($a_attribs[
"points"]) ? $a_attribs[
"points"] : 0,
186 ($a_attribs[
"maxpoints"]) ? $a_attribs[
"maxpoints"] : 0,
187 $a_attribs[
"questioncount"],
188 $a_attribs[
"answeredquestions"],
189 ($a_attribs[
"workingtime"]) ? $a_attribs[
"workingtime"] : 0,
194 case 'tst_result_cache':
195 $affectedRows = $this->db->manipulateF(
196 "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)",
209 $this->active_id_mapping[$a_attribs[
'active_fi']],
210 strlen($a_attribs[
'pass']) ? $a_attribs[
'pass'] : 0,
211 ($a_attribs[
"max_points"]) ? $a_attribs[
"max_points"] : 0,
212 ($a_attribs[
"reached_points"]) ? $a_attribs[
"reached_points"] : 0,
213 strlen($a_attribs[
"mark_short"]) ? $a_attribs[
"mark_short"] :
" ",
214 strlen($a_attribs[
"mark_official"]) ? $a_attribs[
"mark_official"] :
" ",
215 ($a_attribs[
"passed"]) ? 1 : 0,
216 ($a_attribs[
"failed"]) ? 1 : 0,
222 $affectedRows = $this->db->insert(
"tst_sequence", [
223 "active_fi" => [
"integer", $this->active_id_mapping[$a_attribs[
'active_fi']]],
224 "pass" => [
"integer", $a_attribs[
'pass']],
225 "sequence" => [
"clob", $a_attribs[
'sequence']],
226 "postponed" => [
"text", (strlen($a_attribs[
'postponed'])) ? $a_attribs[
'postponed'] : null],
227 "hidden" => [
"text", (strlen($a_attribs[
'hidden'])) ? $a_attribs[
'hidden'] : null],
228 "tstamp" => [
"integer", $a_attribs[
'tstamp']]
231 case 'tst_solutions':
232 $next_id = $this->db->nextId(
'tst_solutions');
233 $affectedRows = $this->db->insert(
"tst_solutions", [
234 "solution_id" => [
"integer", $next_id],
235 "active_fi" => [
"integer", $this->active_id_mapping[$a_attribs[
'active_fi']]],
236 "question_fi" => [
"integer", $this->question_id_mapping[$a_attribs[
'question_fi']]],
238 "value2" => [
"clob", (strlen($a_attribs[
'value2'])) ? $a_attribs[
'value2'] : null],
239 "pass" => [
"integer", $a_attribs[
'pass']],
240 "tstamp" => [
"integer", $a_attribs[
'tstamp']]
243 case 'tst_test_result':
244 $next_id = $this->db->nextId(
'tst_test_result');
245 $affectedRows = $this->db->manipulateF(
246 "INSERT INTO tst_test_result (test_result_id, active_fi, question_fi, points, pass, manual, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
247 [
'integer',
'integer',
'integer',
'float',
'integer',
'integer',
'integer'],
248 [$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']]
252 $next_id = $this->db->nextId(
'tst_times');
253 $affectedRows = $this->db->manipulateF(
254 "INSERT INTO tst_times (times_id, active_fi, started, finished, pass, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
255 [
'integer',
'integer',
'timestamp',
'timestamp',
'integer',
'integer'],
256 [$next_id, $this->active_id_mapping[$a_attribs[
'active_fi']], $a_attribs[
'started'], $a_attribs[
'finished'], $a_attribs[
'pass'], $a_attribs[
'tstamp']]
262 $this->table = $a_name;
272 switch (strtolower($a_name)) {
274 $this->log->info(
'active id mapping: ' . print_r($this->active_id_mapping,
true));
276 case 'tst_test_question':
277 $this->log->info(
'question id mapping: ' . print_r($this->question_id_mapping,
true));
292 if (isset($attributes[$name])) {
293 return $attributes[$name];
301 if (isset($attribs[
'last_finished_pass'])) {
302 return (
int) $attribs[
'last_finished_pass'];
305 if ($attribs[
'tries'] > 0) {
306 return $attribs[
'tries'] - 1;
314 if (isset($attribs[
'last_started_pass'])) {
315 return (
int) $attribs[
'last_started_pass'];
318 if ($attribs[
'tries'] > 0) {
319 return (
int) $attribs[
'tries'] - 1;
331 [
'value1' => $value1,
'value2' => $value2] = $a_attribs;
333 if ($value2 !==
'rid') {
334 return $value1 !==
'' ? $value1 : null;
337 $resource_directory =
"$this->import_directory/objects/resources/$value1";
339 if (!is_string($file_name)) {
340 return $value1 !==
'' ? $value1 : null;
343 $file_path =
"$resource_directory/$file_name";
344 $new_rid = $this->irss->manage()->stream(
345 new Stream(fopen($file_path,
'rwb')),
347 basename($file_path),
349 return $new_rid->serialize();
354 $entries = array_filter(
355 scandir($resource_directory),
356 static fn(
string $entry):
bool => is_file(
"$resource_directory/$entry") && !in_array($entry, [
'.',
'..']),
358 return array_shift($entries);
bool $user_criteria_checked
handlerParseCharacterData($a_xml_parser, $a_data)
handler for character data
__construct(?string $a_xml_file, private ilObjTest $test_obj, private ilDBInterface $db, private TestLogger $log, private ResourceStorage $irss)
Constructor.
importParticipantsUploadedFiles(array $a_attribs)
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)
__construct(Container $dic, ilPlugin $plugin)
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