ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilDB;
57
58 $this->db = $ilDB;
59 $this->user_id = $a_usr_id;
60 $this->obj_id = $a_obj_id;
61 $this->type = ilObject::_lookupType($this->obj_id);
62
63 $this->privacy = ilPrivacySettings::_getInstance();
64
65 if ($this->privacy->confirmationRequired($this->type) or ilCourseDefinedFieldDefinition::_hasFields($this->obj_id)) {
66 $this->read();
67 }
68 }
69
78 public static function _readByObjId($a_obj_id)
79 {
80 global $ilDB;
81
82 $query = "SELECT * FROM member_agreement " .
83 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer');
84
85 $res = $ilDB->query($query);
86 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
87 $user_data[$row->usr_id]['accepted'] = $row->accepted;
88 $user_data[$row->usr_id]['acceptance_time'] = $row->acceptance_time;
89 }
90 return $user_data ? $user_data : array();
91 }
92
101 public static function _hasAgreementsByObjId($a_obj_id)
102 {
103 global $ilDB;
104
105 $query = "SELECT * FROM member_agreement " .
106 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
107 "AND accepted = 1";
108
109 $res = $ilDB->query($query);
110 return $res->numRows() ? true : false;
111 }
112
121 public static function _hasAgreements()
122 {
123 global $ilDB;
124
125 $query = "SELECT * FROM member_agreement " .
126 "WHERE accepted = 1";
127
128 $res = $ilDB->query($query);
129 return $res->numRows() ? true : false;
130 }
131
140 public static function _hasAccepted($a_usr_id, $a_obj_id)
141 {
142 global $ilDB;
143
144 $query = "SELECT accepted FROM member_agreement " .
145 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
146 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
147 $res = $ilDB->query($query);
149
150 return $row->accepted == 1 ? true : false;
151 }
152
158 public static function lookupAcceptedAgreements($a_obj_id)
159 {
160 global $ilDB;
161
162 $query = "SELECT usr_id FROM member_agreement " .
163 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . ' ' .
164 "AND accepted = 1 ";
165
166 $res = $ilDB->query($query);
167 $user_ids = array();
168 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
169 $user_ids[] = $row['usr_id'];
170 }
171 return $user_ids;
172 }
173
174
175
184 public static function _deleteByUser($a_usr_id)
185 {
186 global $ilDB;
187
188 $query = "DELETE FROM member_agreement " .
189 "WHERE usr_id =" . $ilDB->quote($a_usr_id, 'integer') . " ";
190 $res = $ilDB->manipulate($query);
191
192 return true;
193 }
194
202 public static function _deleteByObjId($a_obj_id)
203 {
204 global $ilDB;
205
206 $query = "DELETE FROM member_agreement " .
207 "WHERE obj_id =" . $ilDB->quote($a_obj_id, 'integer') . " ";
208 $res = $ilDB->manipulate($query);
209
210 return true;
211 }
212
221 public static function _reset()
222 {
223 global $ilDB;
224
225 $query = "UPDATE member_agreement SET accepted = 0 ";
226 $res = $ilDB->manipulate($query);
227
228 return true;
229 }
230
238 public static function _resetContainer($a_container_id)
239 {
240 global $ilDB;
241
242 $query = "UPDATE member_agreement " .
243 "SET accepted = 0 " .
244 "WHERE obj_id = " . $ilDB->quote($a_container_id, 'integer') . " ";
245 $res = $ilDB->manipulate($query);
246
247 return true;
248 }
256 public function setAccepted($a_status)
257 {
258 $this->accepted = $a_status;
259 }
260
268 public function setAcceptanceTime($a_timest)
269 {
270 $this->acceptance_time = $a_timest;
271 }
279 public function agreementRequired()
280 {
281 if (!$this->privacy->confirmationRequired($this->type) and !ilCourseDefinedFieldDefinition::_hasFields($this->obj_id)) {
282 return false;
283 }
284 return $this->accepted ? false : true;
285 }
286
294 public function isAccepted()
295 {
296 return (bool) $this->accepted;
297 }
298
306 public function getAcceptanceTime()
307 {
309 }
310
317 public function save()
318 {
319 global $ilDB;
320
321 $this->delete();
322
323 $query = "INSERT INTO member_agreement (usr_id,obj_id,accepted,acceptance_time) " .
324 "VALUES( " .
325 $this->db->quote($this->user_id, 'integer') . ", " .
326 $this->db->quote($this->obj_id, 'integer') . ", " .
327 $this->db->quote((int) $this->isAccepted(), 'integer') . ", " .
328 $this->db->quote($this->getAcceptanceTime(), 'integer') . " " .
329 ")";
330 $ilDB->manipulate($query);
331 return true;
332 }
333
340 public function delete()
341 {
342 global $ilDB;
343
344 $query = "DELETE FROM member_agreement " .
345 "WHERE usr_id = " . $this->db->quote($this->user_id, 'integer') . " " .
346 "AND obj_id = " . $this->db->quote($this->obj_id, 'integer');
347 $res = $ilDB->manipulate($query);
348 return true;
349 }
350
356 public function read()
357 {
358 $query = "SELECT * FROM member_agreement " .
359 "WHERE usr_id = " . $this->db->quote($this->user_id, 'integer') . " " .
360 "AND obj_id = " . $this->db->quote($this->obj_id, 'integer') . " ";
361
362 $res = $this->db->query($query);
363 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
364 $this->accepted = $row->accepted;
365 $this->acceptance_time = $row->acceptance_time;
366 }
367 }
368}
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.
$query
foreach($_POST as $key=> $value) $res
global $ilDB