ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
20
21 public function __construct($a_crs_id, $a_user_id, $a_test_id, $a_objective_id)
22 {
23 $this->container_id = $a_crs_id;
24 $this->user_id = $a_user_id;
25 $this->test_id = $a_test_id;
26 $this->objective_id = $a_objective_id;
27
28 $this->read();
29 }
30
39 public static function lookupRunExistsForObjective($a_test_id, $a_objective_id, $a_user_id)
40 {
41 global $ilDB;
42
43 $query = 'SELECT * FROM loc_tst_run '.
44 'WHERE test_id = '.$ilDB->quote($a_test_id,'integer').' '.
45 'AND objective_id = '.$ilDB->quote($a_objective_id,'integer').' '.
46 'AND user_id = '.$ilDB->quote($a_user_id,'integer');
47 $res = $ilDB->query($query);
48
49 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
50 {
51 return true;
52 }
53 return false;
54 }
55
56 public static function deleteRun($a_container_id, $a_user_id, $a_test_id)
57 {
58 global $ilDB;
59
60 $query = 'DELETE FROM loc_tst_run '.
61 'WHERE container_id = ' . $ilDB->quote($a_container_id,'integer').' '.
62 'AND user_id = '.$ilDB->quote($a_user_id,'integer').' '.
63 'AND test_id = '.$ilDB->quote($a_test_id,'integer').' ';
64 $ilDB->manipulate($query);
65 }
66
67 public static function lookupObjectives($a_container_id, $a_user_id, $a_test_id)
68 {
69 global $ilDB;
70
71 $query = 'SELECT objective_id FROM loc_tst_run '.
72 'WHERE container_id = '.$ilDB->quote($a_container_id,'integer').' '.
73 'AND user_id = '.$ilDB->quote($a_user_id,'integer').' '.
74 'AND test_id = '.$ilDB->quote($a_test_id,'integer');
75 $GLOBALS['ilLog']->write(__METHOD__.': '.$query);
76 $res = $ilDB->query($query);
77 $objectives = array();
78 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
79 {
80 $objectives[] = $row->objective_id;
81 }
82 return $objectives;
83 }
84
89 public static function getRun($a_container_id, $a_user_id, $a_test_id)
90 {
91 global $ilDB;
92
93 $query = 'SELECT objective_id FROM loc_tst_run '.
94 'WHERE container_id = ' . $ilDB->quote($a_container_id,'integer').' '.
95 'AND user_id = '.$ilDB->quote($a_user_id,'integer').' '.
96 'AND test_id = '.$ilDB->quote($a_test_id,'integer').' ';
97 $res = $ilDB->query($query);
98
99 $run = array();
100 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
101 {
102 $run[] = new ilLOTestRun($a_container_id, $a_user_id, $a_test_id, $row->objective_id);
103 }
104 return $run;
105 }
106
107 public function getContainerId()
108 {
109 return $this->container_id;
110 }
111
112 public function getUserId()
113 {
114 return $this->user_id;
115 }
116
117 public function getTestId()
118 {
119 return $this->test_id;
120 }
121
122 public function getObjectiveId()
123 {
124 return $this->objective_id;
125 }
126
127 public function getMaxPoints()
128 {
129 return $this->max_points;
130 }
131
132 public function setMaxPoints($a_points)
133 {
134 $this->max_points = $a_points;
135 }
136
137 public function getQuestions()
138 {
139 return (array) $this->questions;
140 }
141
142 public function clearQuestions()
143 {
144 $this->questions = array();
145 }
146
147 public function addQuestion($a_id)
148 {
149 $this->questions[$a_id] = 0;
150 }
151
152 public function questionExists($a_question_id)
153 {
154 return array_key_exists($a_question_id,(array) $this->questions);
155 }
156
157 public function setQuestionResult($a_qst_id, $a_points)
158 {
159 $GLOBALS['ilLog']->write(__METHOD__.': '.$a_qst_id.' '.$a_points);
160
161
162 if($this->questions[$a_qst_id] < $a_points)
163 {
164 $this->questions[$a_qst_id] = $a_points;
165 }
166 $GLOBALS['ilLog']->write(__METHOD__.': '.print_r($this->questions,true));
167 }
168
172 public function getResult()
173 {
174 $sum_points = 0;
175 foreach($this->questions as $qid => $points)
176 {
177 $sum_points += (int) $points;
178 }
179
180 $percentage =
181 ($this->getMaxPoints() > 0) ?
182 ($sum_points / $this->getMaxPoints() * 100) :
183 100;
184
185 return array(
186 'max' => $this->getMaxPoints(),
187 'reached' => $sum_points,
188 'percentage' => $percentage
189 );
190 }
191
192
197 public function delete()
198 {
199 global $ilDB;
200
201 $query = 'DELETE FROM loc_tst_run '.
202 'WHERE container_id = ' . $ilDB->quote($this->getContainerId(),'integer').' '.
203 'AND user_id = '.$ilDB->quote($this->getUserId(),'integer').' '.
204 'AND test_id = '.$ilDB->quote($this->getTestId(),'integer').' '.
205 'AND objective_id = '.$ilDB->quote($this->getObjectiveId(),'integer');
206 $ilDB->manipulate($query);
207 }
208
209 public function create()
210 {
211 global $ilDB;
212
213 $query = 'INSERT INTO loc_tst_run '.
214 '(container_id, user_id, test_id, objective_id,max_points,questions) '.
215 'VALUES( '.
216 $ilDB->quote($this->getContainerId(),'integer').', '.
217 $ilDB->quote($this->getUserId(),'integer').', '.
218 $ilDB->quote($this->getTestId(),'integer').', '.
219 $ilDB->quote($this->getObjectiveId(),'integer').', '.
220 $ilDB->quote($this->getMaxPoints(),'integer').', '.
221 $ilDB->quote(serialize($this->getQuestions()),'text').' '.
222 ')';
223 $ilDB->manipulate($query);
224 }
225
226 public function update()
227 {
228 global $ilDB;
229
230 $query = 'UPDATE loc_tst_run SET '.
231 'max_points = '.$ilDB->quote($this->getMaxPoints(),'integer').', '.
232 'questions = '.$ilDB->quote(serialize($this->getQuestions()),'text').' '.
233 'WHERE container_id = '.$ilDB->quote($this->container_id,'integer').' '.
234 'AND user_id = '.$ilDB->quote($this->getUserId(),'integer').' '.
235 'AND test_id = '.$ilDB->quote($this->getTestId(),'integer').' '.
236 'AND objective_id = '.$ilDB->quote($this->getObjectiveId(),'integer').' ';
237 $ilDB->manipulate($query);
238 }
239
244 public function read()
245 {
246 global $ilDB;
247
248 $query = 'SELECT * FROM loc_tst_run '.
249 'WHERE container_id = ' . $ilDB->quote($this->getContainerId(),'integer').' '.
250 'AND user_id = '.$ilDB->quote($this->getUserId(),'integer').' '.
251 'AND test_id = '.$ilDB->quote($this->getTestId(),'integer').' '.
252 'AND objective_id = '.$ilDB->quote($this->getObjectiveId(),'integer');
253 $res = $ilDB->query($query);
254 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
255 {
256 $this->max_points = $row->max_points;
257 if($row->questions)
258 {
259 $this->questions = unserialize($row->questions);
260 }
261 }
262
263 }
264}
265?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
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
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)
$GLOBALS['ct_recipient']
global $ilDB