19 declare(strict_types=0);
40 public function __construct(
int $a_course_obj_id,
int $a_user_id)
44 $this->course_obj_id = $a_course_obj_id;
45 $this->user_id = $a_user_id;
47 $this->db = $DIC->database();
50 public static function updateResultLimit(
int $a_objective_id,
int $a_test_type,
int $a_limit): void
54 $db = $DIC->database();
55 $query =
'UPDATE loc_user_results ' .
70 $ilDB = $DIC->database();
71 $query =
'SELECT * FROM loc_user_results ' .
72 'WHERE user_id = ' .
$ilDB->quote($a_user_id,
'integer') .
' ' .
73 'AND course_id = ' .
$ilDB->quote($a_course_obj_id,
'integer') .
' ' .
74 'AND objective_id = ' .
$ilDB->quote($a_objective_id,
'integer') .
' ' .
75 'AND type = ' .
$ilDB->quote($a_tst_type,
'integer');
78 'status' => self::STATUS_FAILED,
86 $ur[
'status'] = $row->status;
87 $ur[
'result_perc'] = $row->result_perc;
88 $ur[
'limit_perc'] = $row->limit_perc;
89 $ur[
'tries'] = $row->tries;
90 $ur[
'is_final'] = $row->is_final;
91 $ur[
'has_result'] =
true;
100 $db = $DIC->database();
101 $query =
'UPDATE loc_user_results ' .
102 'SET is_final = ' . $db->
quote(0,
'integer') .
' ' .
103 'WHERE objective_id = ' . $db->
quote($a_objective_id,
'integer');
109 return in_array($a_type, array(self::TYPE_INITIAL, self::TYPE_QUALIFIED));
114 return in_array($a_status, array(self::STATUS_COMPLETED, self::STATUS_FAILED));
121 $ilDB = $DIC->database();
126 $ilDB->manipulate(
"DELETE FROM loc_user_results" .
127 " WHERE user_id = " .
$ilDB->quote($a_user_id,
"integer"));
135 $ilDB = $DIC->database();
139 $ilDB->manipulate(
"DELETE FROM loc_user_results" .
140 " WHERE course_id = " .
$ilDB->quote($a_course_id,
"integer"));
144 public function delete():
void 146 $query =
'DELETE FROM loc_user_results ' .
149 $this->db->manipulate($query);
155 bool $a_remove_initial,
156 bool $a_remove_qualified,
157 array $a_objective_ids
161 $ilDB = $DIC->database();
163 $a_user_ids === []) {
167 $base_sql =
"DELETE FROM loc_user_results" .
168 " WHERE course_id = " .
$ilDB->quote($a_course_id,
"integer") .
169 " AND " .
$ilDB->in(
"user_id", $a_user_ids,
false,
"integer");
171 if ($a_objective_ids !== []) {
172 $base_sql .=
' AND ' .
$ilDB->in(
'objective_id', $a_objective_ids,
false,
"integer");
176 if ($a_remove_initial) {
178 " AND type = " .
$ilDB->quote(self::TYPE_INITIAL,
"integer");
179 $ilDB->manipulate($sql);
182 if ($a_remove_qualified) {
184 " AND type = " .
$ilDB->quote(self::TYPE_QUALIFIED,
"integer");
185 $ilDB->manipulate($sql);
188 if ($a_objective_ids === []) {
189 $ilDB->manipulate($base_sql);
191 $ilDB->manipulate($sql);
199 int $a_result_percentage,
200 int $a_limit_percentage,
204 if (!self::isValidType($a_type) ||
205 !self::isValidStatus($a_status)) {
211 "course_id" => array(
"integer", $this->course_obj_id),
212 "user_id" => array(
"integer", $this->user_id),
213 "objective_id" => array(
"integer", $a_objective_id),
214 "type" => array(
"integer", $a_type)
217 "status" => array(
"integer", $a_status),
218 "result_perc" => array(
"integer", $a_result_percentage),
219 "limit_perc" => array(
"integer", $a_limit_percentage),
220 "tries" => array(
"integer", $a_tries),
221 "is_final" => array(
"integer", $a_is_final),
222 "tstamp" => array(
"integer", time()),
231 $sql =
"SELECT objective_id" .
232 " FROM loc_user_results" .
233 " WHERE course_id = " . $this->db->quote($this->course_obj_id,
"integer") .
234 " AND user_id = " . $this->db->quote($this->user_id,
"integer");
237 $sql .=
" AND type = " . $this->db->quote($a_type,
"integer");
240 $sql .=
" AND status = " . $this->db->quote($a_status,
"integer");
242 if ($a_is_final !==
null) {
243 $sql .=
" AND is_final = " . $this->db->quote($a_is_final,
"integer");
246 $set = $this->db->query($sql);
247 while ($row = $this->db->fetchAssoc($set)) {
248 $res[] = $row[
"objective_id"];
274 if (!$settings->isInitialTestQualifying() || !$settings->worksWithInitialTest()) {
275 return $this->
findObjectiveIds(self::TYPE_QUALIFIED, self::STATUS_COMPLETED);
281 $settings->isInitialTestQualifying() &&
282 $settings->worksWithInitialTest()
284 $completed_candidates = array_unique(
290 $failed_final = $this->
findObjectiveIds(self::TYPE_QUALIFIED, self::STATUS_FAILED);
292 foreach ($completed_candidates as $objective_completed) {
293 if (!in_array($objective_completed, $failed_final)) {
294 $completed[] = $objective_completed;
304 return $this->
findObjectiveIds(self::TYPE_QUALIFIED, self::STATUS_FAILED, $a_is_final);
312 $set = $this->db->query(
"SELECT *" .
313 " FROM loc_user_results" .
314 " WHERE course_id = " . $this->db->quote($this->course_obj_id,
"integer") .
315 " AND user_id = " . $this->db->quote($this->user_id,
"integer"));
316 while ($row = $this->db->fetchAssoc($set)) {
319 $row[
'type'] == self::TYPE_INITIAL &&
320 !$settings->worksWithInitialTest()
325 $objective_id = (
int) $row[
"objective_id"];
326 $type = (
int) $row[
"type"];
327 unset($row[
"objective_id"]);
329 $res[$objective_id][$type] = $row;
341 $ilDB = $DIC->database();
345 $initial_qualifying = $lo_set->isInitialTestQualifying();
351 $sql =
"SELECT lor.objective_id, lor.user_id, lor.status, lor.is_final" .
352 " FROM loc_user_results lor" .
353 " JOIN crs_objectives cobj ON (cobj.objective_id = lor.objective_id)" .
354 " WHERE " .
$ilDB->in(
"lor.objective_id", $a_objective_ids,
false,
"integer");
355 if (!$initial_qualifying) {
356 $sql .=
" AND lor.type = " .
$ilDB->quote(self::TYPE_QUALIFIED,
"integer");
358 $sql .=
" AND lor.user_id = " .
$ilDB->quote($a_user_id,
"integer") .
359 " AND cobj.active = " .
$ilDB->quote(1,
"integer") .
360 " ORDER BY lor.type";
361 $set =
$ilDB->query($sql);
362 while ($row =
$ilDB->fetchAssoc($set)) {
363 switch ($row[
"status"]) {
364 case self::STATUS_FAILED:
365 if ($row[
"is_final"]) {
373 case self::STATUS_COMPLETED:
382 $res[(
int) $row[
"objective_id"]] = $status;
392 array $a_objective_ids,
397 $ilDB = $DIC->database();
401 $initial_qualifying = $lo_set->isInitialTestQualifying();
405 $res = $tmp_completed = array();
407 $sql =
"SELECT lor.objective_id, lor.user_id, lor.status, lor.type, lor.is_final" .
408 " FROM loc_user_results lor" .
409 " JOIN crs_objectives cobj ON (cobj.objective_id = lor.objective_id)" .
410 " WHERE " .
$ilDB->in(
"lor.objective_id", $a_objective_ids,
false,
"integer") .
411 " AND cobj.active = " .
$ilDB->quote(1,
"integer");
412 if (!$initial_qualifying) {
413 $sql .=
" AND lor.type = " .
$ilDB->quote(self::TYPE_QUALIFIED,
"integer");
416 $sql .=
" AND lor.user_id = " .
$ilDB->quote($a_user_id,
"integer");
418 $sql .=
" ORDER BY lor.type DESC";
419 $set =
$ilDB->query($sql);
421 $has_final_result = array();
422 while ($row =
$ilDB->fetchAssoc($set)) {
423 if ($row[
'type'] == self::TYPE_QUALIFIED) {
424 $has_final_result[$row[
'objective_id']] = $row[
'user_id'];
427 $user_id = (
int) $row[
"user_id"];
428 $status = (
int) $row[
"status"];
432 $row[
"type"] == self::TYPE_INITIAL &&
433 in_array($row[
'user_id'], (array) ($has_final_result[(
int) $row[
'objective_id']] ?? []))
442 case self::STATUS_COMPLETED:
446 case self::STATUS_FAILED:
447 if ($row[
"is_final"]) {
455 $all_nr = count($a_objective_ids);
456 foreach ($tmp_completed as $user_id => $counter) {
458 if ($counter == $all_nr) {
470 public static function hasResults(
int $a_container_id,
int $a_user_id): bool
474 $ilDB = $DIC->database();
475 $query =
'SELECT objective_id FROM loc_user_results ' .
476 'WHERE course_id = ' .
$ilDB->quote($a_container_id,
'integer') .
' ' .
477 'AND user_id = ' .
$ilDB->quote($a_user_id,
'integer');
493 $ilDB = $DIC->database();
495 $sql =
"SELECT lor.objective_id, lor.user_id, lor.status, lor.is_final, lor.tstamp, lor.course_id, cobj.title" .
496 " FROM loc_user_results lor" .
497 " JOIN crs_objectives cobj ON (cobj.objective_id = lor.objective_id)" .
498 " WHERE lor.user_id = " .
$ilDB->quote($a_user_id,
"integer") .
499 " AND lor.type = " .
$ilDB->quote(self::TYPE_QUALIFIED,
"integer") .
500 " AND lor.tstamp >= " .
$ilDB->quote($a_from_ts,
"integer") .
501 " AND lor.tstamp <= " .
$ilDB->quote($a_to_ts,
"integer") .
502 " AND lor.status = " .
$ilDB->quote(self::STATUS_COMPLETED,
"integer");
504 $set =
$ilDB->query($sql);
505 while ($row =
$ilDB->fetchAssoc($set)) {
506 $res[(
int) $row[
"objective_id"]] = $row;
const LP_STATUS_COMPLETED_NUM
getFailedObjectiveIds(bool $a_is_final=true)
static getSummarizedObjectiveStatusForLP(int $a_obj_id, array $a_objective_ids, int $a_user_id=0)
static hasResults(int $a_container_id, int $a_user_id)
static updateResultLimit(int $a_objective_id, int $a_test_type, int $a_limit)
getCompletedObjectiveIdsByType(int $a_type)
const LP_STATUS_IN_PROGRESS_NUM
static lookupResult(int $a_course_obj_id, int $a_user_id, int $a_objective_id, int $a_tst_type)
static isValidStatus(int $a_status)
static getCompletionsOfUser(int $a_user_id, int $a_from_ts, int $a_to_ts)
Get completed learning objectives for user and time frame.
quote($value, string $type)
static getObjectiveStatusForLP(int $a_user_id, int $a_obj_id, array $a_objective_ids)
getSuggestedObjectiveIds()
Get all objectives where the user failed the initial test.
getCompletedObjectiveIds()
Get all objectives where the user completed the qualified test.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static deleteResultsFromLP(int $a_course_id, array $a_user_ids, bool $a_remove_initial, bool $a_remove_qualified, array $a_objective_ids)
static resetFinalByObjective(int $a_objective_id)
static isValidType(int $a_type)
saveObjectiveResult(int $a_objective_id, int $a_type, int $a_status, int $a_result_percentage, int $a_limit_percentage, int $a_tries, bool $a_is_final)
static getInstanceByObjId(int $a_obj_id)
findObjectiveIds(int $a_type=0, int $a_status=0, ?bool $a_is_final=null)
static deleteResultsForUser(int $a_user_id)
manipulate(string $query)
Run a (write) Query on the database.
getCourseResultsForUserPresentation()
__construct(int $a_course_obj_id, int $a_user_id)
const LP_STATUS_FAILED_NUM
static deleteResultsForCourse(int $a_course_id)