ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMemberAgreement.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
28 private int $user_id;
29 private int $obj_id;
30 private string $type;
32 private bool $accepted = false;
33 private int $acceptance_time = 0;
34
35 public function __construct(int $a_usr_id, int $a_obj_id)
36 {
37 global $DIC;
38
39 $ilDB = $DIC['ilDB'];
40
41 $this->db = $ilDB;
42 $this->user_id = $a_usr_id;
43 $this->obj_id = $a_obj_id;
44 $this->type = ilObject::_lookupType($this->obj_id);
45
46 $this->privacy = ilPrivacySettings::getInstance();
47
48 if ($this->privacy->confirmationRequired($this->type) or ilCourseDefinedFieldDefinition::_hasFields($this->obj_id)) {
49 $this->read();
50 }
51 }
52
56 public static function _readByObjId(int $a_obj_id): array
57 {
58 global $DIC;
59
60 $ilDB = $DIC->database();
61
62 $query = "SELECT * FROM member_agreement " .
63 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer');
64
65 $res = $ilDB->query($query);
66 $user_data = [];
67 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
68 $user_data[(int) $row->usr_id]['accepted'] = $row->accepted;
69 $user_data[(int) $row->usr_id]['acceptance_time'] = $row->acceptance_time;
70 }
71 return $user_data;
72 }
73
77 public static function _hasAgreementsByObjId(int $a_obj_id): bool
78 {
79 global $DIC;
80
81 $ilDB = $DIC->database();
82 $query = "SELECT * FROM member_agreement " .
83 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
84 "AND accepted = 1";
85
86 $res = $ilDB->query($query);
87 return (bool) $res->numRows();
88 }
89
93 public static function _hasAgreements(): bool
94 {
95 global $DIC;
96
97 $ilDB = $DIC->database();
98 $query = "SELECT * FROM member_agreement " .
99 "WHERE accepted = 1";
100
101 $res = $ilDB->query($query);
102 return (bool) $res->numRows();
103 }
104
108 public static function _hasAccepted(int $a_usr_id, int $a_obj_id): bool
109 {
110 global $DIC;
111
112 $ilDB = $DIC->database();
113
114 $query = "SELECT accepted FROM member_agreement " .
115 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
116 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
117 $res = $ilDB->query($query);
118 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
119 return (int) $row->accepted === 1;
120 }
121 return false;
122 }
123
128 public static function lookupAcceptedAgreements(int $a_obj_id): array
129 {
130 global $DIC;
131
132 $ilDB = $DIC->database();
133 $query = "SELECT usr_id FROM member_agreement " .
134 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . ' ' .
135 "AND accepted = 1 ";
136
137 $res = $ilDB->query($query);
138 $user_ids = [];
139 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
140 $user_ids[] = (int) $row['usr_id'];
141 }
142 return $user_ids;
143 }
144
148 public static function _deleteByUser(int $a_usr_id): void
149 {
150 global $DIC;
151
152 $ilDB = $DIC->database();
153
154 $query = "DELETE FROM member_agreement " .
155 "WHERE usr_id =" . $ilDB->quote($a_usr_id, 'integer') . " ";
156 $res = $ilDB->manipulate($query);
157 }
158
162 public static function _deleteByObjId(int $a_obj_id): void
163 {
164 global $DIC;
165
166 $ilDB = $DIC->database();
167 $query = "DELETE FROM member_agreement " .
168 "WHERE obj_id =" . $ilDB->quote($a_obj_id, 'integer') . " ";
169 $res = $ilDB->manipulate($query);
170 }
171
176 public static function _reset(): void
177 {
178 global $DIC;
179
180 $ilDB = $DIC->database();
181
182 $query = "UPDATE member_agreement SET accepted = 0 ";
183 $res = $ilDB->manipulate($query);
184 }
185
189 public static function _resetContainer(int $a_container_id): void
190 {
191 global $DIC;
192
193 $ilDB = $DIC->database();
194
195 $query = "UPDATE member_agreement " .
196 "SET accepted = 0 " .
197 "WHERE obj_id = " . $ilDB->quote($a_container_id, 'integer') . " ";
198 $res = $ilDB->manipulate($query);
199 }
200
204 public function setAccepted(bool $a_status): void
205 {
206 $this->accepted = $a_status;
207 }
208
212 public function setAcceptanceTime(int $a_timest): void
213 {
214 $this->acceptance_time = $a_timest;
215 }
216
221 public function agreementRequired(): bool
222 {
223 if (
224 !$this->privacy->confirmationRequired($this->type) &&
226 ) {
227 return false;
228 }
229 return !$this->accepted;
230 }
231
232 public function isAccepted(): bool
233 {
234 return $this->accepted;
235 }
236
237 public function getAcceptanceTime(): int
238 {
240 }
241
245 public function save(): void
246 {
247 $this->delete();
248 $query = "INSERT INTO member_agreement (usr_id,obj_id,accepted,acceptance_time) " .
249 "VALUES( " .
250 $this->db->quote($this->user_id, 'integer') . ", " .
251 $this->db->quote($this->obj_id, 'integer') . ", " .
252 $this->db->quote((int) $this->isAccepted(), 'integer') . ", " .
253 $this->db->quote($this->getAcceptanceTime(), 'integer') . " " .
254 ")";
255 $this->db->manipulate($query);
256 }
257
261 public function delete(): void
262 {
263 $query = "DELETE FROM member_agreement " .
264 "WHERE usr_id = " . $this->db->quote($this->user_id, 'integer') . " " .
265 "AND obj_id = " . $this->db->quote($this->obj_id, 'integer');
266 $res = $this->db->manipulate($query);
267 }
268
272 public function read(): void
273 {
274 $query = "SELECT * FROM member_agreement " .
275 "WHERE usr_id = " . $this->db->quote($this->user_id, 'integer') . " " .
276 "AND obj_id = " . $this->db->quote($this->obj_id, 'integer') . " ";
277
278 $res = $this->db->query($query);
279 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
280 $this->accepted = (bool) $row->accepted;
281 $this->acceptance_time = (int) $row->acceptance_time;
282 }
283 }
284}
static _hasFields(int $a_container_id)
Check if there are any define fields.
save()
save acceptance settings
read()
Read user entries.
static _hasAgreements()
Check if there is any user agreement.
__construct(int $a_usr_id, int $a_obj_id)
static _deleteByUser(int $a_usr_id)
Delete all entries by user.
setAcceptanceTime(int $a_timest)
set acceptance time
static _readByObjId(int $a_obj_id)
Read user data by object id.
static _resetContainer(int $a_container_id)
Reset all agreements for a specific container.
static lookupAcceptedAgreements(int $a_obj_id)
Lookup users who have accepted the agreement.
static _hasAgreementsByObjId(int $a_obj_id)
Check if there is any user agreement.
static _hasAccepted(int $a_usr_id, int $a_obj_id)
Check if user has accepted agreement.
agreementRequired()
Checks whether the agreement is accepted This function return always true if no acceptance is require...
static _deleteByObjId(int $a_obj_id)
Delete all entries by obj_id.
static _reset()
Reset all.
ilPrivacySettings $privacy
setAccepted(bool $a_status)
set accepted
static _lookupType(int $id, bool $reference=false)
Singleton class that stores all privacy settings.
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26