ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLPMarks.php
Go to the documentation of this file.
1<?php
25{
26 protected ?ilDBInterface $db;
28
29 protected int $obj_id;
30 protected int $usr_id;
31 protected ?string $obj_type;
32
33 protected bool $completed = false;
34 protected string $comment = '';
35 protected string $mark = '';
36 protected string $status_changed = '';
37
38 protected $has_entry = false;
39
40 public function __construct(int $a_obj_id, int $a_usr_id)
41 {
42 global $DIC;
43
44 $this->ilObjectDataCache = $DIC['ilObjDataCache'];
45 $this->db = $DIC->database();
46
47 $this->obj_id = $a_obj_id;
48 $this->usr_id = $a_usr_id;
49 $this->obj_type = $this->ilObjectDataCache->lookupType($this->obj_id);
50
51 $this->__read();
52 }
53
54 public static function deleteObject(int $a_obj_id): void
55 {
56 global $DIC;
57
58 $ilDB = $DIC['ilDB'];
59
60 $query = "DELETE FROM ut_lp_marks " .
61 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer');
62 $res = $ilDB->manipulate($query);
63 }
64
65 public function getUserId(): int
66 {
67 return $this->usr_id;
68 }
69
70 public function setMark(string $a_mark): void
71 {
72 $this->mark = $a_mark;
73 }
74
75 public function getMark(): string
76 {
77 return $this->mark;
78 }
79
80 public function setComment(string $a_comment): void
81 {
82 $this->comment = $a_comment;
83 }
84
85 public function getComment(): string
86 {
87 return $this->comment;
88 }
89
90 public function setCompleted(bool $a_status): void
91 {
92 $this->completed = $a_status;
93 }
94
95 public function getCompleted(): bool
96 {
97 return $this->completed;
98 }
99
100 public function getStatusChanged(): string
101 {
103 }
104
105 public function getObjId(): int
106 {
107 return $this->obj_id;
108 }
109
110 public function update(): void
111 {
112 if (!$this->has_entry) {
113 $this->__add();
114 }
115 $query = "UPDATE ut_lp_marks " .
116 "SET mark = " . $this->db->quote($this->getMark(), 'text') . ", " .
117 "u_comment = " . $this->db->quote(
118 $this->getComment(),
119 'text'
120 ) . ", " .
121 "completed = " . $this->db->quote(
122 $this->getCompleted(),
123 'integer'
124 ) . " " .
125 "WHERE obj_id = " . $this->db->quote(
126 $this->getObjId(),
127 'integer'
128 ) . " " .
129 "AND usr_id = " . $this->db->quote($this->getUserId(), 'integer');
130 $res = $this->db->manipulate($query);
131 }
132
133 // Static
134 public static function _hasCompleted(int $a_usr_id, int $a_obj_id): bool
135 {
136 global $DIC;
137
138 $ilDB = $DIC['ilDB'];
139
140 $query = "SELECT * FROM ut_lp_marks " .
141 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
142 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
143
144 $res = $ilDB->query($query);
145 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
146 return (bool) $row->completed;
147 }
148 return false;
149 }
150
151 public static function getCompletionsOfUser(
152 int $user_id,
153 string $from,
154 string $to
155 ): array {
156 global $DIC;
157
158 $ilDB = $DIC['ilDB'];
159
160 $query = "SELECT * FROM ut_lp_marks " .
161 "WHERE usr_id = " . $ilDB->quote($user_id, 'integer') .
162 " AND status = " . $ilDB->quote(
164 'integer'
165 ) .
166 " AND status_changed >= " . $ilDB->quote($from, "timestamp") .
167 " AND status_changed <= " . $ilDB->quote($to, "timestamp");
168
169 $set = $ilDB->query($query);
170 $completions = array();
171 while ($rec = $ilDB->fetchAssoc($set)) {
172 $completion = [
173 'obj_id' => (int) $rec['obj_id'],
174 'usr_id' => (int) $rec['usr_id'],
175 'completed' => (bool) $rec['completed'],
176 'mark' => (string) $rec['mark'],
177 'comment' => (string) $rec['u_comment'],
178 'status' => (int) $rec['status'],
179 'status_changed' => (string) $rec['status_changed'],
180 'status_dirty' => (int) $rec['status_changed'],
181 'percentage' => (int) $rec['percentage']
182 ];
183 $completions[] = $completion;
184 }
185 return $completions;
186 }
187
188 public static function _lookupMark(int $a_usr_id, int $a_obj_id): string
189 {
190 global $DIC;
191
192 $ilDB = $DIC['ilDB'];
193
194 $query = "SELECT * FROM ut_lp_marks " .
195 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
196 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
197
198 $res = $ilDB->query($query);
199 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
200 return (string) $row->mark;
201 }
202 return '';
203 }
204
205 public static function _lookupComment(int $a_usr_id, int $a_obj_id): string
206 {
207 global $DIC;
208
209 $ilDB = $DIC['ilDB'];
210
211 $query = "SELECT * FROM ut_lp_marks " .
212 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
213 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
214
215 $res = $ilDB->query($query);
216 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
217 return (string) $row->u_comment;
218 }
219 return '';
220 }
221
222 // Private
223 public function __read(): bool
224 {
225 $res = $this->db->query(
226 "SELECT * FROM ut_lp_marks " .
227 "WHERE obj_id = " . $this->db->quote(
228 $this->obj_id,
229 'integer'
230 ) . " " .
231 "AND usr_id = " . $this->db->quote($this->usr_id, 'integer')
232 );
233 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
234 $this->has_entry = true;
235 $this->completed = (int) $row->completed;
236 $this->comment = (string) $row->u_comment;
237 $this->mark = (string) $row->mark;
238 $this->status_changed = (string) $row->status_changed;
239 return true;
240 }
241 return false;
242 }
243
244 public function __add(): void
245 {
246 $query = "INSERT INTO ut_lp_marks (mark,u_comment, completed,obj_id,usr_id) " .
247 "VALUES( " .
248 $this->db->quote($this->getMark(), 'text') . ", " .
249 $this->db->quote($this->getComment(), 'text') . ", " .
250 $this->db->quote($this->getCompleted(), 'integer') . ", " .
251 $this->db->quote($this->getObjId(), 'integer') . ", " .
252 $this->db->quote($this->getUserId(), 'integer') . " " .
253 ")";
254 $res = $this->db->manipulate($query);
255 $this->has_entry = true;
256 }
257
258 public static function _deleteForUsers(
259 int $a_obj_id,
260 array $a_user_ids
261 ): void {
262 global $DIC;
263
264 $ilDB = $DIC['ilDB'];
265 $ilDB->manipulate(
266 "DELETE FROM ut_lp_marks" .
267 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
268 " AND " . $ilDB->in("usr_id", $a_user_ids, "", "integer")
269 );
270 }
271
272 public static function _getAllUserIds(int $a_obj_id): array
273 {
274 global $DIC;
275
276 $ilDB = $DIC['ilDB'];
277
278 $res = array();
279 $set = $ilDB->query(
280 "SELECT usr_id FROM ut_lp_marks" .
281 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer")
282 );
283 while ($row = $ilDB->fetchAssoc($set)) {
284 $res[] = (int) $row["usr_id"];
285 }
286 return $res;
287 }
288}
static deleteObject(int $a_obj_id)
static getCompletionsOfUser(int $user_id, string $from, string $to)
setComment(string $a_comment)
static _lookupComment(int $a_usr_id, int $a_obj_id)
static _getAllUserIds(int $a_obj_id)
static _hasCompleted(int $a_usr_id, int $a_obj_id)
string $status_changed
setMark(string $a_mark)
ilDBInterface $db
static _lookupMark(int $a_usr_id, int $a_obj_id)
static _deleteForUsers(int $a_obj_id, array $a_user_ids)
setCompleted(bool $a_status)
string $comment
__construct(int $a_obj_id, int $a_usr_id)
string $obj_type
ilObjectDataCache $ilObjectDataCache
const LP_STATUS_COMPLETED_NUM
class ilObjectDataCache
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26