3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Core_BAO_Discount
extends CRM_Core_DAO_Discount
{
20 * Delete the discount.
22 * @param int $entityId
23 * @param string $entityTable
27 public static function del($entityId, $entityTable) {
28 // delete all discount records with the selected discounted id
29 $discount = new CRM_Core_DAO_Discount();
30 $discount->entity_id
= $entityId;
31 $discount->entity_table
= $entityTable;
32 if ($discount->delete()) {
40 * The function extracts all the params it needs to create a
41 * discount object. the params array contains additional unused name/value
44 * @param array $params
45 * (reference) an assoc array of name/value pairs.
48 * CRM_Core_DAO_Discount object on success, otherwise null
50 public static function add(&$params) {
51 $discount = new CRM_Core_DAO_Discount();
52 $discount->copyValues($params);
58 * Determine whether the given table/id
59 * has discount associated with it
61 * @param int $entityId
62 * Entity id to be searched.
63 * @param string $entityTable
64 * Entity table to be searched.
67 * option group Ids associated with discount
69 public static function getOptionGroup($entityId, $entityTable) {
71 $dao = new CRM_Core_DAO_Discount();
72 $dao->entity_id
= $entityId;
73 $dao->entity_table
= $entityTable;
75 while ($dao->fetch()) {
76 $optionGroupIDs[$dao->id
] = $dao->price_set_id
;
78 return $optionGroupIDs;
82 * Determine in which discount set the registration date falls.
84 * @param int $entityID
85 * Entity id to be searched.
86 * @param string $entityTable
87 * Entity table to be searched.
90 * $dao->id discount id of the set which matches
92 * @throws CRM_Core_Exception
94 public static function findSet($entityID, $entityTable) {
95 if (empty($entityID) ||
empty($entityTable)) {
96 // adding this here, to trap errors if values are not sent
97 throw new CRM_Core_Exception('Invalid parameters passed to findSet function');
101 $dao = new CRM_Core_DAO_Discount();
102 $dao->entity_id
= $entityID;
103 $dao->entity_table
= $entityTable;
106 while ($dao->fetch()) {
107 $endDate = $dao->end_date
;
108 // if end date is not we consider current date as end date
110 $endDate = date('Ymd');
112 $falls = CRM_Utils_Date
::getRange($dao->start_date
, $endDate);
113 if ($falls == TRUE) {