31 $this->course_obj_id = (int)$a_course_obj_id;
32 $this->user_id = (int)$a_user_id;
38 public static function lookupResult($a_course_obj_id, $a_user_id, $a_objective_id, $a_tst_type)
42 $query =
'SELECT * FROM loc_user_results '.
43 'WHERE user_id = '.$ilDB->quote($a_user_id,
'integer').
' '.
44 'AND course_id = '.$ilDB->quote($a_course_obj_id,
'integer').
' '.
45 'AND objective_id = '.$ilDB->quote($a_objective_id,
'integer').
' '.
46 'AND type = '.$ilDB->quote($a_tst_type,
'integer');
49 'status' => self::STATUS_FAILED,
57 $ur[
'status'] =
$row->status;
58 $ur[
'result_perc'] =
$row->result_perc;
59 $ur[
'limit_perc'] =
$row->limit_perc;
60 $ur[
'tries'] =
$row->tries;
61 $ur[
'is_final'] =
$row->is_final;
68 $query =
'UPDATE loc_user_results '.
69 'SET is_final = '.$GLOBALS[
'ilDB']->quote(0,
'integer').
' '.
70 'WHERE objective_id = '.$GLOBALS[
'ilDB']->quote($a_objective_id,
'integer');
83 return in_array((
int)$a_type, array(self::TYPE_INITIAL, self::TYPE_QUALIFIED));
94 return in_array((
int)$a_status, array(self::STATUS_COMPLETED, self::STATUS_FAILED));
112 $ilDB->manipulate(
"DELETE FROM loc_user_results".
113 " WHERE user_id = ".$ilDB->quote($a_user_id,
"integer"));
128 if(!(
int)$a_course_id)
133 $ilDB->manipulate(
"DELETE FROM loc_user_results".
134 " WHERE course_id = ".$ilDB->quote($a_course_id,
"integer"));
142 public function delete()
146 $query =
'DELETE FROM loc_user_results '.
147 'WHERE course_id = '.$ilDB->quote($this->course_obj_id).
' '.
148 'AND user_id = '.$ilDB->quote($this->user_id);
149 $ilDB->manipulate(
$query);
161 public static function deleteResultsFromLP($a_course_id, array $a_user_ids, $a_remove_initial, $a_remove_qualified)
165 if(!(
int)$a_course_id || !
sizeof($a_user_ids))
170 $sql =
"DELETE FROM loc_user_results".
171 " WHERE course_id = ".$ilDB->quote($a_course_id,
"integer").
172 " AND ".$ilDB->in(
"user_id", $a_user_ids,
"",
"integer");
174 if(!(
bool)$a_remove_initial || !(
bool)$a_remove_qualified)
176 if((
bool)$a_remove_initial)
178 $sql .=
" AND type = ".$ilDB->quote(self::TYPE_INITIAL,
"integer");
182 $sql .=
" AND type = ".$ilDB->quote(self::TYPE_QUALIFIED,
"integer");
186 $ilDB->manipulate($sql);
203 public function saveObjectiveResult($a_objective_id, $a_type, $a_status, $a_result_percentage, $a_limit_percentage, $a_tries, $a_is_final)
207 if(!self::isValidType($a_type) ||
208 !self::isValidStatus($a_status))
212 $ilDB->replace(
"loc_user_results",
214 "course_id" => array(
"integer", $this->course_obj_id),
215 "user_id" => array(
"integer", $this->user_id),
216 "objective_id" => array(
"integer", $a_objective_id),
217 "type" => array(
"integer", $a_type)
220 "status" => array(
"integer", $a_status),
221 "result_perc" => array(
"integer", $a_result_percentage),
222 "limit_perc" => array(
"integer", $a_limit_percentage),
223 "tries" => array(
"integer", $a_tries),
224 "is_final" => array(
"integer", $a_is_final),
225 "tstamp" => array(
"integer", time()),
245 $sql =
"SELECT objective_id".
246 " FROM loc_user_results".
247 " WHERE course_id = ".$ilDB->quote($this->course_obj_id,
"integer").
248 " AND user_id = ".$ilDB->quote($this->user_id,
"integer");
252 $sql .=
" AND type = ".$ilDB->quote($a_type,
"integer");
256 $sql .=
" AND status = ".$ilDB->quote($a_status,
"integer");
258 if($a_is_final !== null)
260 $sql .=
" AND is_final = ".$ilDB->quote($a_is_final,
"integer");
263 $set = $ilDB->query($sql);
264 while(
$row = $ilDB->fetchAssoc($set))
299 return $this->
findObjectiveIds(self::TYPE_QUALIFIED, self::STATUS_COMPLETED);
310 return $this->
findObjectiveIds(self::TYPE_QUALIFIED, self::STATUS_FAILED, $a_is_final);
324 $set = $ilDB->query(
"SELECT *".
325 " FROM loc_user_results".
326 " WHERE course_id = ".$ilDB->quote($this->course_obj_id,
"integer").
327 " AND user_id = ".$ilDB->quote($this->user_id,
"integer"));
328 while(
$row = $ilDB->fetchAssoc($set))
330 $objective_id =
$row[
"objective_id"];
331 $type =
$row[
"type"];
332 unset(
$row[
"objective_id"]);
345 include_once
"Services/Tracking/classes/class.ilLPStatus.php";
349 $sql =
"SELECT lor.objective_id, lor.user_id, lor.status, lor.is_final".
350 " FROM loc_user_results lor".
351 " JOIN crs_objectives cobj ON (cobj.objective_id = lor.objective_id)".
352 " WHERE ".$ilDB->in(
"lor.objective_id", $a_objective_ids,
"",
"integer").
353 " AND lor.type = ".$ilDB->quote(self::TYPE_QUALIFIED,
"integer").
354 " AND lor.user_id = ".$ilDB->quote($a_user_id,
"integer").
355 " AND cobj.active = ".$ilDB->quote(1,
"integer");
356 $set = $ilDB->query($sql);
357 while(
$row = $ilDB->fetchAssoc($set))
359 switch(
$row[
"status"])
361 case self::STATUS_FAILED:
365 case self::STATUS_COMPLETED:
377 $res[
$row[
"objective_id"]] = $status;
388 include_once
"Services/Tracking/classes/class.ilLPStatus.php";
390 $res = $tmp_completed = array();
392 $sql =
"SELECT lor.objective_id, lor.user_id, lor.status, lor.is_final".
393 " FROM loc_user_results lor".
394 " JOIN crs_objectives cobj ON (cobj.objective_id = lor.objective_id)".
395 " WHERE ".$ilDB->in(
"lor.objective_id", $a_objective_ids,
"",
"integer").
396 " AND lor.type = ".$ilDB->quote(self::TYPE_QUALIFIED,
"integer").
397 " AND cobj.active = ".$ilDB->quote(1,
"integer");
400 $sql .=
" AND lor.user_id = ".$ilDB->quote($a_user_id,
"integer");
402 $set = $ilDB->query($sql);
403 while(
$row = $ilDB->fetchAssoc($set))
406 $status = (int)
$row[
"status"];
413 case self::STATUS_COMPLETED:
417 case self::STATUS_FAILED:
418 if((
bool)
$row[
"is_final"])
427 $all_nr =
sizeof($a_objective_ids);
428 foreach($tmp_completed as
$user_id => $counter)
431 if($counter == $all_nr)
440 return $res[$a_user_id];
449 public static function hasResults($a_container_id, $a_user_id)
453 $query =
'SELECT objective_id FROM loc_user_results '.
454 'WHERE course_id = '.$ilDB->quote($a_container_id,
'integer').
' '.
455 'AND user_id = '.$ilDB->quote($a_user_id,
'integer');