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_Contribute_BAO_Product
extends CRM_Contribute_DAO_Product
{
20 * Static holder for the default LT.
23 public static $_defaultContributionType = NULL;
28 public function __construct() {
29 parent
::__construct();
33 * Fetch object based on array of properties.
35 * @param array $params
36 * (reference ) an assoc array of name/value pairs.
37 * @param array $defaults
38 * (reference ) an assoc array to hold the flattened values.
40 * @return CRM_Contribute_BAO_Product
42 public static function retrieve(&$params, &$defaults) {
43 $premium = new CRM_Contribute_DAO_Product();
44 $premium->copyValues($params);
45 if ($premium->find(TRUE)) {
46 $premium->product_name
= $premium->name
;
47 CRM_Core_DAO
::storeValues($premium, $defaults);
54 * Update the is_active flag in the db.
57 * Id of the database record.
58 * @param bool $is_active
59 * Value we want to set the is_active field.
63 public static function setIsActive($id, $is_active) {
65 $dao = new CRM_Contribute_DAO_PremiumsProduct();
66 $dao->product_id
= $id;
69 return CRM_Core_DAO
::setFieldValue('CRM_Contribute_DAO_Product', $id, 'is_active', $is_active);
73 * Add a premium product to the database, and return it.
75 * @param array $params
78 * @return CRM_Contribute_DAO_Product
80 public static function create($params) {
81 $id = CRM_Utils_Array
::value('id', $params);
88 'is_deductible' => FALSE,
89 'currency' => CRM_Core_Config
::singleton()->defaultCurrency
,
91 $params = array_merge($defaultParams, $params);
94 // Modify the submitted values for 'image' and 'thumbnail' so that we use
95 // local URLs for these images when possible.
96 if (isset($params['image'])) {
97 $params['image'] = CRM_Utils_String
::simplifyURL($params['image'], TRUE);
99 if (isset($params['thumbnail'])) {
100 $params['thumbnail'] = CRM_Utils_String
::simplifyURL($params['thumbnail'], TRUE);
104 $premium = new CRM_Contribute_DAO_Product();
105 $premium->copyValues($params);
111 * Delete premium Types.
113 * @param int $productID
115 * @throws \CRM_Core_Exception
117 public static function del($productID) {
119 $premiumsProduct = new CRM_Contribute_DAO_PremiumsProduct();
120 $premiumsProduct->product_id
= $productID;
121 if ($premiumsProduct->find(TRUE)) {
122 throw new CRM_Core_Exception('Cannot delete a Premium that is linked to a Contribution page');
125 $premium = new CRM_Contribute_DAO_Product();
126 $premium->id
= $productID;