ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCourseLMHistory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
27{
28 private int $course_id = 0;
29 private int $user_id = 0;
30
31 protected ilDBInterface $db;
32
33 public function __construct(int $crs_id, int $user_id)
34 {
35 global $DIC;
36
37 $this->db = $DIC->database();
38 $this->course_id = $crs_id;
39 $this->user_id = $user_id;
40 }
41
42 public function getUserId(): int
43 {
44 return $this->user_id;
45 }
46
47 public function getCourseRefId(): int
48 {
49 return $this->course_id;
50 }
51
52 public static function _updateLastAccess(int $a_user_id, int $a_lm_ref_id, int $a_page_id): bool
53 {
54 global $DIC;
55
56 $tree = $DIC['tree'];
57 $ilDB = $DIC['ilDB'];
58
59 if (!$crs_ref_id = $tree->checkForParentType($a_lm_ref_id, 'crs')) {
60 return true;
61 }
62
63 $ilDB->replace(
64 "crs_lm_history",
65 [
66 "crs_ref_id" => ["integer", $crs_ref_id],
67 "lm_ref_id" => ["integer", $a_lm_ref_id],
68 "usr_id" => ["integer", $a_user_id]
69 ],
70 [
71 "lm_page_id" => ["integer", $a_page_id],
72 "last_access" => ["integer", time()]
73 ]
74 );
75
76 return true;
77 }
78
79 public function getLastLM(): int
80 {
81 $query = "SELECT * FROM crs_lm_history " .
82 "WHERE usr_id = " . $this->db->quote($this->getUserId(), 'integer') . " " .
83 "AND crs_ref_id = " . $this->db->quote($this->getCourseRefId(), 'integer') . " " .
84 "ORDER BY last_access ";
85
86 $res = $this->db->query($query);
87 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
88 return (int) $row->lm_ref_id;
89 }
90 return 0;
91 }
92
93 public function getLMHistory(): array
94 {
95 $query = "SELECT * FROM crs_lm_history " .
96 "WHERE usr_id = " . $this->db->quote($this->getUserId(), 'integer') . " " .
97 "AND crs_ref_id = " . $this->db->quote($this->getCourseRefId(), 'integer') . "";
98
99 $res = $this->db->query($query);
100 $lm = [];
101 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
102 $lm[$row->lm_ref_id]['lm_ref_id'] = (int) $row->lm_ref_id;
103 $lm[$row->lm_ref_id]['lm_page_id'] = (int) $row->lm_page_id;
104 $lm[$row->lm_ref_id]['last_access'] = (int) $row->last_access;
105 }
106 return $lm;
107 }
108
109 public static function _deleteUser(int $a_usr_id): void
110 {
111 global $DIC;
112
113 $ilDB = $DIC->database();
114 $query = "DELETE FROM crs_lm_history WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
115 $res = $ilDB->manipulate($query);
116 }
117}
class ilCourseLMHistory
static _deleteUser(int $a_usr_id)
static _updateLastAccess(int $a_user_id, int $a_lm_ref_id, int $a_page_id)
__construct(int $crs_id, int $user_id)
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26