ILIAS  Release_3_10_x_branch Revision 61812
 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);
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)." ".
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)." ".
146  "AND obj_id = ".$ilDB->quote($a_obj_id);
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)." ";
168  $ilDB->query($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)." ";
186  $ilDB->query($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  $ilDB->query($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)." ";
224  $ilDB->query($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  $this->delete();
300 
301  $query = "INSERT INTO member_agreement ".
302  "SET usr_id = ".$this->db->quote($this->user_id).", ".
303  "obj_id = ".$this->db->quote($this->obj_id).", ".
304  "accepted = ".$this->db->quote((int) $this->isAccepted()).", ".
305  "acceptance_time = ".$this->db->quote($this->getAcceptanceTime());
306 
307  $this->db->query($query);
308  return true;
309  }
310 
317  public function delete()
318  {
319  $query = "DELETE FROM member_agreement ".
320  "WHERE usr_id = ".$this->db->quote($this->user_id)." ".
321  "AND obj_id = ".$this->db->quote($this->obj_id);
322 
323  $this->db->query($query);
324  return true;
325  }
326 
332  private function read()
333  {
334  $query = "SELECT * FROM member_agreement ".
335  "WHERE usr_id = ".$this->db->quote($this->user_id)." ".
336  "AND obj_id = ".$this->db->quote($this->obj_id)." ";
337 
338  $res = $this->db->query($query);
339  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
340  $this->accepted = $row->accepted;
341  $this->acceptance_time = $row->acceptance_time;
342  }
343 }
344 ?>