21 public function __construct($a_crs_id, $a_user_id, $a_test_id, $a_objective_id)
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;
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');
56 public static function deleteRun($a_container_id, $a_user_id, $a_test_id)
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').
' ';
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');
77 $objectives = array();
80 $objectives[] =
$row->objective_id;
89 public static function getRun($a_container_id, $a_user_id, $a_test_id)
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').
' ';
102 $run[] =
new ilLOTestRun($a_container_id, $a_user_id, $a_test_id,
$row->objective_id);
134 $this->max_points = $a_points;
144 $this->questions = array();
149 $this->questions[$a_id] = 0;
154 return array_key_exists($a_question_id,(array) $this->questions);
159 $GLOBALS[
'ilLog']->write(__METHOD__.
': '.$a_qst_id.
' '.$a_points);
162 if($this->questions[$a_qst_id] < $a_points)
164 $this->questions[$a_qst_id] = $a_points;
166 $GLOBALS[
'ilLog']->write(__METHOD__.
': '.print_r($this->questions,
true));
175 foreach($this->questions as $qid => $points)
177 $sum_points += (int) $points;
187 'reached' => $sum_points,
188 'percentage' => $percentage
197 public function delete()
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);
213 $query =
'INSERT INTO loc_tst_run '.
214 '(container_id, user_id, test_id, objective_id,max_points,questions) '.
217 $ilDB->quote($this->
getUserId(),
'integer').
', '.
218 $ilDB->quote($this->
getTestId(),
'integer').
', '.
221 $ilDB->quote(serialize($this->
getQuestions()),
'text').
' '.
223 $ilDB->manipulate(
$query);
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);
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');
256 $this->max_points =
$row->max_points;
259 $this->questions = unserialize(
$row->questions);