ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilTestResultsToXML.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 include_once './Services/Xml/classes/class.ilXmlWriter.php';
12 
14 {
15  private $test_id = 0;
16  private $anonymized = false;
17  private $active_ids;
18 
20 
21  function __construct($test_id, $anonymized = false)
22  {
23  parent::__construct();
24  $this->test_id = $test_id;
25  $this->anonymized = $anonymized;
26  }
27 
32  {
34  }
35 
40  {
41  $this->includeRandomTestQuestionsEnabled = $includeRandomTestQuestionsEnabled;
42  }
43 
44  protected function exportActiveIDs()
45  {
46  global $ilDB, $ilSetting;
47 
48  include_once "./Modules/Test/classes/class.ilObjTestAccess.php";
49  $assessmentSetting = new ilSetting("assessment");
50  $user_criteria = $assessmentSetting->get("user_criteria");
51  if (strlen($user_criteria) == 0) $user_criteria = 'usr_id';
52 
53  if ($this->anonymized)
54  {
55  $result = $ilDB->queryF("SELECT * FROM tst_active WHERE test_fi = %s",
56  array('integer'),
57  array($this->test_id)
58  );
59  }
60  else
61  {
62  $result = $ilDB->queryF("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",
63  array('integer'),
64  array($this->test_id)
65  );
66  }
67  $this->xmlStartTag("tst_active", NULL);
68  while ($row = $ilDB->fetchAssoc($result))
69  {
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  {
86  $attrs['user_criteria'] = $user_criteria;
87  $attrs[$user_criteria] = $row[$user_criteria];
88  }
89  array_push($this->active_ids, $row['active_id']);
90  $this->xmlElement("row", $attrs);
91  }
92  $this->xmlEndTag("tst_active");
93  }
94 
95  protected function exportPassResult()
96  {
97  global $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  {
104  $attrs = array(
105  'active_fi' => $row['active_fi'],
106  'pass' => $row['pass'],
107  'points' => $row['points'],
108  'maxpoints' => $row['maxpoints'],
109  'questioncount' => $row['questioncount'],
110  'answeredquestions' => $row['answeredquestions'],
111  'workingtime' => $row['workingtime'],
112  'tstamp' => $row['tstamp']
113  );
114  $this->xmlElement("row", $attrs);
115  }
116  $this->xmlEndTag("tst_pass_result");
117  }
118 
119  protected function exportResultCache()
120  {
121  global $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  {
128  $attrs = array(
129  'active_fi' => $row['active_fi'],
130  'pass' => $row['pass'],
131  'max_points' => $row['max_points'],
132  'reached_points' => $row['reached_points'],
133  'mark_short' => $row['mark_short'],
134  'mark_official' => $row['mark_official'],
135  'passed' => $row['passed'],
136  'failed' => $row['failed'],
137  'tstamp' => $row['tstamp']
138  );
139  $this->xmlElement("row", $attrs);
140  }
141  $this->xmlEndTag("tst_result_cache");
142  }
143 
144  protected function exportTestSequence()
145  {
146  global $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  {
153  $attrs = array(
154  'active_fi' => $row['active_fi'],
155  'pass' => $row['pass'],
156  'sequence' => $row['sequence'],
157  'postponed' => $row['postponed'],
158  'hidden' => $row['hidden'],
159  'tstamp' => $row['tstamp']
160  );
161  $this->xmlElement("row", $attrs);
162  }
163  $this->xmlEndTag("tst_sequence");
164  }
165 
166  protected function exportTestSolutions()
167  {
168  global $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  {
175  $attrs = array(
176  'solution_id' => $row['solution_id'],
177  'active_fi' => $row['active_fi'],
178  'question_fi' => $row['question_fi'],
179  'points' => $row['points'],
180  'pass' => $row['pass'],
181  'value1' => $row['value1'],
182  'value2' => $row['value2'],
183  'tstamp' => $row['tstamp']
184  );
185  $this->xmlElement("row", $attrs);
186  }
187  $this->xmlEndTag("tst_solutions");
188  }
189 
190  protected function exportRandomTestQuestions()
191  {
192  global $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  {
203  $attrs = array();
204 
205  foreach($row as $field => $value)
206  {
207  $attrs[$field] = $value;
208  }
209 
210  $this->xmlElement('row', $attrs);
211  }
212  $this->xmlEndTag('tst_test_rnd_qst');
213  }
214 
215 
216  protected function exportTestResults()
217  {
218  global $ilDB;
219 
220  $query = "SELECT * FROM tst_test_result WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY active_fi";
221  $result = $ilDB->query($query);
222  $this->xmlStartTag("tst_test_result", NULL);
223  while ($row = $ilDB->fetchAssoc($result))
224  {
225  $attrs = array(
226  'test_result_id' => $row['test_result_id'],
227  'active_fi' => $row['active_fi'],
228  'question_fi' => $row['question_fi'],
229  'points' => $row['points'],
230  'pass' => $row['pass'],
231  'manual' => $row['manual'],
232  'tstamp' => $row['tstamp']
233  );
234  $this->xmlElement("row", $attrs);
235  }
236  $this->xmlEndTag("tst_test_result");
237  }
238 
239  protected function exportTestTimes()
240  {
241  global $ilDB;
242 
243  $query = "SELECT * FROM tst_times WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY active_fi";
244  $result = $ilDB->query($query);
245  $this->xmlStartTag("tst_times", NULL);
246  while ($row = $ilDB->fetchAssoc($result))
247  {
248  $attrs = array(
249  'times_id' => $row['times_id'],
250  'active_fi' => $row['active_fi'],
251  'started' => $row['started'],
252  'finished' => $row['finished'],
253  'pass' => $row['pass'],
254  'tstamp' => $row['tstamp']
255  );
256  $this->xmlElement("row", $attrs);
257  }
258  $this->xmlEndTag("tst_times");
259  }
260 
261  function getXML()
262  {
263  $this->active_ids = array();
264  $this->xmlHeader();
265  $attrs = array("version" => "4.1.0");
266  $this->xmlStartTag("results", $attrs);
267  $this->exportActiveIDs();
268 
270  {
271  $this->exportRandomTestQuestions();
272  }
273 
274  $this->exportPassResult();
275  $this->exportResultCache();
276  $this->exportTestSequence();
277  $this->exportTestSolutions();
278  $this->exportTestResults();
279  $this->exportTestTimes();
280  $this->xmlEndTag("results");
281  }
282 
283  function xmlDumpMem($format = TRUE)
284  {
285  $this->getXML();
286  return parent::xmlDumpMem($format);
287  }
288 
289  function xmlDumpFile($file, $format = TRUE)
290  {
291  $this->getXML();
292  return parent::xmlDumpFile($file, $format);
293  }
294 
295 
296 }
297 ?>
ILIAS Setting Class.
setIncludeRandomTestQuestionsEnabled($includeRandomTestQuestionsEnabled)
__construct($test_id, $anonymized=false)
static _getParticipantData($active_id)
Retrieves a participant name from active id.
$result
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
XML writer class.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
Test results to XML class.
xmlEndTag($tag)
Writes an endtag.
xmlHeader()
Writes xml header public.
Create styles array
The data for the language used.
global $ilSetting
Definition: privfeed.php:17
global $ilDB
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
xmlDumpFile($file, $format=TRUE)