ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPaymentCoupons.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 include_once './Services/Payment/classes/class.ilPaymentVendors.php';
5 include_once './Services/Payment/classes/class.ilPaymentTrustees.php';
6 
15 {
16  private $db = null;
17 
18  private $user_obj = null;
19  private $vendor_view = false;
20 
21  private $coupons = array();
22  private $current_coupon = array();
23  private $codes = array();
24  private $used_codes = array();
25  private $objects = array();
26 
27  private $id = null;
28  private $coupon_user = null;
29  private $title = null;
30  private $description = null;
31  private $type = null;
32  private $value = null;
33  private $from = null;
34  private $till = null;
35  private $from_date_enabled = null;
36  private $till_date_enabled = null;
37  private $change_date = null;
38  private $uses = null;
39  private $search_title_type = null;
40  private $search_title_value = null;
41  private $search_type = null;
42  private $search_from_day = null;
43  private $search_from_month = null;
44  private $search_from_year = null;
45  private $search_till_day = null;
46  private $search_till_month = null;
47  private $search_till_year = null;
48  private $search_from_enabled = null;
49  private $search_till_enabled = null;
50 
51 
52 
53  public function ilPaymentCoupons($user_obj, $a_vendor_view = false)
54  {
55  global $ilDB;
56 
57  $this->db = $ilDB;
58  $this->vendor_view = $a_vendor_view;
59  $this->user_obj = $user_obj;
60 
61  $this->COUPON_VALID = 0;
62  $this->COUPON_OUT_OF_DATE = 1;
63  $this->COUPON_TOO_MUCH_USED = 2;
64  $this->COUPON_NOT_FOUND = 3;
65  }
66 
67  public function getCoupons()
68  {
69 
70  $this->coupons = array();
71 
72  $data = array();
73  $data_types = array();
74 
75  $query = 'SELECT * FROM payment_coupons WHERE 1 = 1 ';
76 
77  if ($_SESSION['pay_coupons']['from']['date']['d'] != '' &&
78  $_SESSION['pay_coupons']['from']['date']['m'] != '' &&
79  $_SESSION['pay_coupons']['from']['date']['y'] != '')
80  {
81 
82  $from = date('Y-m-d',mktime(0, 0, 0, $_SESSION['pay_coupons']['from']['date']['m'],
83  $_SESSION['pay_coupons']['from']['date']['d'],
84  $_SESSION['pay_coupons']['from']['date']['y']));
85 
86 
87  $query .= 'AND pc_from >= %s ';
88  $data_types[] = 'date';
89  $data[] = $from;
90  }
91  if ($_SESSION['pay_coupons']['til']['date']['d'] != '' &&
92  $_SESSION['pay_coupons']['til']['date']['m'] != '' &&
93  $_SESSION['pay_coupons']['til']['date']['y'] != '')
94  {
95  $til = date('Y-m-d',mktime(23, 59, 59, $_SESSION['pay_coupons']['til']['date']['m'],
96  $_SESSION['pay_coupons']['til']['date']['d'],
97  $_SESSION['pay_coupons']['til']['date']['y']));
98  $query .= 'AND pc_till <= %s ';
99  $data_types[] = 'date';
100  $data[] = $til;
101  }
102 
103  if ($this->getSearchTitleValue() != "")
104  {
105  if ($this->getSearchTitleType() == 0)
106  {
107  $query .= " AND pc_title LIKE %s ";
108  array_push($data, $this->getSearchTitleValue().'%');
109  array_push($data_types, 'text');
110  }
111  else if ($this->getSearchTitleType() == 1)
112  {
113  $query .= " AND pc_title LIKE %s ";
114  array_push($data, '%'.$this->getSearchTitleValue());
115  array_push($data_types,'text');
116  }
117  }
118 
119  if ($this->getSearchType() != "")
120  {
121  $query .= ' AND pc_type = %s';
122  array_push($data, $this->getSearchType());
123  array_push($data_types, 'text');
124  }
125 
126  $vendors = $this->getVendorIds();
127  if (is_array($vendors) &&
128  count($vendors) > 0)
129  {
130  $in = 'usr_id IN (';
131  $counter = 0;
132  foreach($vendors as $vendor)
133  {
134  array_push($data, $vendor);
135  array_push($data_types, 'integer');
136 
137  if($counter > 0) $in .= ',';
138  $in .= '%s';
139  ++$counter;
140  }
141  $in .= ')';
142 
143  $query .= ' AND '.$in;
144  }
145 
146 
147  $cnt_data = count($data);
148  $cnt_data_types = count($data_types);
149 
150  if($cnt_data == 0 && $cnt_data_types == 0)
151  {
152  $res = $this->db->query($query);
153  }
154  else
155  {
156  $res= $this->db->queryf($query, $data_types, $data);
157  }
158 
159  while($row = $this->db->fetchObject($res))
160  {
161  $this->coupons[$row->pc_pk]['pc_pk'] = $row->pc_pk;
162  $this->coupons[$row->pc_pk]['usr_id'] = $row->usr_id;
163  $this->coupons[$row->pc_pk]['pc_title'] = $row->pc_title;
164  $this->coupons[$row->pc_pk]['pc_description'] = $row->pc_description;
165  $this->coupons[$row->pc_pk]['pc_type'] = $row->pc_type;
166  $this->coupons[$row->pc_pk]['pc_value'] = $row->pc_value;
167  $this->coupons[$row->pc_pk]['pc_from'] = $row->pc_from;
168  $this->coupons[$row->pc_pk]['pc_till'] = $row->pc_till;
169  $this->coupons[$row->pc_pk]['pc_from_enabled'] = $row->pc_from_enabled;
170  $this->coupons[$row->pc_pk]['pc_till_enabled'] = $row->pc_till_enabled;
171  $this->coupons[$row->pc_pk]['pc_uses'] = $row->pc_uses;
172  $this->coupons[$row->pc_pk]['pc_last_change_usr_id'] = $row->pc_last_change_usr_id;
173  $this->coupons[$row->pc_pk]['pc_last_changed'] = $row->pc_last_changed;
174  $this->coupons[$row->pc_pk]['number_of_codes'] = count($this->getCodesByCouponId($row->pc_pk));
175  $this->coupons[$row->pc_pk]['usage_of_codes'] = count($this->getUsedCouponsByCouponId($row->pc_pk));
176  $this->coupons[$row->pc_pk]['objects'] = $this->getObjectsByCouponId($row->pc_pk);
177  }
178 
179  return $this->coupons;
180  }
181 
182  private function getVendorIds()
183  {
184  $vendors[] = $this->user_obj->getId();
185  if (ilPaymentVendors::_isVendor($this->user_obj->getId()))
186  {
187  $ptObj = new ilPaymentTrustees($this->user_obj);
188 
189  if ($trustees = $ptObj->getTrustees())
190  {
191  foreach ($trustees as $trustee)
192  {
193  if ((bool) $trustee["perm_coupons"])
194  {
195  $vendors[] = $trustee["trustee_id"];
196  }
197  }
198  }
199  }
200  if ($vend = ilPaymentTrustees::_getVendorsForCouponsByTrusteeId($this->user_obj->getId()))
201  {
202  foreach ($vend as $v)
203  {
204  $vendors[] = $v;
206  {
207  foreach ($trustees as $t)
208  {
209  $vendors[] = $t;
210  }
211  }
212  }
213  }
214 
215  return $vendors ? $vendors : array();
216  }
217 
218  // Object Data
219  public function setId($a_id)
220  {
221  return $this->id = $a_id;
222  }
223  public function getId()
224  {
225  return $this->id;
226  }
227  public function setCouponUser($a_user_id)
228  {
229  $this->coupon_user = $a_user_id;
230  }
231  public function getCouponUser()
232  {
233  return $this->coupon_user;
234  }
235  public function setTitle($a_title)
236  {
237  $this->title = $a_title;
238  }
239  public function getTitle()
240  {
241  return $this->title;
242  }
243  public function setDescription($a_description)
244  {
245  $this->description = $a_description;
246  }
247  public function getDescription()
248  {
249  return $this->description;
250  }
251  public function setType($a_type)
252  {
253  $this->type = $a_type;
254  }
255  public function getType()
256  {
257  return $this->type;
258  }
259  public function setValue($a_value)
260  {
261  $this->value = $a_value;
262  }
263  public function getValue()
264  {
265  return $this->value;
266  }
267  public function setFromDate($a_from)
268  {
269  $this->from = $a_from;
270  }
271  public function getFromDate()
272  {
273  return $this->from;
274  }
275  public function setTillDate($a_till)
276  {
277  $this->till = $a_till;
278  }
279  public function getTillDate()
280  {
281  return $this->till;
282  }
283  public function setFromDateEnabled($a_from_date_enabled = 0)
284  {
285  if($a_from_date_enabled == NULL) $a_from_date_enabled = 0;
286  $this->from_date_enabled = $a_from_date_enabled;
287  }
288  public function getFromDateEnabled()
289  {
291  }
292  public function setTillDateEnabled($a_till_date_enabled = 0)
293  {
294  if($a_till_date_enabled == NULL) $a_till_date_enabled = 0;
295  $this->till_date_enabled = $a_till_date_enabled;
296  }
297  public function getTillDateEnabled()
298  {
300  }
301  public function setChangeDate($a_date)
302  {
303  if($a_date == '0000-00-00 00:00:00')
304  $this->change_date = NULLL;
305  else
306  $this->change_date = $a_date;
307  }
308  public function getChangeDate()
309  {
310  return $this->change_date;
311  }
312  public function setUses($a_uses)
313  {
314  $this->uses = $a_uses;
315  }
316  public function getUses()
317  {
318  return $this->uses;
319  }
320 
321  // Search Data
322  public function setSearchTitleType($a_title_type)
323  {
324  $this->search_title_type = $a_title_type;
325  }
326  public function getSearchTitleType()
327  {
329  }
330  public function setSearchTitleValue($a_title_value)
331  {
332  $this->search_title_value = $a_title_value;
333  }
334  public function getSearchTitleValue()
335  {
337  }
338  public function setSearchType($a_type)
339  {
340  $this->search_type = $a_type;
341  }
342  public function getSearchType()
343  {
344  return $this->search_type;
345  }
346  public function setSearchFromDay($a_day)
347  {
348  $this->search_from_day = $a_day;
349  }
350  public function getSearchFromDay()
351  {
352  return $this->search_from_day;
353  }
354  public function setSearchFromMonth($a_month)
355  {
356 
357  $this->search_from_month = $a_month;
358  }
359  public function getSearchFromMonth()
360  {
362  }
363  public function setSearchFromYear($a_year)
364  {
365  $this->search_from_year = $a_year;
366  }
367  public function getSearchFromYear()
368  {
370  }
371  public function setSearchTillDay($a_day)
372  {
373  $this->search_till_day = $a_day;
374  }
375  public function getSearchTillDay()
376  {
377  return $this->search_till_day;
378  }
379  public function setSearchTillMonth($a_month)
380  {
381  $this->search_till_month = $a_month;
382  }
383  public function getSearchTillMonth()
384  {
386  }
387  public function setSearchTillYear($a_year)
388  {
389  $this->search_till_year = $a_year;
390  }
391  public function getSearchTillYear()
392  {
394  }
395  public function setSearchFromDateEnabled($a_from_enabled)
396  {
397  $this->search_from_enabled = $a_from_enabled;
398  }
399  public function getSearchFromDateEnabled()
400  {
402  }
403  public function setSearchTillDateEnabled($a_till_enabled)
404  {
405  $this->search_till_enabled = $a_till_enabled;
406  }
407  public function getSearchTillDateEnabled()
408  {
410  }
411 
412  public function setCurrentCoupon($coupon = array())
413  {
414  $this->current_coupon = $coupon;
415  }
416  public function getCurrentCoupon()
417  {
418  return $this->current_coupon;
419  }
420 
421  public function add()
422  {
423  $next_id = $this->db->nextId('payment_coupons');
424 
425  $statement = $this->db->manipulateF('
426  INSERT INTO payment_coupons
427  ( pc_pk,
428  usr_id,
429  pc_title,
430  pc_description,
431  pc_type,
432  pc_value,
433  pc_from,
434  pc_till,
435  pc_from_enabled,
436  pc_till_enabled,
437  pc_uses,
438  pc_last_change_usr_id,
439  pc_last_changed
440  )
441  VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',
442  array( 'integer',
443  'integer',
444  'text',
445  'text',
446  'text',
447  'float',
448  'date',
449  'date',
450  'integer',
451  'integer',
452  'integer',
453  'integer',
454  'timestamp'),
455  array( $next_id,
456  $this->getCouponUser(),
457  $this->getTitle(),
458  $this->getDescription(),
459  $this->getType(),
460  $this->getValue(),
461  $this->getFromDate(),
462  $this->getTillDate(),
463  $this->getFromDateEnabled(),
464  $this->getTillDateEnabled(),
465  $this->getUses(),
466  $this->getCouponUser(),
467  $this->getChangeDate() )
468  );
469 
470  return $next_id;
471  }
472 
473  public function update()
474  {
475  if ($this->getId())
476  {
477  $statement = $this->db->manipulateF('
478  UPDATE payment_coupons
479  SET pc_title = %s,
480  pc_description = %s,
481  pc_type = %s,
482  pc_value = %s,
483  pc_from = %s,
484  pc_till = %s,
485  pc_from_enabled = %s,
486  pc_till_enabled = %s,
487  pc_uses = %s,
488  pc_last_change_usr_id = %s,
489  pc_last_changed = %s
490  WHERE pc_pk = %s',
491  array( 'text',
492  'text',
493  'text',
494  'float',
495  'date',
496  'date',
497  'integer',
498  'integer',
499  'integer',
500  'integer',
501  'timestamp',
502  'integer'),
503  array( $this->getTitle(),
504  $this->getDescription(),
505  $this->getType(),
506  $this->getValue(),
507  $this->getFromDate(),
508  $this->getTillDate(),
509  $this->getFromDateEnabled(),
510  $this->getTillDateEnabled(),
511  $this->getUses(),
512  $this->getCouponUser(),
513  $this->getChangeDate(),
514  $this->getId()
515  ));
516 
517  return true;
518  }
519  return false;
520  }
521 
522  public function delete()
523  {
524  if ($this->getId())
525  {
526  $statement = $this->db->manipulateF('
527  DELETE FROM payment_coupons WHERE pc_pk = %s',
528  array('integer'),
529  array($this->getId()));
530 
531  return true;
532  }
533  return false;
534  }
535 
536  public function getCouponById($a_coupon_id)
537  {
538  $res = $this->db->queryf('
539  SELECT * FROM payment_coupons
540  WHERE pc_pk = %s', array('integer'), array($a_coupon_id));
541 
542  while($row = $this->db->fetchObject($res))
543  {
544  $this->setId($row->pc_pk);
545  $this->setCouponUser($row->usr_id);
546  $this->setTitle($row->pc_title);
547  $this->setDescription($row->pc_description);
548  $this->setType($row->pc_type);
549  $this->setValue($row->pc_value);
550  $this->setFromDate($row->pc_from);
551  $this->setTillDate($row->pc_till);
552  $this->setFromDateEnabled($row->pc_from_enabled);
553  $this->setTillDateEnabled($row->pc_till_enabled);
554  $this->setUses($row->pc_uses);
555  $this->setChangeDate(date("Y-m-h H:i:s"));
556  }
557  }
558 
559  public function getCouponBonus($a_item_price)
560  {
561  if (is_array($coupon = $this->getCurrentCoupon()))
562  {
563  switch ($coupon["pc_type"])
564  {
565  case "fix":
566  return (float) $coupon["pc_value"];
567  case "percent":
568  return (float) $a_item_price * ($coupon["pc_value"] / 100);
569  }
570  }
571 
572  return 0;
573  }
574 
575  public function getObjectsByCouponId($a_coupon_id)
576  {
577  $this->objects = array();
578 
579  $res = $this->db->queryf('
580  SELECT * FROM payment_coupons_obj
581  WHERE pco_pc_fk = %s',
582  array('integer'),
583  array($a_coupon_id));
584 
585  while($row = $this->db->fetchObject($res))
586  {
587  $this->objects[] = $row->ref_id;
588  }
589 
590  return $this->objects;
591  }
592 
593  public function getCodesByCouponId($a_coupon_id)
594  {
595  $this->codes = array();
596 
597  $res = $this->db->queryf('
598  SELECT payment_coupons_codes.*, COUNT(pct_pcc_fk) pcc_used, pcc_pk
599  FROM payment_coupons_codes
600  LEFT JOIN payment_coupons_track ON pct_pcc_fk = pcc_pk
601  WHERE pcc_pc_fk = %s
602  GROUP BY pcc_pk, payment_coupons_codes.pcc_pc_fk ,pcc_code',
603  array('integer'),
604  array($a_coupon_id));
605 
606  while($row = $this->db->fetchObject($res))
607  {
608  $this->codes[$row->pcc_pk]['pcc_pk'] = $row->pcc_pk;
609  $this->codes[$row->pcc_pk]['pcc_code'] = $row->pcc_code;
610  $this->codes[$row->pcc_pk]['pcc_used'] = $row->pcc_used;
611  }
612 
613  return $this->codes;
614  }
615 
616  public function getUsedCouponsByCouponId($a_coupon_id)
617  {
618  $this->used_codes = array();
619 
620  $res = $this->db->queryf('
621  SELECT * FROM payment_coupons_track
622  INNER JOIN payment_coupons_codes ON pcc_pk = pct_pcc_fk
623  WHERE pcc_pc_fk = %s',
624  array('integer'),
625  array($a_coupon_id));
626 
627  while($row = $this->db->fetchObject($res))
628  {
629  $this->used_codes[$row->pct_pk]['pct_pk'] = $row->pct_pk;
630  $this->used_codes[$row->pct_pk]['pcc_code'] = $row->pcc_code;
631  $this->used_codes[$row->pct_pk]['usr_id'] = $row->usr_id;
632  $this->used_codes[$row->pct_pk]['pct_date'] = $row->pct_date;
633  $this->used_codes[$row->pct_pk]['pct_ps_fk'] = $row->pct_ps_fk;
634  }
635 
636  return $this->used_codes;
637  }
638 
639  public function getCouponByCode($a_coupon_code)
640  {
641  $res = $this->db->queryf('
642  SELECT * FROM payment_coupons_codes
643  INNER JOIN payment_coupons ON pc_pk = pcc_pc_fk
644  WHERE pcc_code = %s',
645  array('text'),
646  array($a_coupon_code));
647 
648 
649  if (is_object($row = $this->db->fetchObject($res)))
650  {
651  $coupon['pc_pk'] = $row->pc_pk;
652  $coupon['pc_title'] = $row->pc_title;
653  $coupon['pc_description'] = $row->pc_description;
654  $coupon['pc_type'] = $row->pc_type;
655  $coupon['pc_value'] = $row->pc_value;
656  $coupon['pc_type'] = $row->pc_type;
657  $coupon['pc_from'] = $row->pc_from;
658  $coupon['pc_till'] = $row->pc_till;
659  $coupon['pc_uses'] = $row->pc_uses;
660  $coupon['pcc_pk'] = $row->pcc_pk;
661  $coupon['pcc_code'] = $row->pcc_code;
662  $coupon['objects'] = $this->getObjectsByCouponId($row->pc_pk);
663  }
664 
665  $this->setId($coupon['pc_pk']);
666  $this->setCurrentCoupon($coupon);
667 
668  return $coupon ? $coupon : array();
669  }
670 
671  public function checkCouponValidity()
672  {
673  $coupon = $this->getCurrentCoupon();
674 
675  if (empty($coupon)) return $this->COUPON_NOT_FOUND;
676 
677  $current_date = date("Y-m-d");
678  if ($coupon["pc_from"] != "0000-00-00" && $coupon["pc_from_enabled"] == '1' &&
679  $coupon["pc_till"] != "0000-00-00" && $coupon["pc_till_enabled"] == '1'
680  )
681  {
682  if (! ($coupon["pc_from"] <= $current_date && $current_date <= $coupon["pc_till"]))
683  {
684  return $this->COUPON_OUT_OF_DATE;
685  }
686  }
687  else if ($coupon["pc_from"] != "0000-00-00" && $coupon["pc_from_enabled"] == '1')
688  {
689  if ($coupon["pc_from"] > $current_date)
690  {
691  return $this->COUPON_OUT_OF_DATE;
692  }
693  }
694  else if ($coupon["pc_till"] != "0000-00-00" && $coupon["pc_till_enabled"] == '1')
695  {
696  if ($coupon["pc_till"] < $current_date)
697  {
698  return $this->COUPON_OUT_OF_DATE;
699  }
700  }
701 
702  if (is_numeric($coupon["pc_uses"]) && $coupon["pc_uses"] > 0)
703  {
704  $res = $this->db->queryf('
705  SELECT COUNT(*) used_coupons
706  FROM payment_coupons_track
707  WHERE pct_pcc_fk = %s',
708  array('integer'),
709  array($coupon['pcc_pk']));
710 
711  $row = $this->db->fetchObject($res);
712 
713  if ($row->used_coupons >= $coupon["pc_uses"]) return $this->COUPON_TOO_MUCH_USED;
714  }
715 
716  return $this->COUPON_VALID;
717  }
718 
719  public function deleteCode($a_code_id)
720  {
721  if ($a_code_id)
722  {
723  $statement = $this->db->manipulateF('
724  DELETE FROM payment_coupons_codes WHERE pcc_pk = %s',
725  array('integer'), array($a_code_id));
726 
727  return true;
728  }
729  return false;
730  }
731 
732  public function deleteAllCodesByCouponId($a_coupon_id)
733  {
734  if ($a_coupon_id)
735  {
736  $statement = $this->db->manipulateF('
737  DELETE FROM payment_coupons_codes WHERE pcc_pc_fk = %s',
738  array('integer'),array($a_coupon_id));
739 
740  return true;
741  }
742  return false;
743  }
744 
745  public function getCode($a_code_id)
746  {
747  $res = $this->db->queryf('
748  SELECT * FROM payment_coupons_codes
749  WHERE pcc_pk = %s',
750  array('integer'),
751  array($a_code_id));
752 
753  while($row = $this->db->fetchObject($res))
754  {
755  $code['pcc_pk'] = $row->pcc_pk;
756  $code['pcc_pc_fk'] = $row->pcc_pc_fk;
757  $code['pcc_code'] = $row->pcc_code;
758  }
759  return $code ? $code : array();
760  }
761 
762  public function addCode($a_code, $a_coupon_id)
763  {
764  if ($a_code && $a_coupon_id)
765  {
766  $next_id = $this->db->nextId('payment_coupons_codes');
767  $statement = $this->db->manipulateF('
768  INSERT INTO payment_coupons_codes
769  ( pcc_pk,
770  pcc_pc_fk,
771  pcc_code
772  )
773  VALUES (%s,%s,%s)',
774  array('integer','integer', 'text'),
775  array($next_id, $a_coupon_id, $a_code));
776 
777  return $next_id;
778  }
779  return false;
780  }
781 
782  public function addCouponForBookingId($a_booking_id)
783  {
785 
786  if ($a_booking_id && is_array($current_coupon))
787  {
788  $statement = $this->db->manipulateF('
789  INSERT INTO payment_statistic_coup
790  ( psc_ps_fk,
791  psc_pc_fk,
792  psc_pcc_fk
793  ) VALUES(%s,%s,%s)',
794  array('integer', 'integer', 'integer'),
795  array($a_booking_id, $current_coupon['pc_pk'], $current_coupon['pcc_pk']));
796  }
797  return false;
798  }
799 
800  public function addTracking()
801  {
803 
804  if (is_array($current_coupon))
805  {
806  $next_id = $this->db->nextId('payment_coupons_track');
807  $statement = $this->db->manipulateF('
808  INSERT INTO payment_coupons_track
809  ( pct_pk,
810  pct_pcc_fk ,
811  usr_id,
812  pct_date
813  )
814  VALUES (%s, %s, %s, %s)',
815  array('integer','integer', 'integer', 'timestamp'),
816  array($next_id, $current_coupon['pcc_pk'], $this->user_obj->getId(), date("Y-m-d H:i:s")));
817 
818  return $next_id;
819  }
820  return false;
821  }
822 
829  public function isObjectAssignedToCoupon($a_ref_id)
830  {
831  if ($a_ref_id && is_numeric($this->getId()))
832  {
833  $res = $this->db->queryf('
834  SELECT * FROM payment_coupons_obj
835  WHERE ref_id = %s
836  AND pco_pc_fk = %s',
837  array('integer', 'integer'),
838  array($a_ref_id, $this->getId()));
839 
840  if ($res->numRows()) return true;
841 
842  return false;
843  }
844  return false;
845  }
846 
853  public function assignObjectToCoupon($a_ref_id)
854  {
855  if ($a_ref_id && is_numeric($this->getId()))
856  {
857  $statement = $this->db->manipulateF('
858  INSERT INTO payment_coupons_obj
859  ( pco_pc_fk,
860  ref_id
861  ) VALUES(%s, %s)',
862  array('integer', 'integer'),
863  array($this->getId(), $a_ref_id));
864 
865  return true;
866  }
867  return false;
868  }
869 
876  public function unassignObjectFromCoupon($a_ref_id)
877  {
878  if ($a_ref_id && is_numeric($this->getId()))
879  {
880  $statement = $this->db->manipulateF('
881  DELETE FROM payment_coupons_obj
882  WHERE ref_id = %s
883  AND pco_pc_fk = %s',
884  array('integer', 'integer'),
885  array($a_ref_id, $this->getId()));
886 
887  return true;
888  }
889  return false;
890  }
891 }
892 ?>