ILIAS  release_8 Revision v8.24
class.ilLPMarks.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
31{
32 protected ?ilDBInterface $db;
34
35 protected int $obj_id;
36 protected int $usr_id;
37 protected ?string $obj_type;
38
39 protected bool $completed = false;
40 protected string $comment = '';
41 protected string $mark = '';
42 protected string $status_changed = '';
43
44 protected $has_entry = false;
45
46 public function __construct(int $a_obj_id, int $a_usr_id)
47 {
48 global $DIC;
49
50 $this->ilObjectDataCache = $DIC['ilObjDataCache'];
51 $this->db = $DIC->database();
52
53 $this->obj_id = $a_obj_id;
54 $this->usr_id = $a_usr_id;
55 $this->obj_type = $this->ilObjectDataCache->lookupType($this->obj_id);
56
57 $this->__read();
58 }
59
60 public static function deleteObject(int $a_obj_id): void
61 {
62 global $DIC;
63
64 $ilDB = $DIC['ilDB'];
65
66 $query = "DELETE FROM ut_lp_marks " .
67 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer');
68 $res = $ilDB->manipulate($query);
69 }
70
71 public function getUserId(): int
72 {
73 return $this->usr_id;
74 }
75
76 public function setMark(string $a_mark): void
77 {
78 $this->mark = $a_mark;
79 }
80
81 public function getMark(): string
82 {
83 return $this->mark;
84 }
85
86 public function setComment(string $a_comment): void
87 {
88 $this->comment = $a_comment;
89 }
90
91 public function getComment(): string
92 {
93 return $this->comment;
94 }
95
96 public function setCompleted(bool $a_status): void
97 {
98 $this->completed = $a_status;
99 }
100
101 public function getCompleted(): bool
102 {
103 return $this->completed;
104 }
105
106 public function getStatusChanged(): string
107 {
109 }
110
111 public function getObjId(): int
112 {
113 return $this->obj_id;
114 }
115
116 public function update(): void
117 {
118 if (!$this->has_entry) {
119 $this->__add();
120 }
121 $query = "UPDATE ut_lp_marks " .
122 "SET mark = " . $this->db->quote($this->getMark(), 'text') . ", " .
123 "u_comment = " . $this->db->quote(
124 $this->getComment(),
125 'text'
126 ) . ", " .
127 "completed = " . $this->db->quote(
128 $this->getCompleted(),
129 'integer'
130 ) . " " .
131 "WHERE obj_id = " . $this->db->quote(
132 $this->getObjId(),
133 'integer'
134 ) . " " .
135 "AND usr_id = " . $this->db->quote($this->getUserId(), 'integer');
136 $res = $this->db->manipulate($query);
137 }
138
139 // Static
140 public static function _hasCompleted(int $a_usr_id, int $a_obj_id): bool
141 {
142 global $DIC;
143
144 $ilDB = $DIC['ilDB'];
145
146 $query = "SELECT * FROM ut_lp_marks " .
147 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
148 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
149
150 $res = $ilDB->query($query);
151 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
152 return (bool) $row->completed;
153 }
154 return false;
155 }
156
157 public static function getCompletionsOfUser(
158 int $user_id,
159 string $from,
160 string $to
161 ): array {
162 global $DIC;
163
164 $ilDB = $DIC['ilDB'];
165
166 $query = "SELECT * FROM ut_lp_marks " .
167 "WHERE usr_id = " . $ilDB->quote($user_id, 'integer') .
168 " AND status = " . $ilDB->quote(
170 'integer'
171 ) .
172 " AND status_changed >= " . $ilDB->quote($from, "timestamp") .
173 " AND status_changed <= " . $ilDB->quote($to, "timestamp");
174
175 $set = $ilDB->query($query);
176 $completions = array();
177 while ($rec = $ilDB->fetchAssoc($set)) {
178 $completion = [
179 'obj_id' => (int) $rec['obj_id'],
180 'usr_id' => (int) $rec['usr_id'],
181 'completed' => (bool) $rec['completed'],
182 'mark' => (string) $rec['mark'],
183 'comment' => (string) $rec['u_comment'],
184 'status' => (int) $rec['status'],
185 'status_changed' => (string) $rec['status_changed'],
186 'status_dirty' => (int) $rec['status_changed'],
187 'percentage' => (int) $rec['percentage']
188 ];
189 $completions[] = $completion;
190 }
191 return $completions;
192 }
193
194 public static function _lookupMark(int $a_usr_id, int $a_obj_id): string
195 {
196 global $DIC;
197
198 $ilDB = $DIC['ilDB'];
199
200 $query = "SELECT * FROM ut_lp_marks " .
201 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
202 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
203
204 $res = $ilDB->query($query);
205 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
206 return (string) $row->mark;
207 }
208 return '';
209 }
210
211 public static function _lookupComment(int $a_usr_id, int $a_obj_id): string
212 {
213 global $DIC;
214
215 $ilDB = $DIC['ilDB'];
216
217 $query = "SELECT * FROM ut_lp_marks " .
218 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
219 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
220
221 $res = $ilDB->query($query);
222 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
223 return (string) $row->u_comment;
224 }
225 return '';
226 }
227
228 // Private
229 public function __read(): bool
230 {
231 $res = $this->db->query(
232 "SELECT * FROM ut_lp_marks " .
233 "WHERE obj_id = " . $this->db->quote(
234 $this->obj_id,
235 'integer'
236 ) . " " .
237 "AND usr_id = " . $this->db->quote($this->usr_id, 'integer')
238 );
239 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
240 $this->has_entry = true;
241 $this->completed = (int) $row->completed;
242 $this->comment = (string) $row->u_comment;
243 $this->mark = (string) $row->mark;
244 $this->status_changed = (string) $row->status_changed;
245 return true;
246 }
247 return false;
248 }
249
250 public function __add(): void
251 {
252 $query = "INSERT INTO ut_lp_marks (mark,u_comment, completed,obj_id,usr_id) " .
253 "VALUES( " .
254 $this->db->quote($this->getMark(), 'text') . ", " .
255 $this->db->quote($this->getComment(), 'text') . ", " .
256 $this->db->quote($this->getCompleted(), 'integer') . ", " .
257 $this->db->quote($this->getObjId(), 'integer') . ", " .
258 $this->db->quote($this->getUserId(), 'integer') . " " .
259 ")";
260 $res = $this->db->manipulate($query);
261 $this->has_entry = true;
262 }
263
264 public static function _deleteForUsers(
265 int $a_obj_id,
266 array $a_user_ids
267 ): void {
268 global $DIC;
269
270 $ilDB = $DIC['ilDB'];
271 $ilDB->manipulate(
272 "DELETE FROM ut_lp_marks" .
273 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
274 " AND " . $ilDB->in("usr_id", $a_user_ids, "", "integer")
275 );
276 }
277
278 public static function _getAllUserIds(int $a_obj_id): array
279 {
280 global $DIC;
281
282 $ilDB = $DIC['ilDB'];
283
284 $res = array();
285 $set = $ilDB->query(
286 "SELECT usr_id FROM ut_lp_marks" .
287 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer")
288 );
289 while ($row = $ilDB->fetchAssoc($set)) {
290 $res[] = (int) $row["usr_id"];
291 }
292 return $res;
293 }
294}
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query