ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 */
23 include_once('Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
24 include_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  {
67  $this->read();
68  }
69  }
70 
79  public static function _readByObjId($a_obj_id)
80  {
81  global $ilDB;
82 
83  $query = "SELECT * FROM member_agreement ".
84  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer');
85 
86  $res = $ilDB->query($query);
87  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
88  {
89  $user_data[$row->usr_id]['accepted'] = $row->accepted;
90  $user_data[$row->usr_id]['acceptance_time'] = $row->acceptance_time;
91  }
92  return $user_data ? $user_data : array();
93  }
94 
103  public static function _hasAgreementsByObjId($a_obj_id)
104  {
105  global $ilDB;
106 
107  $query = "SELECT * FROM member_agreement ".
108  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
109  "AND accepted = 1";
110 
111  $res = $ilDB->query($query);
112  return $res->numRows() ? true : false;
113  }
114 
123  public static function _hasAgreements()
124  {
125  global $ilDB;
126 
127  $query = "SELECT * FROM member_agreement ".
128  "WHERE accepted = 1";
129 
130  $res = $ilDB->query($query);
131  return $res->numRows() ? true : false;
132  }
133 
142  public static function _hasAccepted($a_usr_id,$a_obj_id)
143  {
144  global $ilDB;
145 
146  $query = "SELECT accepted FROM member_agreement ".
147  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
148  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
149  $res = $ilDB->query($query);
150  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
151 
152  return $row->accepted == 1 ? true : false;
153  }
154 
160  public static function lookupAcceptedAgreements($a_obj_id)
161  {
162  global $ilDB;
163 
164  $query = "SELECT usr_id FROM member_agreement ".
165  "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer').' '.
166  "AND accepted = 1 ";
167 
168  $res = $ilDB->query($query);
169  $user_ids = array();
170  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
171  {
172  $user_ids[] = $row['usr_id'];
173  }
174  return $user_ids;
175  }
176 
177 
178 
187  public static function _deleteByUser($a_usr_id)
188  {
189  global $ilDB;
190 
191  $query = "DELETE FROM member_agreement ".
192  "WHERE usr_id =".$ilDB->quote($a_usr_id ,'integer')." ";
193  $res = $ilDB->manipulate($query);
194 
195  return true;
196  }
197 
205  public static function _deleteByObjId($a_obj_id)
206  {
207  global $ilDB;
208 
209  $query = "DELETE FROM member_agreement ".
210  "WHERE obj_id =".$ilDB->quote($a_obj_id ,'integer')." ";
211  $res = $ilDB->manipulate($query);
212 
213  return true;
214 
215  }
216 
225  public static function _reset()
226  {
227  global $ilDB;
228 
229  $query = "UPDATE member_agreement SET accepted = 0 ";
230  $res = $ilDB->manipulate($query);
231 
232  return true;
233  }
234 
242  public static function _resetContainer($a_container_id)
243  {
244  global $ilDB;
245 
246  $query = "UPDATE member_agreement ".
247  "SET accepted = 0 ".
248  "WHERE obj_id = ".$ilDB->quote($a_container_id ,'integer')." ";
249  $res = $ilDB->manipulate($query);
250 
251  return true;
252  }
260  public function setAccepted($a_status)
261  {
262  $this->accepted = $a_status;
263  }
264 
272  public function setAcceptanceTime($a_timest)
273  {
274  $this->acceptance_time = $a_timest;
275  }
283  public function agreementRequired()
284  {
285  if(!$this->privacy->confirmationRequired($this->type) and !ilCourseDefinedFieldDefinition::_hasFields($this->obj_id))
286  {
287  return false;
288  }
289  return $this->accepted ? false : true;
290  }
291 
299  public function isAccepted()
300  {
301  return (bool) $this->accepted;
302  }
303 
311  public function getAcceptanceTime()
312  {
313  return $this->acceptance_time;
314  }
315 
322  public function save()
323  {
324  global $ilDB;
325 
326  $this->delete();
327 
328  $query = "INSERT INTO member_agreement (usr_id,obj_id,accepted,acceptance_time) ".
329  "VALUES( ".
330  $this->db->quote($this->user_id ,'integer').", ".
331  $this->db->quote($this->obj_id ,'integer').", ".
332  $this->db->quote((int) $this->isAccepted() ,'integer').", ".
333  $this->db->quote($this->getAcceptanceTime() ,'integer')." ".
334  ")";
335  $res = $ilDB->manipulate($query);
336  return true;
337  }
338 
345  public function delete()
346  {
347  global $ilDB;
348 
349  $query = "DELETE FROM member_agreement ".
350  "WHERE usr_id = ".$this->db->quote($this->user_id ,'integer')." ".
351  "AND obj_id = ".$this->db->quote($this->obj_id ,'integer');
352  $res = $ilDB->manipulate($query);
353  return true;
354  }
355 
361  public function read()
362  {
363  $query = "SELECT * FROM member_agreement ".
364  "WHERE usr_id = ".$this->db->quote($this->user_id ,'integer')." ".
365  "AND obj_id = ".$this->db->quote($this->obj_id ,'integer')." ";
366 
367  $res = $this->db->query($query);
368  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
369  {
370  $this->accepted = $row->accepted;
371  $this->acceptance_time = $row->acceptance_time;
372  }
373  }
374 }
375 ?>