ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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(ilDBConstants::FETCHMODE_OBJECT))
50  {
51  return true;
52  }
53  return false;
54  }
55 
62  public static function deleteRuns($a_container_id, $a_user_id)
63  {
64  global $ilDB;
65 
66  $query = 'DELETE FROM loc_tst_run '.
67  'WHERE container_id = ' . $ilDB->quote($a_container_id,'integer').' '.
68  'AND user_id = '.$ilDB->quote($a_user_id,'integer').' ';
69  $ilDB->manipulate($query);
70 
71  }
72 
73  public static function deleteRun($a_container_id, $a_user_id, $a_test_id)
74  {
75  global $ilDB;
76 
77  $query = 'DELETE FROM loc_tst_run '.
78  'WHERE container_id = ' . $ilDB->quote($a_container_id,'integer').' '.
79  'AND user_id = '.$ilDB->quote($a_user_id,'integer').' '.
80  'AND test_id = '.$ilDB->quote($a_test_id,'integer').' ';
81  $ilDB->manipulate($query);
82  }
83 
84  public static function lookupObjectives($a_container_id, $a_user_id, $a_test_id)
85  {
86  global $ilDB;
87 
88  $query = 'SELECT objective_id FROM loc_tst_run '.
89  'WHERE container_id = '.$ilDB->quote($a_container_id,'integer').' '.
90  'AND user_id = '.$ilDB->quote($a_user_id,'integer').' '.
91  'AND test_id = '.$ilDB->quote($a_test_id,'integer');
92  $GLOBALS['ilLog']->write(__METHOD__.': '.$query);
93  $res = $ilDB->query($query);
94  $objectives = array();
95  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
96  {
97  $objectives[] = $row->objective_id;
98  }
99  return $objectives;
100  }
101 
106  public static function getRun($a_container_id, $a_user_id, $a_test_id)
107  {
108  global $ilDB;
109 
110  $query = 'SELECT objective_id FROM loc_tst_run '.
111  'WHERE container_id = ' . $ilDB->quote($a_container_id,'integer').' '.
112  'AND user_id = '.$ilDB->quote($a_user_id,'integer').' '.
113  'AND test_id = '.$ilDB->quote($a_test_id,'integer').' ';
114  $res = $ilDB->query($query);
115 
116  $run = array();
117  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
118  {
119  $run[] = new ilLOTestRun($a_container_id, $a_user_id, $a_test_id, $row->objective_id);
120  }
121  return $run;
122  }
123 
124  public function getContainerId()
125  {
126  return $this->container_id;
127  }
128 
129  public function getUserId()
130  {
131  return $this->user_id;
132  }
133 
134  public function getTestId()
135  {
136  return $this->test_id;
137  }
138 
139  public function getObjectiveId()
140  {
141  return $this->objective_id;
142  }
143 
144  public function getMaxPoints()
145  {
146  return $this->max_points;
147  }
148 
149  public function setMaxPoints($a_points)
150  {
151  $this->max_points = $a_points;
152  }
153 
154  public function getQuestions()
155  {
156  return (array) $this->questions;
157  }
158 
159  public function clearQuestions()
160  {
161  $this->questions = array();
162  }
163 
164  public function addQuestion($a_id)
165  {
166  $this->questions[$a_id] = 0;
167  }
168 
169  public function questionExists($a_question_id)
170  {
171  return array_key_exists($a_question_id,(array) $this->questions);
172  }
173 
174  public function setQuestionResult($a_qst_id, $a_points)
175  {
176  $GLOBALS['ilLog']->write(__METHOD__.': '.$a_qst_id.' '.$a_points);
177 
178 
179  if($this->questions[$a_qst_id] < $a_points)
180  {
181  $this->questions[$a_qst_id] = $a_points;
182  }
183  $GLOBALS['ilLog']->write(__METHOD__.': '.print_r($this->questions,true));
184  }
185 
189  public function getResult()
190  {
191  $sum_points = 0;
192  foreach($this->questions as $qid => $points)
193  {
194  $sum_points += $points;
195  }
196 
197  $percentage =
198  ($this->getMaxPoints() > 0) ?
199  ($sum_points / $this->getMaxPoints() * 100) :
200  100;
201 
202  return array(
203  'max' => $this->getMaxPoints(),
204  'reached' => $sum_points,
205  'percentage' => $percentage
206  );
207  }
208 
209 
214  public function delete()
215  {
216  global $ilDB;
217 
218  $query = 'DELETE FROM loc_tst_run '.
219  'WHERE container_id = ' . $ilDB->quote($this->getContainerId(),'integer').' '.
220  'AND user_id = '.$ilDB->quote($this->getUserId(),'integer').' '.
221  'AND test_id = '.$ilDB->quote($this->getTestId(),'integer').' '.
222  'AND objective_id = '.$ilDB->quote($this->getObjectiveId(),'integer');
223  $ilDB->manipulate($query);
224  }
225 
226  public function create()
227  {
228  global $ilDB;
229 
230  $query = 'INSERT INTO loc_tst_run '.
231  '(container_id, user_id, test_id, objective_id,max_points,questions) '.
232  'VALUES( '.
233  $ilDB->quote($this->getContainerId(),'integer').', '.
234  $ilDB->quote($this->getUserId(),'integer').', '.
235  $ilDB->quote($this->getTestId(),'integer').', '.
236  $ilDB->quote($this->getObjectiveId(),'integer').', '.
237  $ilDB->quote($this->getMaxPoints(),'integer').', '.
238  $ilDB->quote(serialize($this->getQuestions()),'text').' '.
239  ')';
240  $ilDB->manipulate($query);
241  }
242 
243  public function update()
244  {
245  global $ilDB;
246 
247  $query = 'UPDATE loc_tst_run SET '.
248  'max_points = '.$ilDB->quote($this->getMaxPoints(),'integer').', '.
249  'questions = '.$ilDB->quote(serialize($this->getQuestions()),'text').' '.
250  'WHERE container_id = '.$ilDB->quote($this->container_id,'integer').' '.
251  'AND user_id = '.$ilDB->quote($this->getUserId(),'integer').' '.
252  'AND test_id = '.$ilDB->quote($this->getTestId(),'integer').' '.
253  'AND objective_id = '.$ilDB->quote($this->getObjectiveId(),'integer').' ';
254  $ilDB->manipulate($query);
255  }
256 
261  public function read()
262  {
263  global $ilDB;
264 
265  $query = 'SELECT * FROM loc_tst_run '.
266  'WHERE container_id = ' . $ilDB->quote($this->getContainerId(),'integer').' '.
267  'AND user_id = '.$ilDB->quote($this->getUserId(),'integer').' '.
268  'AND test_id = '.$ilDB->quote($this->getTestId(),'integer').' '.
269  'AND objective_id = '.$ilDB->quote($this->getObjectiveId(),'integer');
270  $res = $ilDB->query($query);
271  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
272  {
273  $this->max_points = $row->max_points;
274  if($row->questions)
275  {
276  $this->questions = unserialize($row->questions);
277  }
278  }
279 
280  }
281 }
282 ?>
__construct($a_crs_id, $a_user_id, $a_test_id, $a_objective_id)
setMaxPoints($a_points)
static lookupRunExistsForObjective($a_test_id, $a_objective_id, $a_user_id)
type $ilDB
getResult()
Get result for objective run.
questionExists($a_question_id)
setQuestionResult($a_qst_id, $a_points)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
read()
type $ilDB
static getRun($a_container_id, $a_user_id, $a_test_id)
static deleteRuns($a_container_id, $a_user_id)
Delete runs type $ilDB.
static lookupObjectives($a_container_id, $a_user_id, $a_test_id)
Create styles array
The data for the language used.
static deleteRun($a_container_id, $a_user_id, $a_test_id)
global $ilDB
Stores current objective, questions and max points.