ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMemberAgreement.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 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*/
23include_once('Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
24include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
25
26
36{
37 private $db;
38 private $user_id;
39 private $obj_id;
40 private $type;
41
42 private $privacy;
43
44 private $accepted = false;
45 private $acceptance_time = 0;
46
54 public function __construct($a_usr_id, $a_obj_id)
55 {
56 global $DIC;
57
58 $ilDB = $DIC['ilDB'];
59
60 $this->db = $ilDB;
61 $this->user_id = $a_usr_id;
62 $this->obj_id = $a_obj_id;
63 $this->type = ilObject::_lookupType($this->obj_id);
64
65 $this->privacy = ilPrivacySettings::_getInstance();
66
67 if ($this->privacy->confirmationRequired($this->type) or ilCourseDefinedFieldDefinition::_hasFields($this->obj_id)) {
68 $this->read();
69 }
70 }
71
80 public static function _readByObjId($a_obj_id)
81 {
82 global $DIC;
83
84 $ilDB = $DIC['ilDB'];
85
86 $query = "SELECT * FROM member_agreement " .
87 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer');
88
89 $res = $ilDB->query($query);
90 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
91 $user_data[$row->usr_id]['accepted'] = $row->accepted;
92 $user_data[$row->usr_id]['acceptance_time'] = $row->acceptance_time;
93 }
94 return $user_data ? $user_data : array();
95 }
96
105 public static function _hasAgreementsByObjId($a_obj_id)
106 {
107 global $DIC;
108
109 $ilDB = $DIC['ilDB'];
110
111 $query = "SELECT * FROM member_agreement " .
112 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
113 "AND accepted = 1";
114
115 $res = $ilDB->query($query);
116 return $res->numRows() ? true : false;
117 }
118
127 public static function _hasAgreements()
128 {
129 global $DIC;
130
131 $ilDB = $DIC['ilDB'];
132
133 $query = "SELECT * FROM member_agreement " .
134 "WHERE accepted = 1";
135
136 $res = $ilDB->query($query);
137 return $res->numRows() ? true : false;
138 }
139
148 public static function _hasAccepted($a_usr_id, $a_obj_id)
149 {
150 global $DIC;
151
152 $ilDB = $DIC['ilDB'];
153
154 $query = "SELECT accepted FROM member_agreement " .
155 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
156 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
157 $res = $ilDB->query($query);
159
160 return $row->accepted == 1 ? true : false;
161 }
162
168 public static function lookupAcceptedAgreements($a_obj_id)
169 {
170 global $DIC;
171
172 $ilDB = $DIC['ilDB'];
173
174 $query = "SELECT usr_id FROM member_agreement " .
175 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . ' ' .
176 "AND accepted = 1 ";
177
178 $res = $ilDB->query($query);
179 $user_ids = array();
180 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
181 $user_ids[] = $row['usr_id'];
182 }
183 return $user_ids;
184 }
185
186
187
196 public static function _deleteByUser($a_usr_id)
197 {
198 global $DIC;
199
200 $ilDB = $DIC['ilDB'];
201
202 $query = "DELETE FROM member_agreement " .
203 "WHERE usr_id =" . $ilDB->quote($a_usr_id, 'integer') . " ";
204 $res = $ilDB->manipulate($query);
205
206 return true;
207 }
208
216 public static function _deleteByObjId($a_obj_id)
217 {
218 global $DIC;
219
220 $ilDB = $DIC['ilDB'];
221
222 $query = "DELETE FROM member_agreement " .
223 "WHERE obj_id =" . $ilDB->quote($a_obj_id, 'integer') . " ";
224 $res = $ilDB->manipulate($query);
225
226 return true;
227 }
228
237 public static function _reset()
238 {
239 global $DIC;
240
241 $ilDB = $DIC['ilDB'];
242
243 $query = "UPDATE member_agreement SET accepted = 0 ";
244 $res = $ilDB->manipulate($query);
245
246 return true;
247 }
248
256 public static function _resetContainer($a_container_id)
257 {
258 global $DIC;
259
260 $ilDB = $DIC['ilDB'];
261
262 $query = "UPDATE member_agreement " .
263 "SET accepted = 0 " .
264 "WHERE obj_id = " . $ilDB->quote($a_container_id, 'integer') . " ";
265 $res = $ilDB->manipulate($query);
266
267 return true;
268 }
276 public function setAccepted($a_status)
277 {
278 $this->accepted = $a_status;
279 }
280
288 public function setAcceptanceTime($a_timest)
289 {
290 $this->acceptance_time = $a_timest;
291 }
299 public function agreementRequired()
300 {
301 if (!$this->privacy->confirmationRequired($this->type) and !ilCourseDefinedFieldDefinition::_hasFields($this->obj_id)) {
302 return false;
303 }
304 return $this->accepted ? false : true;
305 }
306
314 public function isAccepted()
315 {
316 return (bool) $this->accepted;
317 }
318
326 public function getAcceptanceTime()
327 {
329 }
330
337 public function save()
338 {
339 global $DIC;
340
341 $ilDB = $DIC['ilDB'];
342
343 $this->delete();
344
345 $query = "INSERT INTO member_agreement (usr_id,obj_id,accepted,acceptance_time) " .
346 "VALUES( " .
347 $this->db->quote($this->user_id, 'integer') . ", " .
348 $this->db->quote($this->obj_id, 'integer') . ", " .
349 $this->db->quote((int) $this->isAccepted(), 'integer') . ", " .
350 $this->db->quote($this->getAcceptanceTime(), 'integer') . " " .
351 ")";
352 $ilDB->manipulate($query);
353 return true;
354 }
355
362 public function delete()
363 {
364 global $DIC;
365
366 $ilDB = $DIC['ilDB'];
367
368 $query = "DELETE FROM member_agreement " .
369 "WHERE usr_id = " . $this->db->quote($this->user_id, 'integer') . " " .
370 "AND obj_id = " . $this->db->quote($this->obj_id, 'integer');
371 $res = $ilDB->manipulate($query);
372 return true;
373 }
374
380 public function read()
381 {
382 $query = "SELECT * FROM member_agreement " .
383 "WHERE usr_id = " . $this->db->quote($this->user_id, 'integer') . " " .
384 "AND obj_id = " . $this->db->quote($this->obj_id, 'integer') . " ";
385
386 $res = $this->db->query($query);
387 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
388 $this->accepted = $row->accepted;
389 $this->acceptance_time = $row->acceptance_time;
390 }
391 }
392}
An exception for terminatinating execution or to throw for unit testing.
static _hasFields($a_container_id)
Check if there are any define fields.
save()
save Acceptance settings
static _hasAccepted($a_usr_id, $a_obj_id)
Check if user has accepted agreement.
setAccepted($a_status)
set accepted
read()
Read user entries.
static _hasAgreementsByObjId($a_obj_id)
Check if there is any user agreement.
setAcceptanceTime($a_timest)
set acceptance time
static _hasAgreements()
Check if there is any user agreement.
static _deleteByObjId($a_obj_id)
Delete all entries by obj_id.
static _deleteByUser($a_usr_id)
Delete all entries by user.
getAcceptanceTime()
get Acceptance time
__construct($a_usr_id, $a_obj_id)
Constructor.
static lookupAcceptedAgreements($a_obj_id)
Lookup users who have accepted the agreement.
agreementRequired()
Checks whether the agreement is accepted This function return always true if no acceptance is require...
static _readByObjId($a_obj_id)
Read user data by object id.
static _resetContainer($a_container_id)
Reset all agreements for a specific container.
static _reset()
Reset all.
static _lookupType($a_id, $a_reference=false)
lookup object type
static _getInstance()
Get instance of ilPrivacySettings.
$row
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB