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