ILIAS  Release_4_4_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 /* 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 
22  public $perm_stat = null;
23  public $perm_obj = null;
24  public $perm_coupons = null;
25 
26  public $trustee_id = 0;
27 
32  public function __construct($user_obj)
33  {
34  global $ilDB;
35 
36  $this->db = $ilDB;
37  $this->user_obj = $user_obj;
38 
39  $this->PERM_STATISTIC = 1;
40  $this->PERM_OBJECT = 2;
41 
42  $this->__read();
43  }
44 
45  public function getTrustees()
46  {
47  return $this->trustees ? $this->trustees : array();
48  }
49  public function getTrustee($a_usr_id)
50  {
51  return isset($this->trustees[$a_usr_id]) ? $this->trustees[$a_usr_id] : array();
52  }
53  public function isTrustee($a_usr_id)
54  {
55  return isset($this->trustees[$a_usr_id]);
56  }
57 
58  public function toggleStatisticPermission($a_on)
59  {
60  $this->perm_stat = (bool) $a_on;
61  }
62  public function toggleObjectPermission($a_on)
63  {
64  $this->perm_obj = (bool) $a_on;
65  }
66  public function toggleCouponsPermission($a_on)
67  {
68  $this->perm_coupons = (bool) $a_on;
69  }
70  public function setTrusteeId($a_id)
71  {
72  $this->trustee_id = $a_id;
73  }
74 
75  public function add()
76  {
77  $statement = $this->db->manipulateF('
78  INSERT INTO payment_trustees
79  ( vendor_id,
80  trustee_id,
81  perm_stat,
82  perm_coupons,
83  perm_obj
84  )
85  VALUES (%s,%s,%s,%s,%s)',
86  array('integer', 'integer', 'integer', 'integer', 'integer'),
87  array( $this->user_obj->getId(),
88  $this->__getTrusteeId(),
92  ));
93 
94 
95  $this->__read();
96 
97  return true;
98  }
99  public function modify()
100  {
101  if(!$this->__getTrusteeId())
102  {
103  die("ilPaymentTrustees::modify() no id given");
104  }
105 
106  $statement = $this->db->manipulateF('
107  UPDATE payment_trustees
108  SET trustee_id = %s,
109  perm_stat = %s,
110  perm_obj = %s,
111  perm_coupons = %s
112  WHERE vendor_id = %s
113  AND trustee_id = %s',
114  array('integer', 'integer', 'integer', 'integer', 'integer', 'integer'),
115  array( $this->__getTrusteeId(),
119  $this->user_obj->getId(),
120  $this->__getTrusteeId()
121  ));
122 
123 
124  $this->__read();
125 
126  return true;
127  }
128  public function delete()
129  {
130  if(!$this->__getTrusteeId())
131  {
132  die("ilPaymentTrustees::delete() no id given");
133  }
134 
135  $statement = $this->db->manipulateF('
136  DELETE FROM payment_trustees
137  WHERE vendor_id = %s
138  AND trustee_id = %s ',
139  array('integer', 'integer'),
140  array($this->user_obj->getId(), $this->__getTrusteeId()));
141 
142  $this->__read();
143 
144  return true;
145  }
146 
147  public function deleteAll()
148  {
149  $statement = $this->db->manipulateF('
150  DELETE FROM payment_trustees
151  WHERE vendor_id = %s',
152  array('integer'),
153  array($this->user_obj->getId()));
154 
155  $this->__read();
156 
157  return true;
158  }
159 
160 
161  // PRIVATE
162  private function __getTrusteeId()
163  {
164  return $this->trustee_id;
165  }
167  {
168  return (int) $this->perm_stat;
169  }
170  private function __getObjectPermissisonStatus()
171  {
172  return (int) $this->perm_obj;
173  }
174  private function __getCouponsPermissisonStatus()
175  {
176  return (int) $this->perm_coupons;
177  }
178  private function __read()
179  {
180 
181  $this->trustees = array();
182 
183  $res = $this->db->queryf('
184  SELECT * FROM payment_trustees
185  WHERE vendor_id = %s',
186  array('integer'),
187  array($this->user_obj->getId()));
188 
189  while($row = $this->db->fetchObject($res))
190  {
191  $this->trustees[$row->trustee_id]['trustee_id'] = $row->trustee_id;
192  $this->trustees[$row->trustee_id]['perm_stat'] = $row->perm_stat;
193  $this->trustees[$row->trustee_id]['perm_obj'] = $row->perm_obj;
194  $this->trustees[$row->trustee_id]['perm_coupons'] = $row->perm_coupons;
195  }
196  }
197 
198  // STATIC
199  public static function _deleteTrusteesOfVendor($a_vendor_id)
200  {
201  global $ilDB;
202 
203  $statement = $ilDB->manipulateF('
204  DELETE FROM payment_trustees
205  WHERE vendor_id = %s',
206  array('integer'), array($a_vendor_id));
207 
208  return true;
209  }
210 
211  public static function _hasStatisticPermission($a_trustee)
212  {
213  global $ilDB;
214 
215  $res = $ilDB->queryf('
216  SELECT * FROM payment_trustees
217  WHERE trustee_id = %s',
218  array('integer'), array($a_trustee));
219 
220  while($row = $ilDB->fetchObject($res))
221  {
222  if((bool) $row->perm_stat)
223  {
224  return true;
225  }
226  }
227  return false;
228  }
229 
230  public static function _hasObjectPermission($a_trustee)
231  {
232  global $ilDB;
233 
234  $res = $ilDB->queryf('
235  SELECT * FROM payment_trustees
236  WHERE trustee_id = %s',
237  array('integer'),
238  array($a_trustee));
239 
240  while($row = $ilDB->fetchObject($res))
241  {
242  if((bool) $row->perm_obj)
243  {
244  return true;
245  }
246  }
247  return false;
248  }
249 
250  public static function _hasCouponsPermission($a_trustee)
251  {
252  global $ilDB;
253 
254  $res = $ilDB->queryf('
255  SELECT * FROM payment_trustees
256  WHERE trustee_id = %s',
257  array('integer'),
258  array($a_trustee));
259 
260  while($row = $ilDB->fetchObject($res))
261  {
262  if((bool) $row->perm_coupons)
263  {
264  return true;
265  }
266  }
267  return false;
268  }
269 
270  public static function _hasStatisticPermissionByVendor($a_trustee,$a_vendor)
271  {
272  global $ilDB;
273 
274  $res = $ilDB->queryf('
275  SELECT * FROM payment_trustees
276  WHERE trustee_id = %s
277  AND vendor_id = %s
278  AND perm_stat = %s',
279  array('integer', 'integer', 'integer' ),
280  array($a_trustee, $a_vendor, '1'));
281 
282  return $res->numRows() ? true : false;
283  }
284 
285  public static function _hasObjectPermissionByVendor($a_trustee,$a_vendor)
286  {
287  global $ilDB;
288 
289  $res = $ilDB->queryf('
290  SELECT * FROM payment_trustees
291  WHERE trustee_id = %s
292  AND vendor_id = %s
293  AND perm_obj = %s',
294  array('integer', 'integer', 'integer' ),
295  array($a_trustee, $a_vendor, '1'));
296 
297  return $ilDB->numRows($res) ? true : false;
298  }
299 
300  public static function _hasCouponsPermissionByVendor($a_trustee,$a_vendor)
301  {
302  global $ilDB;
303 
304  $res = $ilDB->queryf('
305  SELECT * FROM payment_trustees
306  WHERE trustee_id = %s
307  AND vendor_id = %s
308  AND perm_coupons = %s',
309  array('integer', 'integer', 'integer' ),
310  array($a_trustee, $a_vendor, '1'));
311 
312  return $res->numRows() ? true : false;
313  }
314 
315  public static function _hasAccess($a_usr_id)
316  {
317  return ilPaymentTrustees::_hasStatisticPermission($a_usr_id) or
320  }
321 
322  public static function _getVendorsForObjects($a_usr_id)
323  {
324  global $ilDB;
325 
326  $res = $ilDB->queryf('
327  SELECT vendor_id FROM payment_trustees
328  WHERE trustee_id = %s
329  AND perm_obj = %s ',
330  array('integer', 'integer'),
331  array($a_usr_id, '1'));
332 
333  while($row = $ilDB->fetchObject($res))
334  {
335  $vendors[] = $row->vendor_id;
336  }
337 
338  return $vendors ? $vendors : array();
339  }
340 
341  public static function _getVendorsForStatisticsByTrusteeId($a_trustee_id)
342  {
343  global $ilDB;
344 
345  $res = $ilDB->queryf('
346  SELECT vendor_id FROM payment_trustees
347  WHERE trustee_id = %s
348  AND perm_stat = %s ',
349  array('integer', 'integer'),
350  array($a_trustee_id, '1'));
351 
352  while($row = $ilDB->fetchObject($res))
353  {
354  $vendors[] = $row->vendor_id;
355  }
356 
357  return $vendors ? $vendors : array();
358  }
359 
360  public static function _getVendorsForCouponsByTrusteeId($a_usr_id)
361  {
362  global $ilDB;
363 
364  $res = $ilDB->queryf('
365  SELECT vendor_id FROM payment_trustees
366  WHERE trustee_id = %s
367  AND perm_coupons = %s ',
368  array('integer', 'integer'),
369  array($a_usr_id, '1'));
370 
371  while($row = $ilDB->fetchObject($res))
372  {
373  $vendors[] = $row->vendor_id;
374  }
375 
376  return $vendors ? $vendors : array();
377  }
378 
379  public static function _getTrusteesForCouponsByVendorId($a_usr_id)
380  {
381  global $ilDB;
382 
383  $res = $ilDB->queryf('
384  SELECT trustee_id FROM payment_trustees
385  WHERE vendor_id = %s
386  AND perm_coupons = %s ',
387  array('integer', 'integer'), array($a_usr_id, '1'));
388 
389  while($row = $ilDB->fetchObject($res))
390  {
391  $trustees[] = $row->trustee_id;
392  }
393 
394  return $trustees ? $trustees : array();
395  }
396  public static function _getVendorIdsByTrustee($a_usr_id)
397  {
398  global $ilDB;
399 
400  $res = $ilDB->queryf('
401  SELECT vendor_id FROM payment_trustees WHERE trustee_id = %s',
402  array('integer'), array($a_usr_id));
403  while($row = $ilDB->fetchObject($res))
404  {
405  $vendors[] = $row->vendor_id;
406  }
407  return $vendors ? $vendors : array();
408  }
409 } // END class.ilPaymentTrustees
410 ?>