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;
26 * Fetch object based on array of properties.
28 * @param array $params
29 * (reference ) an assoc array of name/value pairs.
30 * @param array $defaults
31 * (reference ) an assoc array to hold the flattened values.
33 * @return CRM_Contribute_BAO_Product
35 public static function retrieve(&$params, &$defaults) {
36 $premium = new CRM_Contribute_DAO_Product();
37 $premium->copyValues($params);
38 if ($premium->find(TRUE)) {
39 $premium->product_name
= $premium->name
;
40 CRM_Core_DAO
::storeValues($premium, $defaults);
47 * Update the is_active flag in the db.
50 * Id of the database record.
51 * @param bool $is_active
52 * Value we want to set the is_active field.
56 public static function setIsActive($id, $is_active) {
58 $dao = new CRM_Contribute_DAO_PremiumsProduct();
59 $dao->product_id
= $id;
62 return CRM_Core_DAO
::setFieldValue('CRM_Contribute_DAO_Product', $id, 'is_active', $is_active);
66 * Add a premium product to the database, and return it.
68 * @param array $params
71 * @return CRM_Contribute_DAO_Product
73 public static function create($params) {
74 $id = $params['id'] ??
NULL;
75 $op = !empty($id) ?
'edit' : 'create';
82 'is_deductible' => FALSE,
83 'currency' => CRM_Core_Config
::singleton()->defaultCurrency
,
85 $params = array_merge($defaultParams, $params);
87 CRM_Utils_Hook
::pre($op, 'Product', $id, $params);
88 // Modify the submitted values for 'image' and 'thumbnail' so that we use
89 // local URLs for these images when possible.
90 if (isset($params['image'])) {
91 $params['image'] = CRM_Utils_String
::simplifyURL($params['image'], TRUE);
93 if (isset($params['thumbnail'])) {
94 $params['thumbnail'] = CRM_Utils_String
::simplifyURL($params['thumbnail'], TRUE);
98 $premium = new CRM_Contribute_DAO_Product();
99 $premium->copyValues($params);
101 CRM_Utils_Hook
::post($op, 'Product', $id, $premium);
106 * Delete premium Types.
108 * @param int $productID
110 * @throws \CRM_Core_Exception
112 public static function del($productID) {
113 static::deleteRecord(['id' => $productID]);