ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestResultsToXML.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2011 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 
19  function __construct($test_id, $anonymized = false)
20  {
22  $this->test_id = $test_id;
23  $this->anonymized = $anonymized;
24  }
25 
26  protected function exportActiveIDs()
27  {
28  global $ilDB, $ilSetting;
29 
30  include_once "./Modules/Test/classes/class.ilObjTestAccess.php";
31  $assessmentSetting = new ilSetting("assessment");
32  $user_criteria = $assessmentSetting->get("user_criteria");
33  if (strlen($user_criteria) == 0) $user_criteria = 'usr_id';
34 
35  if ($this->anonymized)
36  {
37  $result = $ilDB->queryF("SELECT * FROM tst_active WHERE test_fi = %s",
38  array('integer'),
39  array($this->test_id)
40  );
41  }
42  else
43  {
44  $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",
45  array('integer'),
46  array($this->test_id)
47  );
48  }
49  $this->xmlStartTag("tst_active", NULL);
50  while ($row = $ilDB->fetchAssoc($result))
51  {
52  $attrs = array(
53  'active_id' => $row['active_id'],
54  'user_fi' => $row['user_fi'],
55  'anonymous_id' => $row['anonymous_id'],
56  'test_fi' => $row['test_fi'],
57  'lastindex' => $row['lastindex'],
58  'tries' => $row['tries'],
59  'submitted' => $row['submitted'],
60  'submittimestamp' => $row['submittimestamp'],
61  'tstamp' => $row['tstamp']
62  );
63  $attrs['fullname'] = ilObjTestAccess::_getParticipantData($row['active_id']);
64  if (!$this->anonymized)
65  {
66  $attrs['user_criteria'] = $user_criteria;
67  $attrs[$user_criteria] = $row[$user_criteria];
68  }
69  array_push($this->active_ids, $row['active_id']);
70  $this->xmlElement("row", $attrs);
71  }
72  $this->xmlEndTag("tst_active");
73  }
74 
75  protected function exportPassResult()
76  {
77  global $ilDB;
78 
79  $query = "SELECT * FROM tst_pass_result WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY active_fi, pass";
80  $result = $ilDB->query($query);
81  $this->xmlStartTag("tst_pass_result", NULL);
82  while ($row = $ilDB->fetchAssoc($result))
83  {
84  $attrs = array(
85  'active_fi' => $row['active_fi'],
86  'pass' => $row['pass'],
87  'points' => $row['points'],
88  'maxpoints' => $row['maxpoints'],
89  'questioncount' => $row['questioncount'],
90  'answeredquestions' => $row['answeredquestions'],
91  'workingtime' => $row['workingtime'],
92  'tstamp' => $row['tstamp']
93  );
94  $this->xmlElement("row", $attrs);
95  }
96  $this->xmlEndTag("tst_pass_result");
97  }
98 
99  protected function exportResultCache()
100  {
101  global $ilDB;
102 
103  $query = "SELECT * FROM tst_result_cache WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY active_fi";
104  $result = $ilDB->query($query);
105  $this->xmlStartTag("tst_result_cache", NULL);
106  while ($row = $ilDB->fetchAssoc($result))
107  {
108  $attrs = array(
109  'active_fi' => $row['active_fi'],
110  'pass' => $row['pass'],
111  'max_points' => $row['max_points'],
112  'reached_points' => $row['reached_points'],
113  'mark_short' => $row['mark_short'],
114  'mark_official' => $row['mark_official'],
115  'passed' => $row['passed'],
116  'failed' => $row['failed'],
117  'tstamp' => $row['tstamp']
118  );
119  $this->xmlElement("row", $attrs);
120  }
121  $this->xmlEndTag("tst_result_cache");
122  }
123 
124  protected function exportTestSequence()
125  {
126  global $ilDB;
127 
128  $query = "SELECT * FROM tst_sequence WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY active_fi, pass";
129  $result = $ilDB->query($query);
130  $this->xmlStartTag("tst_sequence", NULL);
131  while ($row = $ilDB->fetchAssoc($result))
132  {
133  $attrs = array(
134  'active_fi' => $row['active_fi'],
135  'pass' => $row['pass'],
136  'sequence' => $row['sequence'],
137  'postponed' => $row['postponed'],
138  'hidden' => $row['hidden'],
139  'tstamp' => $row['tstamp']
140  );
141  $this->xmlElement("row", $attrs);
142  }
143  $this->xmlEndTag("tst_sequence");
144  }
145 
146  protected function exportTestSolutions()
147  {
148  global $ilDB;
149 
150  $query = "SELECT * FROM tst_solutions WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY solution_id";
151  $result = $ilDB->query($query);
152  $this->xmlStartTag("tst_solutions", NULL);
153  while ($row = $ilDB->fetchAssoc($result))
154  {
155  $attrs = array(
156  'solution_id' => $row['solution_id'],
157  'active_fi' => $row['active_fi'],
158  'question_fi' => $row['question_fi'],
159  'points' => $row['points'],
160  'pass' => $row['pass'],
161  'value1' => $row['value1'],
162  'value2' => $row['value2'],
163  'tstamp' => $row['tstamp']
164  );
165  $this->xmlElement("row", $attrs);
166  }
167  $this->xmlEndTag("tst_solutions");
168  }
169 
170  protected function exportTestQuestions()
171  {
172  global $ilDB;
173 
174  $result = $ilDB->queryF("SELECT * FROM tst_test_question WHERE test_fi = %s",
175  array('integer'),
176  array($this->test_id)
177  );
178  $this->xmlStartTag("tst_test_question", NULL);
179  while ($row = $ilDB->fetchAssoc($result))
180  {
181  $attrs = array(
182  'test_question_id' => $row['test_question_id'],
183  'test_fi' => $row['test_fi'],
184  'question_fi' => $row['question_fi'],
185  'sequence' => $row['sequence'],
186  'tstamp' => $row['tstamp']
187  );
188  $this->xmlElement("row", $attrs);
189  }
190  $this->xmlEndTag("tst_test_question");
191  }
192 
193 
194  protected function exportTestResults()
195  {
196  global $ilDB;
197 
198  $query = "SELECT * FROM tst_test_result WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY active_fi";
199  $result = $ilDB->query($query);
200  $this->xmlStartTag("tst_test_result", NULL);
201  while ($row = $ilDB->fetchAssoc($result))
202  {
203  $attrs = array(
204  'test_result_id' => $row['test_result_id'],
205  'active_fi' => $row['active_fi'],
206  'question_fi' => $row['question_fi'],
207  'points' => $row['points'],
208  'pass' => $row['pass'],
209  'manual' => $row['manual'],
210  'tstamp' => $row['tstamp']
211  );
212  $this->xmlElement("row", $attrs);
213  }
214  $this->xmlEndTag("tst_test_result");
215  }
216 
217  protected function exportTestTimes()
218  {
219  global $ilDB;
220 
221  $query = "SELECT * FROM tst_times WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY active_fi";
222  $result = $ilDB->query($query);
223  $this->xmlStartTag("tst_times", NULL);
224  while ($row = $ilDB->fetchAssoc($result))
225  {
226  $attrs = array(
227  'times_id' => $row['times_id'],
228  'active_fi' => $row['active_fi'],
229  'started' => $row['started'],
230  'finished' => $row['finished'],
231  'pass' => $row['pass'],
232  'tstamp' => $row['tstamp']
233  );
234  $this->xmlElement("row", $attrs);
235  }
236  $this->xmlEndTag("tst_times");
237  }
238 
239  function getXML()
240  {
241  $this->active_ids = array();
242  $this->xmlHeader();
243  $attrs = array("version" => "4.1.0");
244  $this->xmlStartTag("results", $attrs);
245  $this->exportActiveIDs();
246  $this->exportTestQuestions();
247  $this->exportPassResult();
248  $this->exportResultCache();
249  $this->exportTestSequence();
250  $this->exportTestSolutions();
251  $this->exportTestResults();
252  $this->exportTestTimes();
253  $this->xmlEndTag("results");
254  }
255 
256  function xmlDumpMem($format = TRUE)
257  {
258  $this->getXML();
259  return parent::xmlDumpMem($format);
260  }
261 
262  function xmlDumpFile($file, $format = TRUE)
263  {
264  $this->getXML();
265  return parent::xmlDumpFile($file, $format);
266  }
267 
268 
269 }
270 ?>