3 declare(strict_types=0);
38 public function __construct(
int $a_course_obj_id,
int $a_user_id)
42 $this->course_obj_id = $a_course_obj_id;
43 $this->user_id = $a_user_id;
45 $this->db = $DIC->database();
48 public static function updateResultLimit(
int $a_objective_id,
int $a_test_type,
int $a_limit) : void
52 $db = $DIC->database();
53 $query =
'UPDATE loc_user_results ' .
68 $ilDB = $DIC->database();
69 $query =
'SELECT * FROM loc_user_results ' .
70 'WHERE user_id = ' .
$ilDB->quote($a_user_id,
'integer') .
' ' .
71 'AND course_id = ' .
$ilDB->quote($a_course_obj_id,
'integer') .
' ' .
72 'AND objective_id = ' .
$ilDB->quote($a_objective_id,
'integer') .
' ' .
73 'AND type = ' .
$ilDB->quote($a_tst_type,
'integer');
76 'status' => self::STATUS_FAILED,
84 $ur[
'status'] = $row->status;
85 $ur[
'result_perc'] = $row->result_perc;
86 $ur[
'limit_perc'] = $row->limit_perc;
87 $ur[
'tries'] = $row->tries;
88 $ur[
'is_final'] = $row->is_final;
89 $ur[
'has_result'] =
true;
98 $db = $DIC->database();
99 $query =
'UPDATE loc_user_results ' .
100 'SET is_final = ' . $db->
quote(0,
'integer') .
' ' .
101 'WHERE objective_id = ' . $db->
quote($a_objective_id,
'integer');
107 return in_array($a_type, array(self::TYPE_INITIAL, self::TYPE_QUALIFIED));
112 return in_array($a_status, array(self::STATUS_COMPLETED, self::STATUS_FAILED));
119 $ilDB = $DIC->database();
124 $ilDB->manipulate(
"DELETE FROM loc_user_results" .
125 " WHERE user_id = " .
$ilDB->quote($a_user_id,
"integer"));
133 $ilDB = $DIC->database();
137 $ilDB->manipulate(
"DELETE FROM loc_user_results" .
138 " WHERE course_id = " .
$ilDB->quote($a_course_id,
"integer"));
142 public function delete():
void 144 $query =
'DELETE FROM loc_user_results ' .
147 $this->db->manipulate(
$query);
153 bool $a_remove_initial,
154 bool $a_remove_qualified,
155 array $a_objective_ids
159 $ilDB = $DIC->database();
161 $a_user_ids === []) {
165 $base_sql =
"DELETE FROM loc_user_results" .
166 " WHERE course_id = " .
$ilDB->quote($a_course_id,
"integer") .
167 " AND " .
$ilDB->in(
"user_id", $a_user_ids,
false,
"integer");
169 if ($a_objective_ids !== []) {
170 $base_sql .=
' AND ' .
$ilDB->in(
'objective_id', $a_objective_ids,
false,
"integer");
174 if ($a_remove_initial) {
176 " AND type = " .
$ilDB->quote(self::TYPE_INITIAL,
"integer");
177 $ilDB->manipulate($sql);
180 if ($a_remove_qualified) {
182 " AND type = " .
$ilDB->quote(self::TYPE_QUALIFIED,
"integer");
183 $ilDB->manipulate($sql);
186 if ($a_objective_ids === []) {
187 $ilDB->manipulate($base_sql);
189 $ilDB->manipulate($sql);
197 int $a_result_percentage,
198 int $a_limit_percentage,
202 if (!self::isValidType($a_type) ||
203 !self::isValidStatus($a_status)) {
209 "course_id" => array(
"integer", $this->course_obj_id),
210 "user_id" => array(
"integer", $this->user_id),
211 "objective_id" => array(
"integer", $a_objective_id),
212 "type" => array(
"integer", $a_type)
215 "status" => array(
"integer", $a_status),
216 "result_perc" => array(
"integer", $a_result_percentage),
217 "limit_perc" => array(
"integer", $a_limit_percentage),
218 "tries" => array(
"integer", $a_tries),
219 "is_final" => array(
"integer", $a_is_final),
220 "tstamp" => array(
"integer", time()),
226 protected function findObjectiveIds(
int $a_type = 0,
int $a_status = 0, ?
bool $a_is_final = null): array
229 $sql =
"SELECT objective_id" .
230 " FROM loc_user_results" .
231 " WHERE course_id = " . $this->db->quote($this->course_obj_id,
"integer") .
232 " AND user_id = " . $this->db->quote($this->user_id,
"integer");
235 $sql .=
" AND type = " . $this->db->quote($a_type,
"integer");
238 $sql .=
" AND status = " . $this->db->quote($a_status,
"integer");
240 if ($a_is_final !== null) {
241 $sql .=
" AND is_final = " . $this->db->quote($a_is_final,
"integer");
244 $set = $this->db->query($sql);
245 while ($row = $this->db->fetchAssoc($set)) {
246 $res[] = $row[
"objective_id"];
273 return $this->
findObjectiveIds(self::TYPE_QUALIFIED, self::STATUS_COMPLETED);
282 $completed_candidates = array_unique(
288 $failed_final = $this->
findObjectiveIds(self::TYPE_QUALIFIED, self::STATUS_FAILED);
290 foreach ($completed_candidates as $objective_completed) {
291 if (!in_array($objective_completed, $failed_final)) {
292 $completed[] = $objective_completed;
302 return $this->
findObjectiveIds(self::TYPE_QUALIFIED, self::STATUS_FAILED, $a_is_final);
310 $set = $this->db->query(
"SELECT *" .
311 " FROM loc_user_results" .
312 " WHERE course_id = " . $this->db->quote($this->course_obj_id,
"integer") .
313 " AND user_id = " . $this->db->quote($this->user_id,
"integer"));
314 while ($row = $this->db->fetchAssoc($set)) {
317 $row[
'type'] == self::TYPE_INITIAL &&
323 $objective_id = (
int) $row[
"objective_id"];
325 unset($row[
"objective_id"]);
339 $ilDB = $DIC->database();
343 $initial_qualifying = $lo_set->isInitialTestQualifying();
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,
false,
"integer");
353 if (!$initial_qualifying) {
354 $sql .=
" AND lor.type = " .
$ilDB->quote(self::TYPE_QUALIFIED,
"integer");
356 $sql .=
" AND lor.user_id = " .
$ilDB->quote($a_user_id,
"integer") .
357 " AND cobj.active = " .
$ilDB->quote(1,
"integer") .
358 " ORDER BY lor.type";
359 $set =
$ilDB->query($sql);
360 while ($row =
$ilDB->fetchAssoc($set)) {
361 switch ($row[
"status"]) {
362 case self::STATUS_FAILED:
363 if ($row[
"is_final"]) {
371 case self::STATUS_COMPLETED:
380 $res[(
int) $row[
"objective_id"]] = $status;
390 array $a_objective_ids,
395 $ilDB = $DIC->database();
399 $initial_qualifying = $lo_set->isInitialTestQualifying();
403 $res = $tmp_completed = array();
405 $sql =
"SELECT lor.objective_id, lor.user_id, lor.status, lor.type, lor.is_final" .
406 " FROM loc_user_results lor" .
407 " JOIN crs_objectives cobj ON (cobj.objective_id = lor.objective_id)" .
408 " WHERE " .
$ilDB->in(
"lor.objective_id", $a_objective_ids,
false,
"integer") .
409 " AND cobj.active = " .
$ilDB->quote(1,
"integer");
410 if (!$initial_qualifying) {
411 $sql .=
" AND lor.type = " .
$ilDB->quote(self::TYPE_QUALIFIED,
"integer");
414 $sql .=
" AND lor.user_id = " .
$ilDB->quote($a_user_id,
"integer");
416 $sql .=
" ORDER BY lor.type DESC";
417 $set =
$ilDB->query($sql);
419 $has_final_result = array();
420 while ($row =
$ilDB->fetchAssoc($set)) {
421 if ($row[
'type'] == self::TYPE_QUALIFIED) {
422 $has_final_result[$row[
'objective_id']] = $row[
'user_id'];
425 $user_id = (
int) $row[
"user_id"];
426 $status = (
int) $row[
"status"];
430 $row[
"type"] == self::TYPE_INITIAL &&
431 in_array($row[
'user_id'], (array) ($has_final_result[(
int) $row[
'objective_id']] ?? []))
440 case self::STATUS_COMPLETED:
444 case self::STATUS_FAILED:
445 if ($row[
"is_final"]) {
453 $all_nr = count($a_objective_ids);
454 foreach ($tmp_completed as $user_id => $counter) {
456 if ($counter == $all_nr) {
462 return isset(
$res[$a_user_id]) ? (
int)
$res[$a_user_id] : null;
468 public static function hasResults(
int $a_container_id,
int $a_user_id): bool
472 $ilDB = $DIC->database();
473 $query =
'SELECT objective_id FROM loc_user_results ' .
474 'WHERE course_id = ' .
$ilDB->quote($a_container_id,
'integer') .
' ' .
475 'AND user_id = ' .
$ilDB->quote($a_user_id,
'integer');
491 $ilDB = $DIC->database();
493 $sql =
"SELECT lor.objective_id, lor.user_id, lor.status, lor.is_final, lor.tstamp, lor.course_id, cobj.title" .
494 " FROM loc_user_results lor" .
495 " JOIN crs_objectives cobj ON (cobj.objective_id = lor.objective_id)" .
496 " WHERE lor.user_id = " .
$ilDB->quote($a_user_id,
"integer") .
497 " AND lor.type = " .
$ilDB->quote(self::TYPE_QUALIFIED,
"integer") .
498 " AND lor.tstamp >= " .
$ilDB->quote($a_from_ts,
"integer") .
499 " AND lor.tstamp <= " .
$ilDB->quote($a_to_ts,
"integer") .
500 " AND lor.status = " .
$ilDB->quote(self::STATUS_COMPLETED,
"integer");
502 $set =
$ilDB->query($sql);
503 while ($row =
$ilDB->fetchAssoc($set)) {
504 $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.
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)