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