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
19 class CRM_Core_BAO_Discount
extends CRM_Core_DAO_Discount
{
24 public function __construct() {
25 parent
::__construct();
29 * Delete the discount.
31 * @param int $entityId
32 * @param string $entityTable
36 public static function del($entityId, $entityTable) {
37 // delete all discount records with the selected discounted id
38 $discount = new CRM_Core_DAO_Discount();
39 $discount->entity_id
= $entityId;
40 $discount->entity_table
= $entityTable;
41 if ($discount->delete()) {
49 * The function extracts all the params it needs to create a
50 * discount object. the params array contains additional unused name/value
53 * @param array $params
54 * (reference) an assoc array of name/value pairs.
57 * CRM_Core_DAO_Discount object on success, otherwise null
59 public static function add(&$params) {
60 $discount = new CRM_Core_DAO_Discount();
61 $discount->copyValues($params);
67 * Determine whether the given table/id
68 * has discount associated with it
70 * @param int $entityId
71 * Entity id to be searched.
72 * @param string $entityTable
73 * Entity table to be searched.
76 * option group Ids associated with discount
78 public static function getOptionGroup($entityId, $entityTable) {
80 $dao = new CRM_Core_DAO_Discount();
81 $dao->entity_id
= $entityId;
82 $dao->entity_table
= $entityTable;
84 while ($dao->fetch()) {
85 $optionGroupIDs[$dao->id
] = $dao->price_set_id
;
87 return $optionGroupIDs;
91 * Determine in which discount set the registration date falls.
93 * @param int $entityID
94 * Entity id to be searched.
95 * @param string $entityTable
96 * Entity table to be searched.
99 * $dao->id discount id of the set which matches
102 public static function findSet($entityID, $entityTable) {
103 if (empty($entityID) ||
empty($entityTable)) {
104 // adding this here, to trap errors if values are not sent
105 CRM_Core_Error
::fatal();
109 $dao = new CRM_Core_DAO_Discount();
110 $dao->entity_id
= $entityID;
111 $dao->entity_table
= $entityTable;
114 while ($dao->fetch()) {
115 $endDate = $dao->end_date
;
116 // if end date is not we consider current date as end date
118 $endDate = date('Ymd');
120 $falls = CRM_Utils_Date
::getRange($dao->start_date
, $endDate);
121 if ($falls == TRUE) {