ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestResultsToXML.php
Go to the documentation of this file.
1 <?php
2 
20 {
21  private int $test_id = 0;
22  private bool $anonymized = false;
23  private $active_ids;
24 
25  protected bool $includeRandomTestQuestionsEnabled = false;
26 
27  public function __construct($test_id, $anonymized = false)
28  {
30  $this->test_id = $test_id;
31  $this->anonymized = $anonymized;
32  }
33 
34  public function isIncludeRandomTestQuestionsEnabled(): bool
35  {
37  }
38 
39  public function setIncludeRandomTestQuestionsEnabled(bool $includeRandomTestQuestionsEnabled): void
40  {
41  $this->includeRandomTestQuestionsEnabled = $includeRandomTestQuestionsEnabled;
42  }
43 
44  protected function exportActiveIDs(): void
45  {
46  global $DIC;
47  $ilDB = $DIC['ilDB'];
48  $ilSetting = $DIC['ilSetting'];
49  $assessmentSetting = new ilSetting("assessment");
50  $user_criteria = $assessmentSetting->get("user_criteria");
51  if (!$user_criteria || $user_criteria === '') {
52  $user_criteria = 'usr_id';
53  }
54 
55  if ($this->anonymized) {
56  $result = $ilDB->queryF(
57  "SELECT * FROM tst_active WHERE test_fi = %s",
58  array('integer'),
59  array($this->test_id)
60  );
61  } else {
62  $result = $ilDB->queryF(
63  "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",
64  array('integer'),
65  array($this->test_id)
66  );
67  }
68  $this->xmlStartTag("tst_active", null);
69  while ($row = $ilDB->fetchAssoc($result)) {
70  $attrs = array(
71  'active_id' => $row['active_id'],
72  'user_fi' => $row['user_fi'] ?? '',
73  'anonymous_id' => $row['anonymous_id'] ?? '',
74  'test_fi' => $row['test_fi'],
75  'lastindex' => $row['lastindex'] ?? '',
76  'tries' => $row['tries'] ?? '',
77  'last_started_pass' => $row['last_started_pass'] ?? '',
78  'last_finished_pass' => $row['last_finished_pass'] ?? '',
79  'submitted' => $row['submitted'] ?? '',
80  'submittimestamp' => $row['submittimestamp'] ?? '',
81  'tstamp' => $row['tstamp'] ?? ''
82  );
83  $attrs['fullname'] = ilObjTestAccess::_getParticipantData($row['active_id']);
84  if (!$this->anonymized) {
85  $attrs['user_criteria'] = $user_criteria;
86  $attrs[$user_criteria] = $row[$user_criteria];
87  }
88  array_push($this->active_ids, $row['active_id']);
89  $this->xmlElement("row", $attrs);
90  }
91  $this->xmlEndTag("tst_active");
92  }
93 
94  protected function exportPassResult(): void
95  {
96  global $DIC;
97  $ilDB = $DIC['ilDB'];
98 
99  $query = "SELECT * FROM tst_pass_result WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY active_fi, pass";
100  $result = $ilDB->query($query);
101  $this->xmlStartTag("tst_pass_result", null);
102  while ($row = $ilDB->fetchAssoc($result)) {
103  $attrs = array(
104  'active_fi' => $row['active_fi'],
105  'pass' => $row['pass'] ?? '',
106  'points' => $row['points'] ?? '',
107  'maxpoints' => $row['maxpoints'] ?? '',
108  'questioncount' => $row['questioncount'] ?? '',
109  'answeredquestions' => $row['answeredquestions'] ?? '',
110  'workingtime' => $row['workingtime'] ?? '',
111  'tstamp' => $row['tstamp'] ?? ''
112  );
113  $this->xmlElement("row", $attrs);
114  }
115  $this->xmlEndTag("tst_pass_result");
116  }
117 
118  protected function exportResultCache(): void
119  {
120  global $DIC;
121  $ilDB = $DIC['ilDB'];
122 
123  $query = "SELECT * FROM tst_result_cache WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY active_fi";
124  $result = $ilDB->query($query);
125  $this->xmlStartTag("tst_result_cache", null);
126  while ($row = $ilDB->fetchAssoc($result)) {
127  $attrs = array(
128  'active_fi' => $row['active_fi'],
129  'pass' => $row['pass'],
130  'max_points' => $row['max_points'],
131  'reached_points' => $row['reached_points'],
132  'mark_short' => $row['mark_short'],
133  'mark_official' => $row['mark_official'],
134  'passed' => $row['passed'],
135  'failed' => $row['failed'],
136  'tstamp' => $row['tstamp']
137  );
138  $this->xmlElement("row", $attrs);
139  }
140  $this->xmlEndTag("tst_result_cache");
141  }
142 
143  protected function exportTestSequence(): void
144  {
145  global $DIC;
146  $ilDB = $DIC['ilDB'];
147 
148  $query = "SELECT * FROM tst_sequence WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY active_fi, pass";
149  $result = $ilDB->query($query);
150  $this->xmlStartTag("tst_sequence", null);
151  while ($row = $ilDB->fetchAssoc($result)) {
152  $attrs = array(
153  'active_fi' => $row['active_fi'],
154  'pass' => $row['pass'] ?? '',
155  'sequence' => $row['sequence'] ?? '',
156  'postponed' => $row['postponed'] ?? '',
157  'hidden' => $row['hidden'] ?? '',
158  'tstamp' => $row['tstamp'] ?? ''
159  );
160  $this->xmlElement("row", $attrs);
161  }
162  $this->xmlEndTag("tst_sequence");
163  }
164 
165  protected function exportTestSolutions(): void
166  {
167  global $DIC;
168  $ilDB = $DIC['ilDB'];
169 
170  $query = "SELECT * FROM tst_solutions WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY solution_id";
171  $result = $ilDB->query($query);
172  $this->xmlStartTag("tst_solutions", null);
173  while ($row = $ilDB->fetchAssoc($result)) {
174  $attrs = array(
175  'solution_id' => $row['solution_id'],
176  'active_fi' => $row['active_fi'],
177  'question_fi' => $row['question_fi'],
178  'points' => $row['points'] ?? '',
179  'pass' => $row['pass'] ?? '',
180  'value1' => $row['value1'] ?? '',
181  'value2' => $row['value2'] ?? '',
182  'tstamp' => $row['tstamp'] ?? ''
183  );
184  $this->xmlElement("row", $attrs);
185  }
186  $this->xmlEndTag("tst_solutions");
187  }
188 
189  protected function exportRandomTestQuestions(): void
190  {
191  global $DIC;
192  $ilDB = $DIC['ilDB'];
193 
194  $result = $ilDB->query("
195  SELECT * FROM tst_test_rnd_qst
196  WHERE {$ilDB->in('active_fi', $this->active_ids, false, 'integer')}
197  ORDER BY test_random_question_id
198  ");
199 
200  $this->xmlStartTag('tst_test_rnd_qst', null);
201  while ($row = $ilDB->fetchAssoc($result)) {
202  $attrs = array();
203 
204  foreach ($row as $field => $value) {
205  $attrs[$field] = $value;
206  }
207 
208  $this->xmlElement('row', $attrs);
209  }
210  $this->xmlEndTag('tst_test_rnd_qst');
211  }
212 
213 
214  protected function exportTestResults(): void
215  {
216  global $DIC;
217  $ilDB = $DIC['ilDB'];
218 
219  $query = "SELECT * FROM tst_test_result WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY active_fi";
220  $result = $ilDB->query($query);
221  $this->xmlStartTag("tst_test_result", null);
222  while ($row = $ilDB->fetchAssoc($result)) {
223  $attrs = array(
224  'test_result_id' => $row['test_result_id'],
225  'active_fi' => $row['active_fi'],
226  'question_fi' => $row['question_fi'],
227  'points' => $row['points'] ?? '',
228  'pass' => $row['pass'] ?? '',
229  'manual' => $row['manual'] ?? '',
230  'tstamp' => $row['tstamp'] ?? ''
231  );
232  $this->xmlElement("row", $attrs);
233  }
234  $this->xmlEndTag("tst_test_result");
235  }
236 
237  protected function exportTestTimes(): void
238  {
239  global $DIC;
240  $ilDB = $DIC['ilDB'];
241 
242  $query = "SELECT * FROM tst_times WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY active_fi";
243  $result = $ilDB->query($query);
244  $this->xmlStartTag("tst_times", null);
245  while ($row = $ilDB->fetchAssoc($result)) {
246  $attrs = array(
247  'times_id' => $row['times_id'],
248  'active_fi' => $row['active_fi'],
249  'started' => $row['started'],
250  'finished' => $row['finished'],
251  'pass' => $row['pass'],
252  'tstamp' => $row['tstamp']
253  );
254  $this->xmlElement("row", $attrs);
255  }
256  $this->xmlEndTag("tst_times");
257  }
258 
259  public function getXML(): void
260  {
261  $this->active_ids = array();
262  $this->xmlHeader();
263  $attrs = array("version" => "4.1.0");
264  $this->xmlStartTag("results", $attrs);
265  $this->exportActiveIDs();
266 
268  $this->exportRandomTestQuestions();
269  }
270 
271  $this->exportPassResult();
272  $this->exportResultCache();
273  $this->exportTestSequence();
274  $this->exportTestSolutions();
275  $this->exportTestResults();
276  $this->exportTestTimes();
277  $this->xmlEndTag("results");
278  }
279 
280  public function xmlDumpMem(bool $format = true): string
281  {
282  $this->getXML();
283  return parent::xmlDumpMem($format);
284  }
285 
286  public function xmlDumpFile(string $file, bool $format = true): void
287  {
288  $this->getXML();
289  parent::xmlDumpFile($file, $format);
290  }
291 }
__construct($test_id, $anonymized=false)
static _getParticipantData($active_id)
Retrieves a participant name from active id.
xmlDumpFile(string $file, bool $format=true)
setIncludeRandomTestQuestionsEnabled(bool $includeRandomTestQuestionsEnabled)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlDumpMem(bool $format=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlEndTag(string $tag)
Writes an endtag.
global $DIC
Definition: feed.php:28
$format
Definition: metadata.php:235
xmlHeader()
Writes xml header.
$query
global $ilSetting
Definition: privfeed.php:17
__construct(Container $dic, ilPlugin $plugin)
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)