Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | class CRM_Contribute_BAO_ManagePremiums extends CRM_Contribute_DAO_Product { | |
36 | ||
37 | /** | |
38 | * static holder for the default LT | |
39 | */ | |
40 | static $_defaultContributionType = NULL; | |
41 | ||
42 | /** | |
43 | * class constructor | |
44 | */ | |
45 | function __construct() { | |
46 | parent::__construct(); | |
47 | } | |
48 | ||
49 | /** | |
50 | * Takes a bunch of params that are needed to match certain criteria and | |
51 | * retrieves the relevant objects. Typically the valid params are only | |
52 | * contact_id. We'll tweak this function to be more full featured over a period | |
53 | * of time. This is the inverse function of create. It also stores all the retrieved | |
54 | * values in the default array | |
55 | * | |
56 | * @param array $params (reference ) an assoc array of name/value pairs | |
57 | * @param array $defaults (reference ) an assoc array to hold the flattened values | |
58 | * | |
59 | * @return object CRM_Contribute_BAO_ManagePremium object | |
60 | * @access public | |
61 | * @static | |
62 | */ | |
63 | static function retrieve(&$params, &$defaults) { | |
64 | $premium = new CRM_Contribute_DAO_Product(); | |
65 | $premium->copyValues($params); | |
66 | if ($premium->find(TRUE)) { | |
67 | $premium->product_name = $premium->name; | |
68 | CRM_Core_DAO::storeValues($premium, $defaults); | |
69 | return $premium; | |
70 | } | |
71 | return NULL; | |
72 | } | |
73 | ||
74 | /** | |
75 | * update the is_active flag in the db | |
76 | * | |
77 | * @param int $id id of the database record | |
78 | * @param boolean $is_active value we want to set the is_active field | |
79 | * | |
80 | * @return Object DAO object on sucess, null otherwise | |
81 | * @static | |
82 | */ | |
83 | static function setIsActive($id, $is_active) { | |
84 | if (!$is_active) { | |
85 | $dao = new CRM_Contribute_DAO_PremiumsProduct(); | |
86 | $dao->product_id = $id; | |
87 | $dao->delete(); | |
88 | } | |
89 | return CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Product', $id, 'is_active', $is_active); | |
90 | } | |
91 | ||
92 | /** | |
93 | * function to add the financial types | |
94 | * | |
95 | * @param array $params reference array contains the values submitted by the form | |
96 | * @param array $ids reference array contains the id | |
97 | * | |
98 | * @access public | |
99 | * @static | |
100 | * | |
101 | * @return object | |
102 | */ | |
103 | static function add(&$params, &$ids) { | |
104 | ||
105 | $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); | |
106 | $params['is_deductible'] = CRM_Utils_Array::value('is_deductible', $params, FALSE); | |
107 | ||
108 | // action is taken depending upon the mode | |
109 | $premium = new CRM_Contribute_DAO_Product(); | |
110 | $premium->copyValues($params); | |
111 | ||
112 | $premium->id = CRM_Utils_Array::value('premium', $ids); | |
113 | ||
114 | // set currency for CRM-1496 | |
115 | if (!isset($premium->currency)) { | |
116 | $config = CRM_Core_Config::singleton(); | |
117 | $premium->currency = $config->defaultCurrency; | |
118 | } | |
119 | ||
120 | $premium->save(); | |
121 | return $premium; | |
122 | } | |
123 | ||
124 | /** | |
125 | * Function to delete premium Types | |
126 | * | |
127 | * @param int $productID | |
128 | * @static | |
129 | */ | |
130 | ||
131 | static function del($productID) { | |
132 | //check dependencies | |
133 | $premiumsProduct = new CRM_Contribute_DAO_PremiumsProduct(); | |
134 | $premiumsProduct->product_id = $productID; | |
135 | if ($premiumsProduct->find(TRUE)) { | |
136 | $session = CRM_Core_Session::singleton(); | |
137 | $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'); | |
138 | CRM_Core_Session::setStatus($message); | |
139 | return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/contribute/managePremiums', 'reset=1&action=browse')); | |
140 | } | |
141 | ||
142 | //delete from financial Type table | |
143 | $premium = new CRM_Contribute_DAO_Product(); | |
144 | $premium->id = $productID; | |
145 | $premium->delete(); | |
146 | } | |
147 | } | |
148 |