ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilDB;
51 
52  $query = 'SELECT * FROM loc_tst_run ' .
53  'WHERE test_id = ' . $ilDB->quote($a_test_id, 'integer') . ' ' .
54  'AND objective_id = ' . $ilDB->quote($a_objective_id, 'integer') . ' ' .
55  'AND user_id = ' . $ilDB->quote($a_user_id, 'integer');
56  $res = $ilDB->query($query);
57 
58  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
59  return true;
60  }
61  return false;
62  }
63 
70  public static function deleteRuns($a_container_id, $a_user_id)
71  {
72  global $ilDB;
73 
74  $query = 'DELETE FROM loc_tst_run ' .
75  'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
76  'AND user_id = ' . $ilDB->quote($a_user_id, 'integer') . ' ';
77  $ilDB->manipulate($query);
78  }
79 
80  public static function deleteRun($a_container_id, $a_user_id, $a_test_id)
81  {
82  global $ilDB;
83 
84  $query = 'DELETE FROM loc_tst_run ' .
85  'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
86  'AND user_id = ' . $ilDB->quote($a_user_id, 'integer') . ' ' .
87  'AND test_id = ' . $ilDB->quote($a_test_id, 'integer') . ' ';
88  $ilDB->manipulate($query);
89  }
90 
91  public static function lookupObjectives($a_container_id, $a_user_id, $a_test_id)
92  {
93  global $ilDB;
94 
95  $query = 'SELECT objective_id FROM loc_tst_run ' .
96  'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
97  'AND user_id = ' . $ilDB->quote($a_user_id, 'integer') . ' ' .
98  'AND test_id = ' . $ilDB->quote($a_test_id, 'integer');
99  $GLOBALS['ilLog']->write(__METHOD__ . ': ' . $query);
100  $res = $ilDB->query($query);
101  $objectives = array();
102  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
103  $objectives[] = $row->objective_id;
104  }
105  return $objectives;
106  }
107 
112  public static function getRun($a_container_id, $a_user_id, $a_test_id)
113  {
114  global $ilDB;
115 
116  $query = 'SELECT objective_id FROM loc_tst_run ' .
117  'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
118  'AND user_id = ' . $ilDB->quote($a_user_id, 'integer') . ' ' .
119  'AND test_id = ' . $ilDB->quote($a_test_id, 'integer') . ' ';
120  $res = $ilDB->query($query);
121 
122  $run = array();
123  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
124  $run[] = new ilLOTestRun($a_container_id, $a_user_id, $a_test_id, $row->objective_id);
125  }
126  return $run;
127  }
128 
129  public function getContainerId()
130  {
131  return $this->container_id;
132  }
133 
134  public function getUserId()
135  {
136  return $this->user_id;
137  }
138 
139  public function getTestId()
140  {
141  return $this->test_id;
142  }
143 
144  public function getObjectiveId()
145  {
146  return $this->objective_id;
147  }
148 
149  public function getMaxPoints()
150  {
151  return $this->max_points;
152  }
153 
154  public function setMaxPoints($a_points)
155  {
156  $this->max_points = $a_points;
157  }
158 
159  public function getQuestions()
160  {
161  return (array) $this->questions;
162  }
163 
164  public function clearQuestions()
165  {
166  $this->questions = array();
167  }
168 
169  public function addQuestion($a_id)
170  {
171  $this->questions[$a_id] = 0;
172  }
173 
174  public function questionExists($a_question_id)
175  {
176  return array_key_exists($a_question_id, (array) $this->questions);
177  }
178 
183  public function setQuestionResult($a_qst_id, $a_points)
184  {
185  $this->logger->debug($a_qst_id . ' ' . $a_points);
186  $this->questions[$a_qst_id] = $a_points;
187  $this->logger->dump($this->questions, ilLogLevel::DEBUG);
188  }
189 
193  public function getResult()
194  {
195  $sum_points = 0;
196  foreach ($this->questions as $qid => $points) {
197  $sum_points += $points;
198  }
199 
200  $percentage =
201  ($this->getMaxPoints() > 0) ?
202  ($sum_points / $this->getMaxPoints() * 100) :
203  100;
204 
205  return array(
206  'max' => $this->getMaxPoints(),
207  'reached' => $sum_points,
208  'percentage' => $percentage
209  );
210  }
211 
212 
217  public function delete()
218  {
219  global $ilDB;
220 
221  $query = 'DELETE FROM loc_tst_run ' .
222  'WHERE container_id = ' . $ilDB->quote($this->getContainerId(), 'integer') . ' ' .
223  'AND user_id = ' . $ilDB->quote($this->getUserId(), 'integer') . ' ' .
224  'AND test_id = ' . $ilDB->quote($this->getTestId(), 'integer') . ' ' .
225  'AND objective_id = ' . $ilDB->quote($this->getObjectiveId(), 'integer');
226  $ilDB->manipulate($query);
227  }
228 
229  public function create()
230  {
231  global $ilDB;
232 
233  $query = 'INSERT INTO loc_tst_run ' .
234  '(container_id, user_id, test_id, objective_id,max_points,questions) ' .
235  'VALUES( ' .
236  $ilDB->quote($this->getContainerId(), 'integer') . ', ' .
237  $ilDB->quote($this->getUserId(), 'integer') . ', ' .
238  $ilDB->quote($this->getTestId(), 'integer') . ', ' .
239  $ilDB->quote($this->getObjectiveId(), 'integer') . ', ' .
240  $ilDB->quote($this->getMaxPoints(), 'integer') . ', ' .
241  $ilDB->quote(serialize($this->getQuestions()), 'text') . ' ' .
242  ')';
243  $ilDB->manipulate($query);
244  }
245 
246  public function update()
247  {
248  global $ilDB;
249 
250  $query = 'UPDATE loc_tst_run SET ' .
251  'max_points = ' . $ilDB->quote($this->getMaxPoints(), 'integer') . ', ' .
252  'questions = ' . $ilDB->quote(serialize($this->getQuestions()), 'text') . ' ' .
253  'WHERE container_id = ' . $ilDB->quote($this->container_id, 'integer') . ' ' .
254  'AND user_id = ' . $ilDB->quote($this->getUserId(), 'integer') . ' ' .
255  'AND test_id = ' . $ilDB->quote($this->getTestId(), 'integer') . ' ' .
256  'AND objective_id = ' . $ilDB->quote($this->getObjectiveId(), 'integer') . ' ';
257  $ilDB->manipulate($query);
258  }
259 
264  public function read()
265  {
266  global $ilDB;
267 
268  $query = 'SELECT * FROM loc_tst_run ' .
269  'WHERE container_id = ' . $ilDB->quote($this->getContainerId(), '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  $res = $ilDB->query($query);
274  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
275  $this->max_points = $row->max_points;
276  if ($row->questions) {
277  $this->questions = unserialize($row->questions);
278  }
279  }
280  }
281 }
__construct($a_crs_id, $a_user_id, $a_test_id, $a_objective_id)
setMaxPoints($a_points)
global $DIC
Definition: saml.php:7
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)
foreach($_POST as $key=> $value) $res
$query
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.