ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
11include_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 public 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) {
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()
95 {
96 global $ilDB;
97
98 $query = "SELECT * FROM tst_pass_result WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY active_fi, pass";
99 $result = $ilDB->query($query);
100 $this->xmlStartTag("tst_pass_result", null);
101 while ($row = $ilDB->fetchAssoc($result)) {
102 $attrs = array(
103 'active_fi' => $row['active_fi'],
104 'pass' => $row['pass'],
105 'points' => $row['points'],
106 'maxpoints' => $row['maxpoints'],
107 'questioncount' => $row['questioncount'],
108 'answeredquestions' => $row['answeredquestions'],
109 'workingtime' => $row['workingtime'],
110 'tstamp' => $row['tstamp']
111 );
112 $this->xmlElement("row", $attrs);
113 }
114 $this->xmlEndTag("tst_pass_result");
115 }
116
117 protected function exportResultCache()
118 {
119 global $ilDB;
120
121 $query = "SELECT * FROM tst_result_cache WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY active_fi";
122 $result = $ilDB->query($query);
123 $this->xmlStartTag("tst_result_cache", null);
124 while ($row = $ilDB->fetchAssoc($result)) {
125 $attrs = array(
126 'active_fi' => $row['active_fi'],
127 'pass' => $row['pass'],
128 'max_points' => $row['max_points'],
129 'reached_points' => $row['reached_points'],
130 'mark_short' => $row['mark_short'],
131 'mark_official' => $row['mark_official'],
132 'passed' => $row['passed'],
133 'failed' => $row['failed'],
134 'tstamp' => $row['tstamp']
135 );
136 $this->xmlElement("row", $attrs);
137 }
138 $this->xmlEndTag("tst_result_cache");
139 }
140
141 protected function exportTestSequence()
142 {
143 global $ilDB;
144
145 $query = "SELECT * FROM tst_sequence WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY active_fi, pass";
146 $result = $ilDB->query($query);
147 $this->xmlStartTag("tst_sequence", null);
148 while ($row = $ilDB->fetchAssoc($result)) {
149 $attrs = array(
150 'active_fi' => $row['active_fi'],
151 'pass' => $row['pass'],
152 'sequence' => $row['sequence'],
153 'postponed' => $row['postponed'],
154 'hidden' => $row['hidden'],
155 'tstamp' => $row['tstamp']
156 );
157 $this->xmlElement("row", $attrs);
158 }
159 $this->xmlEndTag("tst_sequence");
160 }
161
162 protected function exportTestSolutions()
163 {
164 global $ilDB;
165
166 $query = "SELECT * FROM tst_solutions WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY solution_id";
167 $result = $ilDB->query($query);
168 $this->xmlStartTag("tst_solutions", null);
169 while ($row = $ilDB->fetchAssoc($result)) {
170 $attrs = array(
171 'solution_id' => $row['solution_id'],
172 'active_fi' => $row['active_fi'],
173 'question_fi' => $row['question_fi'],
174 'points' => $row['points'],
175 'pass' => $row['pass'],
176 'value1' => $row['value1'],
177 'value2' => $row['value2'],
178 'tstamp' => $row['tstamp']
179 );
180 $this->xmlElement("row", $attrs);
181 }
182 $this->xmlEndTag("tst_solutions");
183 }
184
185 protected function exportRandomTestQuestions()
186 {
187 global $ilDB;
188
189 $result = $ilDB->query("
190 SELECT * FROM tst_test_rnd_qst
191 WHERE {$ilDB->in('active_fi', $this->active_ids, false, 'integer')}
192 ORDER BY test_random_question_id
193 ");
194
195 $this->xmlStartTag('tst_test_rnd_qst', null);
196 while ($row = $ilDB->fetchAssoc($result)) {
197 $attrs = array();
198
199 foreach ($row as $field => $value) {
200 $attrs[$field] = $value;
201 }
202
203 $this->xmlElement('row', $attrs);
204 }
205 $this->xmlEndTag('tst_test_rnd_qst');
206 }
207
208
209 protected function exportTestResults()
210 {
211 global $ilDB;
212
213 $query = "SELECT * FROM tst_test_result WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY active_fi";
214 $result = $ilDB->query($query);
215 $this->xmlStartTag("tst_test_result", null);
216 while ($row = $ilDB->fetchAssoc($result)) {
217 $attrs = array(
218 'test_result_id' => $row['test_result_id'],
219 'active_fi' => $row['active_fi'],
220 'question_fi' => $row['question_fi'],
221 'points' => $row['points'],
222 'pass' => $row['pass'],
223 'manual' => $row['manual'],
224 'tstamp' => $row['tstamp']
225 );
226 $this->xmlElement("row", $attrs);
227 }
228 $this->xmlEndTag("tst_test_result");
229 }
230
231 protected function exportTestTimes()
232 {
233 global $ilDB;
234
235 $query = "SELECT * FROM tst_times WHERE " . $ilDB->in('active_fi', $this->active_ids, false, 'integer') . " ORDER BY active_fi";
236 $result = $ilDB->query($query);
237 $this->xmlStartTag("tst_times", null);
238 while ($row = $ilDB->fetchAssoc($result)) {
239 $attrs = array(
240 'times_id' => $row['times_id'],
241 'active_fi' => $row['active_fi'],
242 'started' => $row['started'],
243 'finished' => $row['finished'],
244 'pass' => $row['pass'],
245 'tstamp' => $row['tstamp']
246 );
247 $this->xmlElement("row", $attrs);
248 }
249 $this->xmlEndTag("tst_times");
250 }
251
252 public function getXML()
253 {
254 $this->active_ids = array();
255 $this->xmlHeader();
256 $attrs = array("version" => "4.1.0");
257 $this->xmlStartTag("results", $attrs);
258 $this->exportActiveIDs();
259
262 }
263
264 $this->exportPassResult();
265 $this->exportResultCache();
266 $this->exportTestSequence();
267 $this->exportTestSolutions();
268 $this->exportTestResults();
269 $this->exportTestTimes();
270 $this->xmlEndTag("results");
271 }
272
273 public function xmlDumpMem($format = true)
274 {
275 $this->getXML();
276 return parent::xmlDumpMem($format);
277 }
278
279 public function xmlDumpFile($file, $format = true)
280 {
281 $this->getXML();
282 return parent::xmlDumpFile($file, $format);
283 }
284}
$result
An exception for terminatinating execution or to throw for unit testing.
static _getParticipantData($active_id)
Retrieves a participant name from active id.
ILIAS Setting Class.
Test results to XML class.
xmlDumpMem($format=true)
Returns xml document from memory.
__construct($test_id, $anonymized=false)
xmlDumpFile($file, $format=true)
Dumps xml document from memory into a file.
setIncludeRandomTestQuestionsEnabled($includeRandomTestQuestionsEnabled)
XML writer class.
xmlEndTag($tag)
Writes an endtag.
xmlHeader()
Writes xml header @access public.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
$format
Definition: metadata.php:141
global $ilSetting
Definition: privfeed.php:17
$query
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
global $ilDB