ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ilTestResultsToXML Class Reference
+ Inheritance diagram for ilTestResultsToXML:
+ Collaboration diagram for ilTestResultsToXML:

Public Member Functions

 __construct (private readonly ilObjTest $test_obj, private readonly ilDBInterface $db, private readonly ResourceStorage $irss, private readonly ilObjUser $user, private readonly ilLanguage $lng, private string $objects_export_directory)
 
 isIncludeRandomTestQuestionsEnabled ()
 
 setIncludeRandomTestQuestionsEnabled (bool $include_random_test_questions_enabled)
 
 getXML ()
 
 xmlDumpMem (bool $format=true)
 Returns xml document from memory. More...
 
 xmlDumpFile (string $file, bool $format=true)
 Dumps xml document from memory into a file. More...
 
- Public Member Functions inherited from ilXmlWriter
 __construct (string $version="1.0", string $outEnc="utf-8", string $inEnc="utf-8")
 
 xmlSetDtdDef (string $dtdDef)
 Sets dtd definition. More...
 
 xmlSetGenCmt (string $genCmt)
 Sets generated comment. More...
 
 xmlFormatData (string $data)
 Indents text for better reading. More...
 
 xmlHeader ()
 Writes xml header. More...
 
 xmlStartTag (string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
 Writes a starttag. More...
 
 xmlEndTag (string $tag)
 Writes an endtag. More...
 
 xmlData (string $data, bool $encode=true, bool $escape=true)
 Writes data. More...
 
 xmlElement (string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
 Writes a basic element (no children, just textual content) More...
 
 xmlDumpFile (string $file, bool $format=true)
 Dumps xml document from memory into a file. More...
 
 xmlDumpMem (bool $format=true)
 Returns xml document from memory. More...
 
 appendXML (string $a_str)
 append xml string to document More...
 
 xmlClear ()
 clears xmlStr More...
 

Protected Member Functions

 exportActiveIDs ()
 
 exportPassResult ()
 
 exportResultCache ()
 
 exportTestSequence ()
 
 exportTestSolutions ()
 
 exportRandomTestQuestions ()
 
 exportTestResults ()
 
 exportParticipantUploadedFiles (array $uploaded_files)
 
 exportTestTimes ()
 

Protected Attributes

bool $include_random_test_questions_enabled = false
 

Private Attributes

array $active_ids = []
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilTestResultsToXML::__construct ( private readonly ilObjTest  $test_obj,
private readonly ilDBInterface  $db,
private readonly ResourceStorage  $irss,
private readonly ilObjUser  $user,
private readonly ilLanguage  $lng,
private string  $objects_export_directory 
)

Definition at line 29 of file class.ilTestResultsToXML.php.

36 {
38 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

Member Function Documentation

◆ exportActiveIDs()

ilTestResultsToXML::exportActiveIDs ( )
protected

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

50 : void
51 {
52 $user_criteria = (new ilSetting('assessment'))->get('user_criteria', 'usr_id');
53
54 $query = $this->test_obj->getAnonymity()
55 ? 'SELECT * FROM tst_active WHERE test_fi = %s'
56 : "SELECT tst_active.*, usr_data.{$user_criteria} FROM tst_active, usr_data WHERE tst_active.test_fi = %s AND tst_active.user_fi = usr_data.usr_id";
57 $result = $this->db->queryF($query, [ilDBConstants::T_INTEGER], [$this->test_obj->getTestId()]);
58
59 $test_participant_list = new ilTestParticipantList($this->test_obj, $this->user, $this->lng, $this->db);
60 $test_participant_list->initializeFromDbRows($this->test_obj->getTestParticipants());
61
62 $this->xmlStartTag('tst_active', null);
63 while ($row = $this->db->fetchAssoc($result)) {
64 $this->active_ids[] = $row['active_id'];
65 $participant = $test_participant_list->getParticipantByActiveId($row['active_id']);
66
67 $attrs = [
68 'active_id' => $row['active_id'],
69 'user_fi' => $this->test_obj->getAnonymity() ? '' : ($row['user_fi'] ?? ''),
70 'fullname' => $participant ? $test_participant_list->buildFullname($participant) : '',
71 'anonymous_id' => $row['anonymous_id'] ?? '',
72 'test_fi' => $row['test_fi'],
73 'lastindex' => $row['lastindex'] ?? '',
74 'tries' => $row['tries'] ?? '',
75 'last_started_pass' => $row['last_started_pass'] ?? '',
76 'last_finished_pass' => $row['last_finished_pass'] ?? '',
77 'submitted' => $row['submitted'] ?? '',
78 'submittimestamp' => $row['submittimestamp'] ?? '',
79 'tstamp' => $row['tstamp'] ?? ''
80 ];
81
82 if (!$this->test_obj->getAnonymity()) {
83 $attrs['user_criteria'] = $user_criteria;
84 $attrs[$user_criteria] = $row[$user_criteria];
85 }
86
87 $this->xmlElement('row', $attrs);
88 }
89 $this->xmlEndTag('tst_active');
90 }
ILIAS Setting Class.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.

References ILIAS\Repository\lng(), ilDBConstants\T_INTEGER, ILIAS\Repository\user(), ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by getXML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exportParticipantUploadedFiles()

ilTestResultsToXML::exportParticipantUploadedFiles ( array  $uploaded_files)
protected
Parameters
array{value1string, value2: string} $uploaded_files

Definition at line 227 of file class.ilTestResultsToXML.php.

227 : void
228 {
229 foreach ($uploaded_files as $uploaded_file) {
230 if ($uploaded_file['value2'] !== 'rid') {
231 continue;
232 }
233
234 $rid_string = $uploaded_file['value1'];
235 $rid = $this->irss->manage()->find($rid_string);
236 if ($rid === null) {
237 continue;
238 }
239
240 $target_dir = "$this->objects_export_directory/resources/$rid_string";
241 ilFileUtils::makeDirParents($target_dir);
242 file_put_contents(
243 "$target_dir/{$this->irss->manage()->getCurrentRevision($rid)->getTitle()}",
244 $this->irss->consume()->stream($rid)->getStream(),
245 );
246 }
247 }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.

References ilFileUtils\makeDirParents().

Referenced by exportTestResults().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exportPassResult()

ilTestResultsToXML::exportPassResult ( )
protected

Definition at line 92 of file class.ilTestResultsToXML.php.

92 : void
93 {
94 $query = 'SELECT * FROM tst_pass_result WHERE ' . $this->db->in('active_fi', $this->active_ids, false, 'integer') . ' ORDER BY active_fi, pass';
95 $result = $this->db->query($query);
96 $this->xmlStartTag('tst_pass_result', null);
97 while ($row = $this->db->fetchAssoc($result)) {
98 $attrs = [
99 'active_fi' => $row['active_fi'],
100 'pass' => $row['pass'] ?? '',
101 'points' => $row['points'] ?? '',
102 'maxpoints' => $row['maxpoints'] ?? '',
103 'questioncount' => $row['questioncount'] ?? '',
104 'answeredquestions' => $row['answeredquestions'] ?? '',
105 'workingtime' => $row['workingtime'] ?? '',
106 'tstamp' => $row['tstamp'] ?? ''
107 ];
108 $this->xmlElement('row', $attrs);
109 }
110 $this->xmlEndTag('tst_pass_result');
111 }

References ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by getXML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exportRandomTestQuestions()

ilTestResultsToXML::exportRandomTestQuestions ( )
protected

Definition at line 175 of file class.ilTestResultsToXML.php.

175 : void
176 {
177 $result = $this->db->query("
178 SELECT * FROM tst_test_rnd_qst
179 WHERE {$this->db->in('active_fi', $this->active_ids, false, 'integer')}
180 ORDER BY test_random_question_id
181 ");
182
183 $this->xmlStartTag('tst_test_rnd_qst', null);
184 while ($row = $this->db->fetchAssoc($result)) {
185 $attrs = [];
186
187 foreach ($row as $field => $value) {
188 $attrs[$field] = $value;
189 }
190
191 $this->xmlElement('row', $attrs);
192 }
193 $this->xmlEndTag('tst_test_rnd_qst');
194 }

References ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by getXML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exportResultCache()

ilTestResultsToXML::exportResultCache ( )
protected

Definition at line 113 of file class.ilTestResultsToXML.php.

113 : void
114 {
115 $query = 'SELECT * FROM tst_result_cache WHERE ' . $this->db->in('active_fi', $this->active_ids, false, 'integer') . ' ORDER BY active_fi';
116 $result = $this->db->query($query);
117 $this->xmlStartTag('tst_result_cache', null);
118 while ($row = $this->db->fetchAssoc($result)) {
119 $attrs = [
120 'active_fi' => $row['active_fi'],
121 'pass' => $row['pass'],
122 'max_points' => $row['max_points'],
123 'reached_points' => $row['reached_points'],
124 'mark_short' => $row['mark_short'],
125 'mark_official' => $row['mark_official'],
126 'passed' => $row['passed'],
127 'failed' => $row['failed'],
128 'tstamp' => $row['tstamp']
129 ];
130 $this->xmlElement('row', $attrs);
131 }
132 $this->xmlEndTag('tst_result_cache');
133 }

References ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by getXML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exportTestResults()

ilTestResultsToXML::exportTestResults ( )
protected

Definition at line 197 of file class.ilTestResultsToXML.php.

197 : void
198 {
199 $query = 'SELECT * FROM tst_test_result WHERE ' . $this->db->in('active_fi', $this->active_ids, false, 'integer') . ' ORDER BY active_fi';
200 $result = $this->db->query($query);
201 $this->xmlStartTag('tst_test_result', null);
202 while ($row = $this->db->fetchAssoc($result)) {
203 $active_fi = $row['active_fi'];
204 $pass = $row['pass'] ?? '';
205 $attrs = [
206 'test_result_id' => $row['test_result_id'],
207 'active_fi' => $active_fi,
208 'question_fi' => $row['question_fi'],
209 'points' => $row['points'] ?? '',
210 'pass' => $pass,
211 'manual' => $row['manual'] ?? '',
212 'tstamp' => $row['tstamp'] ?? ''
213 ];
214
215 if (($question = assQuestion::instantiateQuestion($row['question_fi'])) instanceof assFileUpload) {
216 $this->exportParticipantUploadedFiles($question->getUploadedFiles($active_fi, $pass));
217 }
218
219 $this->xmlElement('row', $attrs);
220 }
221 $this->xmlEndTag('tst_test_result');
222 }
Class for file upload questions.
static instantiateQuestion(int $question_id)
exportParticipantUploadedFiles(array $uploaded_files)

References exportParticipantUploadedFiles(), assQuestion\instantiateQuestion(), ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by getXML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exportTestSequence()

ilTestResultsToXML::exportTestSequence ( )
protected

Definition at line 135 of file class.ilTestResultsToXML.php.

135 : void
136 {
137 $query = 'SELECT * FROM tst_sequence WHERE ' . $this->db->in('active_fi', $this->active_ids, false, 'integer') . ' ORDER BY active_fi, pass';
138 $result = $this->db->query($query);
139 $this->xmlStartTag('tst_sequence', null);
140 while ($row = $this->db->fetchAssoc($result)) {
141 $attrs = [
142 'active_fi' => $row['active_fi'],
143 'pass' => $row['pass'] ?? '',
144 'sequence' => $row['sequence'] ?? '',
145 'postponed' => $row['postponed'] ?? '',
146 'hidden' => $row['hidden'] ?? '',
147 'tstamp' => $row['tstamp'] ?? ''
148 ];
149 $this->xmlElement('row', $attrs);
150 }
151 $this->xmlEndTag('tst_sequence');
152 }

References ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by getXML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exportTestSolutions()

ilTestResultsToXML::exportTestSolutions ( )
protected

Definition at line 154 of file class.ilTestResultsToXML.php.

154 : void
155 {
156 $query = 'SELECT * FROM tst_solutions WHERE ' . $this->db->in('active_fi', $this->active_ids, false, 'integer') . ' ORDER BY solution_id';
157 $result = $this->db->query($query);
158 $this->xmlStartTag('tst_solutions', null);
159 while ($row = $this->db->fetchAssoc($result)) {
160 $attrs = [
161 'solution_id' => $row['solution_id'],
162 'active_fi' => $row['active_fi'],
163 'question_fi' => $row['question_fi'],
164 'points' => $row['points'] ?? '',
165 'pass' => $row['pass'] ?? '',
166 'value1' => $row['value1'] ?? '',
167 'value2' => $row['value2'] ?? '',
168 'tstamp' => $row['tstamp'] ?? ''
169 ];
170 $this->xmlElement('row', $attrs);
171 }
172 $this->xmlEndTag('tst_solutions');
173 }

References ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by getXML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exportTestTimes()

ilTestResultsToXML::exportTestTimes ( )
protected

Definition at line 249 of file class.ilTestResultsToXML.php.

249 : void
250 {
251 $query = 'SELECT * FROM tst_times WHERE ' . $this->db->in('active_fi', $this->active_ids, false, 'integer') . ' ORDER BY active_fi';
252 $result = $this->db->query($query);
253 $this->xmlStartTag('tst_times', null);
254 while ($row = $this->db->fetchAssoc($result)) {
255 $attrs = [
256 'times_id' => $row['times_id'],
257 'active_fi' => $row['active_fi'],
258 'started' => $row['started'],
259 'finished' => $row['finished'],
260 'pass' => $row['pass'],
261 'tstamp' => $row['tstamp']
262 ];
263 $this->xmlElement('row', $attrs);
264 }
265 $this->xmlEndTag('tst_times');
266 }

References ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by getXML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getXML()

ilTestResultsToXML::getXML ( )

Definition at line 268 of file class.ilTestResultsToXML.php.

268 : void
269 {
270 $this->active_ids = [];
271 $this->xmlHeader();
272 $attrs = ['version' => '4.1.0'];
273 $this->xmlStartTag('results', $attrs);
274 $this->exportActiveIDs();
275
278 }
279
280 $this->exportPassResult();
281 $this->exportResultCache();
282 $this->exportTestSequence();
283 $this->exportTestSolutions();
284 $this->exportTestResults();
285 $this->exportTestTimes();
286 $this->xmlEndTag('results');
287 }
xmlHeader()
Writes xml header.

References exportActiveIDs(), exportPassResult(), exportRandomTestQuestions(), exportResultCache(), exportTestResults(), exportTestSequence(), exportTestSolutions(), exportTestTimes(), isIncludeRandomTestQuestionsEnabled(), ilXmlWriter\xmlEndTag(), ilXmlWriter\xmlHeader(), and ilXmlWriter\xmlStartTag().

Referenced by xmlDumpFile(), and xmlDumpMem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isIncludeRandomTestQuestionsEnabled()

ilTestResultsToXML::isIncludeRandomTestQuestionsEnabled ( )

Definition at line 40 of file class.ilTestResultsToXML.php.

40 : bool
41 {
43 }

References $include_random_test_questions_enabled.

Referenced by getXML().

+ Here is the caller graph for this function:

◆ setIncludeRandomTestQuestionsEnabled()

ilTestResultsToXML::setIncludeRandomTestQuestionsEnabled ( bool  $include_random_test_questions_enabled)

Definition at line 45 of file class.ilTestResultsToXML.php.

45 : void
46 {
47 $this->include_random_test_questions_enabled = $include_random_test_questions_enabled;
48 }

References $include_random_test_questions_enabled.

◆ xmlDumpFile()

ilTestResultsToXML::xmlDumpFile ( string  $file,
bool  $format = true 
)

Dumps xml document from memory into a file.

Reimplemented from ilXmlWriter.

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

295 : void
296 {
297 $this->getXML();
298 parent::xmlDumpFile($file, $format);
299 }

References getXML().

+ Here is the call graph for this function:

◆ xmlDumpMem()

ilTestResultsToXML::xmlDumpMem ( bool  $format = true)

Returns xml document from memory.

Reimplemented from ilXmlWriter.

Definition at line 289 of file class.ilTestResultsToXML.php.

289 : string
290 {
291 $this->getXML();
292 return parent::xmlDumpMem($format);
293 }

References getXML().

+ Here is the call graph for this function:

Field Documentation

◆ $active_ids

array ilTestResultsToXML::$active_ids = []
private

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

◆ $include_random_test_questions_enabled

bool ilTestResultsToXML::$include_random_test_questions_enabled = false
protected

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