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
{
22 public function __construct() {
23 parent
::__construct();
27 * Delete the discount.
29 * @param int $entityId
30 * @param string $entityTable
34 public static function del($entityId, $entityTable) {
35 // delete all discount records with the selected discounted id
36 $discount = new CRM_Core_DAO_Discount();
37 $discount->entity_id
= $entityId;
38 $discount->entity_table
= $entityTable;
39 if ($discount->delete()) {
47 * The function extracts all the params it needs to create a
48 * discount object. the params array contains additional unused name/value
51 * @param array $params
52 * (reference) an assoc array of name/value pairs.
55 * CRM_Core_DAO_Discount object on success, otherwise null
57 public static function add(&$params) {
58 $discount = new CRM_Core_DAO_Discount();
59 $discount->copyValues($params);
65 * Determine whether the given table/id
66 * has discount associated with it
68 * @param int $entityId
69 * Entity id to be searched.
70 * @param string $entityTable
71 * Entity table to be searched.
74 * option group Ids associated with discount
76 public static function getOptionGroup($entityId, $entityTable) {
78 $dao = new CRM_Core_DAO_Discount();
79 $dao->entity_id
= $entityId;
80 $dao->entity_table
= $entityTable;
82 while ($dao->fetch()) {
83 $optionGroupIDs[$dao->id
] = $dao->price_set_id
;
85 return $optionGroupIDs;
89 * Determine in which discount set the registration date falls.
91 * @param int $entityID
92 * Entity id to be searched.
93 * @param string $entityTable
94 * Entity table to be searched.
97 * $dao->id discount id of the set which matches
99 * @throws CRM_Core_Exception
101 public static function findSet($entityID, $entityTable) {
102 if (empty($entityID) ||
empty($entityTable)) {
103 // adding this here, to trap errors if values are not sent
104 throw new CRM_Core_Exception('Invalid parameters passed to findSet function');
108 $dao = new CRM_Core_DAO_Discount();
109 $dao->entity_id
= $entityID;
110 $dao->entity_table
= $entityTable;
113 while ($dao->fetch()) {
114 $endDate = $dao->end_date
;
115 // if end date is not we consider current date as end date
117 $endDate = date('Ymd');
119 $falls = CRM_Utils_Date
::getRange($dao->start_date
, $endDate);
120 if ($falls == TRUE) {