ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPaymentTrustees.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 
35 {
36  var $db = null;
37 
38  var $user_obj;
39  var $trustees = array();
40 
46  {
47  global $ilDB;
48 
49  $this->db =& $ilDB;
50  $this->user_obj =& $user_obj;
51 
52  $this->PERM_STATISTIC = 1;
53  $this->PERM_OBJECT = 2;
54 
55  $this->__read();
56  }
57 
58  function getTrustees()
59  {
60  return $this->trustees ? $this->trustees : array();
61  }
62  function getTrustee($a_usr_id)
63  {
64  return isset($this->trustees[$a_usr_id]) ? $this->trustees[$a_usr_id] : array();
65  }
66  function isTrustee($a_usr_id)
67  {
68  return isset($this->trustees[$a_usr_id]);
69  }
70 
71 
72 
73  function toggleStatisticPermission($a_on)
74  {
75  $this->perm_stat = (bool) $a_on;
76  }
77  function toggleObjectPermission($a_on)
78  {
79  $this->perm_obj = (bool) $a_on;
80  }
81  function toggleCouponsPermission($a_on)
82  {
83  $this->perm_coupons = (bool) $a_on;
84  }
85  function setTrusteeId($a_id)
86  {
87  $this->trustee_id = $a_id;
88  }
89 
90  function add()
91  {
92  $query = "INSERT INTO payment_trustees ".
93  "SET vendor_id = '".$this->user_obj->getId()."', ".
94  "trustee_id = '".$this->__getTrusteeId()."', ".
95  "perm_stat = '".$this->__getStatisticPermissionStatus()."', ".
96  "perm_coupons = '".$this->__getCouponsPermissisonStatus()."', ".
97  "perm_obj = '".$this->__getObjectPermissisonStatus()."'";
98 
99  $this->db->query($query);
100  $this->__read();
101 
102  return true;
103  }
104  function modify()
105  {
106  if(!$this->__getTrusteeId())
107  {
108  die("ilPaymentTrustees::modify() no id given");
109  }
110 
111  $query = "UPDATE payment_trustees SET ".
112  "trustee_id = '".$this->__getTrusteeId()."', ".
113  "perm_stat = '".$this->__getStatisticPermissionStatus()."', ".
114  "perm_obj = '".$this->__getObjectPermissisonStatus()."', ".
115  "perm_coupons = '".$this->__getCouponsPermissisonStatus()."' ".
116  "WHERE vendor_id = '".$this->user_obj->getId()."' ".
117  "AND trustee_id = '".$this->__getTrusteeId()."'";
118 
119  $this->db->query($query);
120  $this->__read();
121 
122  return true;
123  }
124  function delete()
125  {
126  if(!$this->__getTrusteeId())
127  {
128  die("ilPaymentTrustees::delete() no id given");
129  }
130  $query = "DELETE FROM payment_trustees ".
131  "WHERE vendor_id = '".$this->user_obj->getId()."' ".
132  "AND trustee_id = '".$this->__getTrusteeId()."'";
133 
134  $this->db->query($query);
135  $this->__read();
136 
137  return true;
138  }
139 
140  function deleteAll()
141  {
142  $query = "DELETE FROM payment_trustees ".
143  "WHERE vendor_id = '".$this->user_obj->getId()."'";
144 
145  $this->db->query($query);
146  $this->__read();
147 
148  return true;
149  }
150 
151 
152  // PRIVATE
153  function __getTrusteeId()
154  {
155  return $this->trustee_id;
156  }
158  {
159  return (int) $this->perm_stat;
160  }
162  {
163  return (int) $this->perm_obj;
164  }
166  {
167  return (int) $this->perm_coupons;
168  }
169  function __read()
170  {
171  $this->trustees = array();
172 
173  $query = "SELECT * FROM payment_trustees ".
174  "WHERE vendor_id = '".$this->user_obj->getId()."'";
175 
176  $res = $this->db->query($query);
177  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
178  {
179  $this->trustees[$row->trustee_id]['trustee_id'] = $row->trustee_id;
180  $this->trustees[$row->trustee_id]['perm_stat'] = $row->perm_stat;
181  $this->trustees[$row->trustee_id]['perm_obj'] = $row->perm_obj;
182  $this->trustees[$row->trustee_id]['perm_coupons'] = $row->perm_coupons;
183  }
184  }
185 
186  // STATIC
187  function _deleteTrusteesOfVendor($a_vendor_id)
188  {
189  global $ilDB;
190 
191  $query = "DELETE FROM payment_trustees ".
192  "WHERE vendor_id = '".$a_vendor_id."'";
193 
194  $ilDB->query($query);
195 
196  return true;
197  }
198 
199  function _hasStatisticPermission($a_trustee)
200  {
201  global $ilDB;
202 
203  $query = "SELECT * FROM payment_trustees ".
204  "WHERE trustee_id = '".$a_trustee."'";
205 
206  $res = $ilDB->query($query);
207  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
208  {
209  if((bool) $row->perm_stat)
210  {
211  return true;
212  }
213  }
214  return false;
215  }
216  function _hasObjectPermission($a_trustee)
217  {
218  global $ilDB;
219 
220  $query = "SELECT * FROM payment_trustees ".
221  "WHERE trustee_id = '".$a_trustee."'";
222 
223  $res = $ilDB->query($query);
224  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
225  {
226  if((bool) $row->perm_obj)
227  {
228  return true;
229  }
230  }
231  return false;
232  }
233  function _hasCouponsPermission($a_trustee)
234  {
235  global $ilDB;
236 
237  $query = "SELECT * FROM payment_trustees ".
238  "WHERE trustee_id = '".$a_trustee."'";
239 
240  $res = $ilDB->query($query);
241  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
242  {
243  if((bool) $row->perm_coupons)
244  {
245  return true;
246  }
247  }
248  return false;
249  }
250  function _hasStatisticPermissionByVendor($a_trustee,$a_vendor)
251  {
252  global $ilDB;
253 
254  $query = "SELECT * FROM payment_trustees ".
255  "WHERE trustee_id = '".$a_trustee."' ".
256  "AND vendor_id = '".$a_vendor."' ".
257  "AND perm_stat = '1'";
258 
259  $res = $ilDB->query($query);
260 
261  return $res->numRows() ? true : false;
262  }
263 
264  function _hasObjectPermissionByVendor($a_trustee,$a_vendor)
265  {
266  global $ilDB;
267 
268  $query = "SELECT * FROM payment_trustees ".
269  "WHERE trustee_id = '".$a_trustee."' ".
270  "AND vendor_id = '".$a_vendor."' ".
271  "AND perm_obj = '1'";
272 
273  $res = $ilDB->query($query);
274 
275  return $res->numRows() ? true : false;
276  }
277 
278  function _hasCouponsPermissionByVendor($a_trustee,$a_vendor)
279  {
280  global $ilDB;
281 
282  $query = "SELECT * FROM payment_trustees ".
283  "WHERE trustee_id = '".$a_trustee."' ".
284  "AND vendor_id = '".$a_vendor."' ".
285  "AND perm_coupons = '1'";
286 
287  $res = $ilDB->query($query);
288 
289  return $res->numRows() ? true : false;
290  }
291 
292  function _hasAccess($a_usr_id)
293  {
294  return ilPaymentTrustees::_hasStatisticPermission($a_usr_id) or
297  }
298 
299  function _getVendorsForObjects($a_usr_id)
300  {
301  global $ilDB;
302 
303  $query = "SELECT vendor_id FROM payment_trustees ".
304  "WHERE perm_obj = '1' ".
305  "AND trustee_id = '".$a_usr_id."'";
306 
307  $res = $ilDB->query($query);
308  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
309  {
310  $vendors[] = $row->vendor_id;
311  }
312 
313  return $vendors ? $vendors : array();
314  }
315 
317  {
318  global $ilDB;
319 
320  $query = "SELECT vendor_id FROM payment_trustees ".
321  "WHERE perm_coupons = '1' ".
322  "AND trustee_id = '".$a_usr_id."'";
323 
324  $res = $ilDB->query($query);
325  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
326  {
327  $vendors[] = $row->vendor_id;
328  }
329 
330  return $vendors ? $vendors : array();
331  }
332 
334  {
335  global $ilDB;
336 
337  $query = "SELECT trustee_id FROM payment_trustees ".
338  "WHERE perm_coupons = '1' ".
339  "AND vendor_id = '".$a_usr_id."'";
340 
341  $res = $ilDB->query($query);
342  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
343  {
344  $trustees[] = $row->trustee_id;
345  }
346 
347  return $trustees ? $trustees : array();
348  }
349 
350 } // END class.ilPaymentTrustees
351 ?>