Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | */ |
33 | class CRM_Contribute_BAO_ManagePremiums extends CRM_Contribute_DAO_Product { | |
34 | ||
35 | /** | |
fe482240 | 36 | * Static holder for the default LT. |
6a488035 TO |
37 | */ |
38 | static $_defaultContributionType = NULL; | |
39 | ||
40 | /** | |
fe482240 | 41 | * Class constructor. |
6a488035 | 42 | */ |
00be9182 | 43 | public function __construct() { |
6a488035 TO |
44 | parent::__construct(); |
45 | } | |
46 | ||
47 | /** | |
fe482240 | 48 | * Fetch object based on array of properties. |
6a488035 | 49 | * |
014c4014 TO |
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. | |
6a488035 | 54 | * |
16b10e64 | 55 | * @return CRM_Contribute_BAO_ManagePremium |
6a488035 | 56 | */ |
00be9182 | 57 | public static function retrieve(&$params, &$defaults) { |
6a488035 TO |
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); | |
63 | return $premium; | |
64 | } | |
65 | return NULL; | |
66 | } | |
67 | ||
68 | /** | |
fe482240 | 69 | * Update the is_active flag in the db. |
6a488035 | 70 | * |
014c4014 TO |
71 | * @param int $id |
72 | * Id of the database record. | |
73 | * @param bool $is_active | |
74 | * Value we want to set the is_active field. | |
6a488035 | 75 | * |
a6c01b45 | 76 | * @return Object |
b44e3f84 | 77 | * DAO object on success, null otherwise |
6a488035 | 78 | */ |
00be9182 | 79 | public static function setIsActive($id, $is_active) { |
6a488035 TO |
80 | if (!$is_active) { |
81 | $dao = new CRM_Contribute_DAO_PremiumsProduct(); | |
82 | $dao->product_id = $id; | |
83 | $dao->delete(); | |
84 | } | |
85 | return CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Product', $id, 'is_active', $is_active); | |
86 | } | |
87 | ||
88 | /** | |
fe482240 | 89 | * add the financial types. |
6a488035 | 90 | * |
014c4014 TO |
91 | * @param array $params |
92 | * Reference array contains the values submitted by the form. | |
93 | * @param array $ids | |
94 | * Reference array contains the id. | |
6a488035 | 95 | * |
6a488035 TO |
96 | * |
97 | * @return object | |
98 | */ | |
00be9182 | 99 | public static function add(&$params, &$ids) { |
ffc4d2d0 FG |
100 | // CRM-14283 - strip protocol and domain from image URLs |
101 | $image_type = array('image', 'thumbnail'); | |
102 | foreach ($image_type as $key) { | |
f24afa16 | 103 | if (isset($params[$key]) && $params[$key]) { |
ffc4d2d0 FG |
104 | $parsedURL = explode('/', $params[$key]); |
105 | $pathComponents = array_slice($parsedURL, 3); | |
106 | $params[$key] = '/' . implode('/', $pathComponents); | |
107 | } | |
108 | } | |
6a488035 TO |
109 | |
110 | $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); | |
111 | $params['is_deductible'] = CRM_Utils_Array::value('is_deductible', $params, FALSE); | |
112 | ||
113 | // action is taken depending upon the mode | |
114 | $premium = new CRM_Contribute_DAO_Product(); | |
115 | $premium->copyValues($params); | |
116 | ||
117 | $premium->id = CRM_Utils_Array::value('premium', $ids); | |
118 | ||
119 | // set currency for CRM-1496 | |
120 | if (!isset($premium->currency)) { | |
121 | $config = CRM_Core_Config::singleton(); | |
122 | $premium->currency = $config->defaultCurrency; | |
123 | } | |
124 | ||
125 | $premium->save(); | |
126 | return $premium; | |
127 | } | |
128 | ||
129 | /** | |
fe482240 | 130 | * Delete premium Types. |
6a488035 TO |
131 | * |
132 | * @param int $productID | |
6a488035 | 133 | */ |
00be9182 | 134 | public static function del($productID) { |
6a488035 TO |
135 | //check dependencies |
136 | $premiumsProduct = new CRM_Contribute_DAO_PremiumsProduct(); | |
137 | $premiumsProduct->product_id = $productID; | |
138 | if ($premiumsProduct->find(TRUE)) { | |
139 | $session = CRM_Core_Session::singleton(); | |
140 | $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'); | |
141 | CRM_Core_Session::setStatus($message); | |
142 | return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/contribute/managePremiums', 'reset=1&action=browse')); | |
143 | } | |
144 | ||
874c9be7 | 145 | //delete from financial Type table |
6a488035 TO |
146 | $premium = new CRM_Contribute_DAO_Product(); |
147 | $premium->id = $productID; | |
148 | $premium->delete(); | |
149 | } | |
96025800 | 150 | |
6a488035 | 151 | } |