ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCourseAgreement.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 
41  private $privacy;
42 
43  private $accepted = false;
44  private $acceptance_time = 0;
45 
53  public function __construct($a_usr_id,$a_obj_id)
54  {
55  global $ilDB;
56 
57  $this->db = $ilDB;
58  $this->user_id = $a_usr_id;
59  $this->obj_id = $a_obj_id;
60 
61  $this->privacy = ilPrivacySettings::_getInstance();
62 
63  if($this->privacy->confirmationRequired() or ilCourseDefinedFieldDefinition::_hasFields($this->obj_id))
64  {
65  $this->read();
66  }
67  }
68 
77  public static function _readByObjId($a_obj_id)
78  {
79  global $ilDB;
80 
81  $query = "SELECT * FROM member_agreement ".
82  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer');
83 
84  $res = $ilDB->query($query);
85  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
86  {
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);
148  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
149 
150  return $row->accepted == 1 ? true : false;
151  }
152 
153 
162  public static function _deleteByUser($a_usr_id)
163  {
164  global $ilDB;
165 
166  $query = "DELETE FROM member_agreement ".
167  "WHERE usr_id =".$ilDB->quote($a_usr_id ,'integer')." ";
168  $res = $ilDB->manipulate($query);
169 
170  return true;
171  }
172 
180  public static function _deleteByObjId($a_obj_id)
181  {
182  global $ilDB;
183 
184  $query = "DELETE FROM member_agreement ".
185  "WHERE obj_id =".$ilDB->quote($a_obj_id ,'integer')." ";
186  $res = $ilDB->manipulate($query);
187 
188  return true;
189 
190  }
191 
200  public static function _reset()
201  {
202  global $ilDB;
203 
204  $query = "UPDATE member_agreement SET accepted = 0 ";
205  $res = $ilDB->manipulate($query);
206 
207  return true;
208  }
209 
217  public static function _resetContainer($a_container_id)
218  {
219  global $ilDB;
220 
221  $query = "UPDATE member_agreement ".
222  "SET accepted = 0 ".
223  "WHERE obj_id = ".$ilDB->quote($a_container_id ,'integer')." ";
224  $res = $ilDB->manipulate($query);
225 
226  return true;
227  }
235  public function setAccepted($a_status)
236  {
237  $this->accepted = $a_status;
238  }
239 
247  public function setAcceptanceTime($a_timest)
248  {
249  $this->acceptance_time = $a_timest;
250  }
258  public function agreementRequired()
259  {
260  if(!$this->privacy->confirmationRequired() and !ilCourseDefinedFieldDefinition::_hasFields($this->obj_id))
261  {
262  return false;
263  }
264  return $this->accepted ? false : true;
265  }
266 
274  public function isAccepted()
275  {
276  return (bool) $this->accepted;
277  }
278 
286  public function getAcceptanceTime()
287  {
288  return $this->acceptance_time;
289  }
290 
297  public function save()
298  {
299  global $ilDB;
300 
301  $this->delete();
302 
303  $query = "INSERT INTO member_agreement (usr_id,obj_id,accepted,acceptance_time) ".
304  "VALUES( ".
305  $this->db->quote($this->user_id ,'integer').", ".
306  $this->db->quote($this->obj_id ,'integer').", ".
307  $this->db->quote((int) $this->isAccepted() ,'integer').", ".
308  $this->db->quote($this->getAcceptanceTime() ,'integer')." ".
309  ")";
310  $res = $ilDB->manipulate($query);
311  return true;
312  }
313 
320  public function delete()
321  {
322  global $ilDB;
323 
324  $query = "DELETE FROM member_agreement ".
325  "WHERE usr_id = ".$this->db->quote($this->user_id ,'integer')." ".
326  "AND obj_id = ".$this->db->quote($this->obj_id ,'integer');
327  $res = $ilDB->manipulate($query);
328  return true;
329  }
330 
336  public function read()
337  {
338  $query = "SELECT * FROM member_agreement ".
339  "WHERE usr_id = ".$this->db->quote($this->user_id ,'integer')." ".
340  "AND obj_id = ".$this->db->quote($this->obj_id ,'integer')." ";
341 
342  $res = $this->db->query($query);
343  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
344  {
345  $this->accepted = $row->accepted;
346  $this->acceptance_time = $row->acceptance_time;
347  }
348  }
349 }
350 ?>