ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilLOTestRun.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
12 protected $container_id = 0;
13 protected $user_id = 0;
14 protected $test_id = 0;
15 protected $objective_id = 0;
16
17 protected $max_points = 0;
18 protected $questions = array();
19
23 private $logger = null;
24
25
26 public function __construct($a_crs_id, $a_user_id, $a_test_id, $a_objective_id)
27 {
28 global $DIC;
29
30 $this->logger = $DIC->logger()->crs();
31
32 $this->container_id = $a_crs_id;
33 $this->user_id = $a_user_id;
34 $this->test_id = $a_test_id;
35 $this->objective_id = $a_objective_id;
36
37 $this->read();
38 }
39
48 public static function lookupRunExistsForObjective($a_test_id, $a_objective_id, $a_user_id)
49 {
50 global $DIC;
51
52 $ilDB = $DIC['ilDB'];
53
54 $query = 'SELECT * FROM loc_tst_run ' .
55 'WHERE test_id = ' . $ilDB->quote($a_test_id, 'integer') . ' ' .
56 'AND objective_id = ' . $ilDB->quote($a_objective_id, 'integer') . ' ' .
57 'AND user_id = ' . $ilDB->quote($a_user_id, 'integer');
58 $res = $ilDB->query($query);
59
60 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
61 return true;
62 }
63 return false;
64 }
65
72 public static function deleteRuns($a_container_id, $a_user_id)
73 {
74 global $DIC;
75
76 $ilDB = $DIC['ilDB'];
77
78 $query = 'DELETE FROM loc_tst_run ' .
79 'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
80 'AND user_id = ' . $ilDB->quote($a_user_id, 'integer') . ' ';
81 $ilDB->manipulate($query);
82 }
83
84 public static function deleteRun($a_container_id, $a_user_id, $a_test_id)
85 {
86 global $DIC;
87
88 $ilDB = $DIC['ilDB'];
89
90 $query = 'DELETE FROM loc_tst_run ' .
91 'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
92 'AND user_id = ' . $ilDB->quote($a_user_id, 'integer') . ' ' .
93 'AND test_id = ' . $ilDB->quote($a_test_id, 'integer') . ' ';
94 $ilDB->manipulate($query);
95 }
96
97 public static function lookupObjectives($a_container_id, $a_user_id, $a_test_id)
98 {
99 global $DIC;
100
101 $ilDB = $DIC['ilDB'];
102
103 $query = 'SELECT objective_id FROM loc_tst_run ' .
104 'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
105 'AND user_id = ' . $ilDB->quote($a_user_id, 'integer') . ' ' .
106 'AND test_id = ' . $ilDB->quote($a_test_id, 'integer');
107 $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': ' . $query);
108 $res = $ilDB->query($query);
109 $objectives = array();
110 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
111 $objectives[] = $row->objective_id;
112 }
113 return $objectives;
114 }
115
120 public static function getRun($a_container_id, $a_user_id, $a_test_id)
121 {
122 global $DIC;
123
124 $ilDB = $DIC['ilDB'];
125
126 $query = 'SELECT objective_id FROM loc_tst_run ' .
127 'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
128 'AND user_id = ' . $ilDB->quote($a_user_id, 'integer') . ' ' .
129 'AND test_id = ' . $ilDB->quote($a_test_id, 'integer') . ' ';
130 $res = $ilDB->query($query);
131
132 $run = array();
133 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
134 $run[] = new ilLOTestRun($a_container_id, $a_user_id, $a_test_id, $row->objective_id);
135 }
136 return $run;
137 }
138
139 public function getContainerId()
140 {
141 return $this->container_id;
142 }
143
144 public function getUserId()
145 {
146 return $this->user_id;
147 }
148
149 public function getTestId()
150 {
151 return $this->test_id;
152 }
153
154 public function getObjectiveId()
155 {
156 return $this->objective_id;
157 }
158
159 public function getMaxPoints()
160 {
161 return $this->max_points;
162 }
163
164 public function setMaxPoints($a_points)
165 {
166 $this->max_points = $a_points;
167 }
168
169 public function getQuestions()
170 {
171 return (array) $this->questions;
172 }
173
174 public function clearQuestions()
175 {
176 $this->questions = array();
177 }
178
179 public function addQuestion($a_id)
180 {
181 $this->questions[$a_id] = 0;
182 }
183
184 public function questionExists($a_question_id)
185 {
186 return array_key_exists($a_question_id, (array) $this->questions);
187 }
188
193 public function setQuestionResult($a_qst_id, $a_points)
194 {
195 $this->logger->debug($a_qst_id . ' ' . $a_points);
196 $this->questions[$a_qst_id] = $a_points;
197 $this->logger->dump($this->questions, ilLogLevel::DEBUG);
198 }
199
203 public function getResult()
204 {
205 $sum_points = 0;
206 foreach ($this->questions as $qid => $points) {
207 $sum_points += $points;
208 }
209
210 $percentage =
211 ($this->getMaxPoints() > 0) ?
212 ($sum_points / $this->getMaxPoints() * 100) :
213 100;
214
215 return array(
216 'max' => $this->getMaxPoints(),
217 'reached' => $sum_points,
218 'percentage' => $percentage
219 );
220 }
221
222
227 public function delete()
228 {
229 global $DIC;
230
231 $ilDB = $DIC['ilDB'];
232
233 $query = 'DELETE FROM loc_tst_run ' .
234 'WHERE container_id = ' . $ilDB->quote($this->getContainerId(), 'integer') . ' ' .
235 'AND user_id = ' . $ilDB->quote($this->getUserId(), 'integer') . ' ' .
236 'AND test_id = ' . $ilDB->quote($this->getTestId(), 'integer') . ' ' .
237 'AND objective_id = ' . $ilDB->quote($this->getObjectiveId(), 'integer');
238 $ilDB->manipulate($query);
239 }
240
241 public function create()
242 {
243 global $DIC;
244
245 $ilDB = $DIC['ilDB'];
246
247 $query = 'INSERT INTO loc_tst_run ' .
248 '(container_id, user_id, test_id, objective_id,max_points,questions) ' .
249 'VALUES( ' .
250 $ilDB->quote($this->getContainerId(), 'integer') . ', ' .
251 $ilDB->quote($this->getUserId(), 'integer') . ', ' .
252 $ilDB->quote($this->getTestId(), 'integer') . ', ' .
253 $ilDB->quote($this->getObjectiveId(), 'integer') . ', ' .
254 $ilDB->quote($this->getMaxPoints(), 'integer') . ', ' .
255 $ilDB->quote(serialize($this->getQuestions()), 'text') . ' ' .
256 ')';
257 $ilDB->manipulate($query);
258 }
259
260 public function update()
261 {
262 global $DIC;
263
264 $ilDB = $DIC['ilDB'];
265
266 $query = 'UPDATE loc_tst_run SET ' .
267 'max_points = ' . $ilDB->quote($this->getMaxPoints(), 'integer') . ', ' .
268 'questions = ' . $ilDB->quote(serialize($this->getQuestions()), 'text') . ' ' .
269 'WHERE container_id = ' . $ilDB->quote($this->container_id, 'integer') . ' ' .
270 'AND user_id = ' . $ilDB->quote($this->getUserId(), 'integer') . ' ' .
271 'AND test_id = ' . $ilDB->quote($this->getTestId(), 'integer') . ' ' .
272 'AND objective_id = ' . $ilDB->quote($this->getObjectiveId(), 'integer') . ' ';
273 $ilDB->manipulate($query);
274 }
275
280 public function read()
281 {
282 global $DIC;
283
284 $ilDB = $DIC['ilDB'];
285
286 $query = 'SELECT * FROM loc_tst_run ' .
287 'WHERE container_id = ' . $ilDB->quote($this->getContainerId(), 'integer') . ' ' .
288 'AND user_id = ' . $ilDB->quote($this->getUserId(), 'integer') . ' ' .
289 'AND test_id = ' . $ilDB->quote($this->getTestId(), 'integer') . ' ' .
290 'AND objective_id = ' . $ilDB->quote($this->getObjectiveId(), 'integer');
291 $res = $ilDB->query($query);
292 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
293 $this->max_points = $row->max_points;
294 if ($row->questions) {
295 $this->questions = unserialize($row->questions);
296 }
297 }
298 }
299}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
Stores current objective, questions and max points.
setQuestionResult($a_qst_id, $a_points)
__construct($a_crs_id, $a_user_id, $a_test_id, $a_objective_id)
getResult()
Get result for objective run.
questionExists($a_question_id)
static lookupObjectives($a_container_id, $a_user_id, $a_test_id)
static lookupRunExistsForObjective($a_test_id, $a_objective_id, $a_user_id)
@global type $ilDB
static deleteRuns($a_container_id, $a_user_id)
Delete runs @global type $ilDB.
setMaxPoints($a_points)
read()
@global type $ilDB
static deleteRun($a_container_id, $a_user_id, $a_test_id)
static getRun($a_container_id, $a_user_id, $a_test_id)
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$DIC
Definition: xapitoken.php:46