3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
33 class CRM_Contribute_BAO_ManagePremiums
extends CRM_Contribute_DAO_Product
{
36 * Static holder for the default LT.
38 static $_defaultContributionType = NULL;
43 public function __construct() {
44 parent
::__construct();
48 * Fetch object based on array of properties.
50 * @param array $params
51 * (reference ) an assoc array of name/value pairs.
52 * @param array $defaults
53 * (reference ) an assoc array to hold the flattened values.
55 * @return CRM_Contribute_BAO_ManagePremium
57 public static function retrieve(&$params, &$defaults) {
58 $premium = new CRM_Contribute_DAO_Product();
59 $premium->copyValues($params);
60 if ($premium->find(TRUE)) {
61 $premium->product_name
= $premium->name
;
62 CRM_Core_DAO
::storeValues($premium, $defaults);
69 * Update the is_active flag in the db.
72 * Id of the database record.
73 * @param bool $is_active
74 * Value we want to set the is_active field.
77 * DAO object on success, null otherwise
79 public static function setIsActive($id, $is_active) {
81 $dao = new CRM_Contribute_DAO_PremiumsProduct();
82 $dao->product_id
= $id;
85 return CRM_Core_DAO
::setFieldValue('CRM_Contribute_DAO_Product', $id, 'is_active', $is_active);
89 * Add a premium product to the database, and return it.
91 * @param array $params
92 * Reference array contains the values submitted by the form.
94 * Reference array contains the id.
96 * @return CRM_Contribute_DAO_Product
98 public static function add(&$params, &$ids) {
99 $params = array_merge(array(
100 'id' => CRM_Utils_Array
::value('premium', $ids),
104 'is_deductible' => FALSE,
105 'currency' => CRM_Core_Config
::singleton()->defaultCurrency
,
108 // Modify the submitted values for 'image' and 'thumbnail' so that we use
109 // local URLs for these images when possible.
110 $params['image'] = CRM_Utils_String
::simplifyURL($params['image'], TRUE);
111 $params['thumbnail'] = CRM_Utils_String
::simplifyURL($params['thumbnail'], TRUE);
114 $premium = new CRM_Contribute_DAO_Product();
115 $premium->copyValues($params);
121 * Delete premium Types.
123 * @param int $productID
125 public static function del($productID) {
127 $premiumsProduct = new CRM_Contribute_DAO_PremiumsProduct();
128 $premiumsProduct->product_id
= $productID;
129 if ($premiumsProduct->find(TRUE)) {
130 $session = CRM_Core_Session
::singleton();
131 $message .= ts('This Premium is being linked to <a href=\'%1\'>Online Contribution page</a>. Please remove it in order to delete this Premium.', array(1 => CRM_Utils_System
::url('civicrm/admin/contribute', 'reset=1')), ts('Deletion Error'), 'error');
132 CRM_Core_Session
::setStatus($message);
133 return CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/contribute/managePremiums', 'reset=1&action=browse'));
136 //delete from financial Type table
137 $premium = new CRM_Contribute_DAO_Product();
138 $premium->id
= $productID;