ILIAS  Release_4_0_x_branch Revision 61816
 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  function toggleStatisticPermission($a_on)
72  {
73  $this->perm_stat = (bool) $a_on;
74  }
75  function toggleObjectPermission($a_on)
76  {
77  $this->perm_obj = (bool) $a_on;
78  }
79  function toggleCouponsPermission($a_on)
80  {
81  $this->perm_coupons = (bool) $a_on;
82  }
83  function setTrusteeId($a_id)
84  {
85  $this->trustee_id = $a_id;
86  }
87 
88  function add()
89  {
90  $statement = $this->db->manipulateF('
91  INSERT INTO payment_trustees
92  ( vendor_id,
93  trustee_id,
94  perm_stat,
95  perm_coupons,
96  perm_obj
97  )
98  VALUES (%s,%s,%s,%s,%s)',
99  array('integer', 'integer', 'integer', 'integer', 'integer'),
100  array( $this->user_obj->getId(),
101  $this->__getTrusteeId(),
105  ));
106 
107 
108  $this->__read();
109 
110  return true;
111  }
112  function modify()
113  {
114  if(!$this->__getTrusteeId())
115  {
116  die("ilPaymentTrustees::modify() no id given");
117  }
118 
119  $statement = $this->db->manipulateF('
120  UPDATE payment_trustees
121  SET trustee_id = %s,
122  perm_stat = %s,
123  perm_obj = %s,
124  perm_coupons = %s
125  WHERE vendor_id = %s
126  AND trustee_id = %s',
127  array('integer', 'integer', 'integer', 'integer', 'integer', 'integer'),
128  array( $this->__getTrusteeId(),
132  $this->user_obj->getId(),
133  $this->__getTrusteeId()
134  ));
135 
136 
137  $this->__read();
138 
139  return true;
140  }
141  function delete()
142  {
143  if(!$this->__getTrusteeId())
144  {
145  die("ilPaymentTrustees::delete() no id given");
146  }
147 
148  $statement = $this->db->manipulateF('
149  DELETE FROM payment_trustees
150  WHERE vendor_id = %s
151  AND trustee_id = %s ',
152  array('integer', 'integer'),
153  array($this->user_obj->getId(), $this->__getTrusteeId()));
154 
155  $this->__read();
156 
157  return true;
158  }
159 
160  function deleteAll()
161  {
162  $statement = $this->db->manipulateF('
163  DELETE FROM payment_trustees
164  WHERE vendor_id = %s',
165  array('integer'),
166  array($this->user_obj->getId()));
167 
168  $this->__read();
169 
170  return true;
171  }
172 
173 
174  // PRIVATE
175  function __getTrusteeId()
176  {
177  return $this->trustee_id;
178  }
180  {
181  return (int) $this->perm_stat;
182  }
184  {
185  return (int) $this->perm_obj;
186  }
188  {
189  return (int) $this->perm_coupons;
190  }
191  function __read()
192  {
193 
194  $this->trustees = array();
195 
196  $res = $this->db->queryf('
197  SELECT * FROM payment_trustees
198  WHERE vendor_id = %s',
199  array('integer'),
200  array($this->user_obj->getId()));
201 
202  while($row = $this->db->fetchObject($res))
203  {
204  $this->trustees[$row->trustee_id]['trustee_id'] = $row->trustee_id;
205  $this->trustees[$row->trustee_id]['perm_stat'] = $row->perm_stat;
206  $this->trustees[$row->trustee_id]['perm_obj'] = $row->perm_obj;
207  $this->trustees[$row->trustee_id]['perm_coupons'] = $row->perm_coupons;
208  }
209  }
210 
211  // STATIC
212  function _deleteTrusteesOfVendor($a_vendor_id)
213  {
214  global $ilDB;
215 
216  $statement = $ilDB->manipulateF('
217  DELETE FROM payment_trustees
218  WHERE vendor_id = %s',
219  array('integer'), array($a_vendor_id));
220 
221  return true;
222  }
223 
224  function _hasStatisticPermission($a_trustee)
225  {
226  global $ilDB;
227 
228  $res = $ilDB->queryf('
229  SELECT * FROM payment_trustees
230  WHERE trustee_id = %s',
231  array('integer'), array($a_trustee));
232 
233  while($row = $ilDB->fetchObject($res))
234  {
235  if((bool) $row->perm_stat)
236  {
237  return true;
238  }
239  }
240  return false;
241  }
242 
243  function _hasObjectPermission($a_trustee)
244  {
245  global $ilDB;
246 
247  $res = $ilDB->queryf('
248  SELECT * FROM payment_trustees
249  WHERE trustee_id = %s',
250  array('integer'),
251  array($a_trustee));
252 
253  while($row = $ilDB->fetchObject($res))
254  {
255  if((bool) $row->perm_obj)
256  {
257  return true;
258  }
259  }
260  return false;
261  }
262 
263  function _hasCouponsPermission($a_trustee)
264  {
265  global $ilDB;
266 
267  $res = $ilDB->queryf('
268  SELECT * FROM payment_trustees
269  WHERE trustee_id = %s',
270  array('integer'),
271  array($a_trustee));
272 
273  while($row = $ilDB->fetchObject($res))
274  {
275  if((bool) $row->perm_coupons)
276  {
277  return true;
278  }
279  }
280  return false;
281  }
282 
283  function _hasStatisticPermissionByVendor($a_trustee,$a_vendor)
284  {
285  global $ilDB;
286 
287  $res = $ilDB->queryf('
288  SELECT * FROM payment_trustees
289  WHERE trustee_id = %s
290  AND vendor_id = %s
291  AND perm_stat = %s',
292  array('integer', 'integer', 'integer' ),
293  array($a_trustee, $a_vendor, '1'));
294 
295  return $res->numRows() ? true : false;
296  }
297 
298  function _hasObjectPermissionByVendor($a_trustee,$a_vendor)
299  {
300  global $ilDB;
301 
302  $res = $ilDB->queryf('
303  SELECT * FROM payment_trustees
304  WHERE trustee_id = %s
305  AND vendor_id = %s
306  AND perm_obj = %s',
307  array('integer', 'integer', 'integer' ),
308  array($a_trustee, $a_vendor, '1'));
309 
310  return $res->numRows() ? true : false;
311  }
312 
313  function _hasCouponsPermissionByVendor($a_trustee,$a_vendor)
314  {
315  global $ilDB;
316 
317  $res = $ilDB->queryf('
318  SELECT * FROM payment_trustees
319  WHERE trustee_id = %s
320  AND vendor_id = %s
321  AND perm_coupons = %s',
322  array('integer', 'integer', 'integer' ),
323  array($a_trustee, $a_vendor, '1'));
324 
325  return $res->numRows() ? true : false;
326  }
327 
328  function _hasAccess($a_usr_id)
329  {
330  return ilPaymentTrustees::_hasStatisticPermission($a_usr_id) or
333  }
334 
335  function _getVendorsForObjects($a_usr_id)
336  {
337  global $ilDB;
338 
339  $res = $ilDB->queryf('
340  SELECT vendor_id FROM payment_trustees
341  WHERE trustee_id = %s
342  AND perm_obj = %s ',
343  array('integer', 'integer'),
344  array($a_usr_id, '1'));
345 
346  while($row = $ilDB->fetchObject($res))
347  {
348  $vendors[] = $row->vendor_id;
349  }
350 
351  return $vendors ? $vendors : array();
352  }
353 
355  {
356  global $ilDB;
357 
358  $res = $ilDB->queryf('
359  SELECT vendor_id FROM payment_trustees
360  WHERE trustee_id = %s
361  AND perm_coupons = %s ',
362  array('integer', 'integer'),
363  array($a_usr_id, '1'));
364 
365  while($row = $ilDB->fetchObject($res))
366  {
367  $vendors[] = $row->vendor_id;
368  }
369 
370  return $vendors ? $vendors : array();
371  }
372 
374  {
375  global $ilDB;
376 
377  $res = $ilDB->queryf('
378  SELECT trustee_id FROM payment_trustees
379  WHERE vendor_id = %s
380  AND perm_coupons = %s ',
381  array('integer', 'integer'), array($a_usr_id, '1'));
382 
383  while($row = $ilDB->fetchObject($res))
384  {
385  $trustees[] = $row->trustee_id;
386  }
387 
388  return $trustees ? $trustees : array();
389  }
390 
391 } // END class.ilPaymentTrustees
392 ?>