Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
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 | ||
36 | /** | |
37 | * This class holds all the Pseudo constants that are specific to Contributions. This avoids | |
38 | * polluting the core class and isolates the mass mailer class | |
39 | */ | |
40 | class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant { | |
41 | ||
42 | /** | |
43 | * financial types | |
44 | * @var array | |
45 | * @static | |
46 | */ | |
47 | private static $financialType; | |
48 | ||
49 | /** | |
50 | * financial types | |
51 | * @var array | |
52 | * @static | |
53 | */ | |
54 | private static $financialTypeAccount; | |
55 | ||
56 | ||
57 | /** | |
58 | * financial types | |
59 | * @var array | |
60 | * @static | |
61 | */ | |
62 | private static $financialAccount; | |
63 | ||
64 | /** | |
65 | * contribution pages | |
66 | * @var array | |
67 | * @static | |
68 | */ | |
69 | private static $contributionPageActive = NULL; | |
70 | ||
71 | /** | |
72 | * contribution pages | |
73 | * @var array | |
74 | * @static | |
75 | */ | |
76 | private static $contributionPageAll = NULL; | |
77 | ||
78 | /** | |
79 | * payment instruments | |
80 | * | |
81 | * @var array | |
82 | * @static | |
83 | */ | |
84 | private static $paymentInstrument; | |
85 | ||
86 | /** | |
87 | * credit card | |
88 | * | |
89 | * @var array | |
90 | * @static | |
91 | */ | |
92 | private static $creditCard; | |
93 | ||
94 | /** | |
95 | * contribution status | |
96 | * | |
97 | * @var array | |
98 | * @static | |
99 | */ | |
100 | private static $contributionStatus; | |
101 | ||
102 | /** | |
103 | * Personal campaign pages | |
104 | * @var array | |
105 | * @static | |
106 | */ | |
107 | private static $pcPage; | |
108 | ||
109 | /** | |
110 | * status of personal campaign page | |
111 | * @var array | |
112 | * @static | |
113 | */ | |
114 | private static $pcpStatus; | |
115 | ||
116 | /** | |
117 | * Get all the financial types | |
118 | * | |
119 | * @access public | |
120 | * | |
121 | * @return array - array reference of all financial types if any | |
122 | * @static | |
123 | */ | |
124 | public static function &financialType($id = NULL) { | |
125 | if (!self::$financialType) { | |
126 | $condition = " is_active = 1 "; | |
127 | CRM_Core_PseudoConstant::populate( | |
128 | self::$financialType, | |
129 | 'CRM_Financial_DAO_FinancialType', | |
130 | TRUE, | |
131 | 'name', | |
132 | NULL, | |
133 | $condition | |
134 | ); | |
135 | } | |
136 | ||
137 | if ($id) { | |
138 | $result = CRM_Utils_Array::value($id, self::$financialType); | |
139 | return $result; | |
140 | } | |
141 | return self::$financialType; | |
142 | } | |
143 | ||
144 | /** | |
145 | * Get all the financial Accounts | |
146 | * | |
147 | * @access public | |
148 | * @return array - array reference of all financial accounts if any | |
149 | * @static | |
150 | */ | |
086ca649 | 151 | public static function &financialAccount($id = NULL, $financialAccountTypeId = NULL, $retrieveColumn = 'name', $key = 'id') { |
6a488035 TO |
152 | $condition = NUll; |
153 | if ($financialAccountTypeId) { | |
154 | $condition = " financial_account_type_id = ". $financialAccountTypeId; | |
155 | } | |
086ca649 | 156 | $cacheKey = "{$id}_{$financialAccountTypeId}_{$retrieveColumn}_{$key}"; |
6a488035 TO |
157 | if (!isset(self::$financialAccount[$cacheKey])) { |
158 | CRM_Core_PseudoConstant::populate( | |
159 | self::$financialAccount[$cacheKey], | |
160 | 'CRM_Financial_DAO_FinancialAccount', | |
161 | TRUE, | |
086ca649 | 162 | $retrieveColumn, |
6a488035 | 163 | 'is_active', |
086ca649 PN |
164 | $condition, |
165 | NULL, | |
166 | $key | |
6a488035 TO |
167 | ); |
168 | ||
169 | } | |
170 | if ($id) { | |
171 | $result = CRM_Utils_Array::value($id, self::$financialAccount[$cacheKey]); | |
172 | return $result; | |
173 | } | |
174 | return self::$financialAccount[$cacheKey]; | |
175 | } | |
176 | ||
177 | /** | |
178 | * Flush given pseudoconstant so it can be reread from db | |
179 | * nex time it's requested. | |
180 | * | |
181 | * @access public | |
182 | * @static | |
183 | * | |
184 | * @param boolean $name pseudoconstant to be flushed | |
185 | * | |
186 | */ | |
187 | public static function flush($name) { | |
fa56270d CW |
188 | if (isset(self::$$name)) { |
189 | self::$$name = NULL; | |
190 | } | |
6a488035 TO |
191 | } |
192 | ||
193 | /** | |
194 | * Get all the contribution pages | |
195 | * | |
196 | * @param integer $id id of the contribution page | |
197 | * @param boolean $all do we want all pages or only active pages | |
198 | * | |
199 | * @access public | |
200 | * | |
201 | * @return array - array reference of all contribution pages if any | |
202 | * @static | |
203 | */ | |
204 | public static function &contributionPage($id = NULL, $all = FALSE) { | |
205 | if ($all) { | |
206 | $cacheVarToUse = &self::$contributionPageAll; | |
207 | } | |
208 | else { | |
209 | $cacheVarToUse = &self::$contributionPageActive; | |
210 | } | |
211 | ||
212 | if (!$cacheVarToUse) { | |
213 | CRM_Core_PseudoConstant::populate($cacheVarToUse, | |
214 | 'CRM_Contribute_DAO_ContributionPage', | |
215 | $all, 'title' | |
216 | ); | |
217 | } | |
218 | if ($id) { | |
219 | $pageTitle = CRM_Utils_Array::value($id, $cacheVarToUse); | |
220 | return $pageTitle; | |
221 | } | |
222 | return $cacheVarToUse; | |
223 | } | |
224 | ||
225 | /** | |
226 | * Get all the payment instruments | |
227 | * | |
228 | * @access public | |
229 | * | |
230 | * @return array - array reference of all payment instruments if any | |
231 | * @static | |
232 | */ | |
233 | public static function &paymentInstrument($columnName = 'label') { | |
234 | if (!isset(self::$paymentInstrument[$columnName])) { | |
235 | self::$paymentInstrument[$columnName] = CRM_Core_OptionGroup::values('payment_instrument', | |
236 | FALSE, FALSE, FALSE, NULL, $columnName | |
237 | ); | |
238 | } | |
239 | ||
240 | return self::$paymentInstrument[$columnName]; | |
241 | } | |
242 | ||
243 | /** | |
244 | * Get all the valid accepted credit cards | |
245 | * | |
246 | * @access public | |
247 | * | |
248 | * @return array - array reference of all payment instruments if any | |
249 | * @static | |
250 | */ | |
251 | public static function &creditCard() { | |
252 | $acceptCreditCard = array(); | |
253 | $creditCard = CRM_Core_OptionGroup::values('accept_creditcard'); | |
254 | ||
255 | if (!$creditCard) { | |
256 | $creditCard = array(); | |
257 | } | |
258 | foreach ($creditCard as $key => $value) { | |
259 | $acceptCreditCard[$value] = $value; | |
260 | } | |
261 | return $acceptCreditCard; | |
262 | } | |
263 | ||
264 | /** | |
265 | * Get all premiums | |
266 | * | |
267 | * @access public | |
268 | * | |
269 | * @return array - array of all Premiums if any | |
270 | * @static | |
271 | */ | |
272 | public static function products($pageID = NULL) { | |
273 | $products = array(); | |
274 | $dao = new CRM_Contribute_DAO_Product(); | |
275 | $dao->is_active = 1; | |
276 | $dao->orderBy('id'); | |
277 | $dao->find(); | |
278 | ||
279 | while ($dao->fetch()) { | |
280 | $products[$dao->id] = $dao->name; | |
281 | } | |
282 | if ($pageID) { | |
283 | $dao = new CRM_Contribute_DAO_Premium(); | |
284 | $dao->entity_table = 'civicrm_contribution_page'; | |
285 | $dao->entity_id = $pageID; | |
286 | $dao->find(TRUE); | |
287 | $premiumID = $dao->id; | |
288 | ||
289 | $productID = array(); | |
290 | ||
291 | $dao = new CRM_Contribute_DAO_PremiumsProduct(); | |
292 | $dao->premiums_id = $premiumID; | |
293 | $dao->find(); | |
294 | while ($dao->fetch()) { | |
295 | $productID[$dao->product_id] = $dao->product_id; | |
296 | } | |
297 | ||
298 | $tempProduct = array(); | |
299 | foreach ($products as $key => $value) { | |
300 | if (!array_key_exists($key, $productID)) { | |
301 | $tempProduct[$key] = $value; | |
302 | } | |
303 | } | |
304 | ||
305 | return $tempProduct; | |
306 | } | |
307 | ||
308 | return $products; | |
309 | } | |
310 | ||
311 | /** | |
312 | * Get all the contribution statuses | |
313 | * | |
314 | * @access public | |
315 | * | |
316 | * @return array - array reference of all contribution statuses | |
317 | * @static | |
318 | */ | |
319 | public static function &contributionStatus($id = NULL, $columnName = 'label') { | |
320 | $cacheKey = $columnName; | |
321 | if (!isset(self::$contributionStatus[$cacheKey])) { | |
322 | self::$contributionStatus[$cacheKey] = CRM_Core_OptionGroup::values('contribution_status', | |
323 | FALSE, FALSE, FALSE, NULL, $columnName | |
324 | ); | |
325 | } | |
326 | $result = self::$contributionStatus[$cacheKey]; | |
327 | if ($id) { | |
328 | $result = CRM_Utils_Array::value($id, $result); | |
329 | } | |
330 | ||
331 | return $result; | |
332 | } | |
333 | ||
334 | /** | |
335 | * Get all the Personal campaign pages | |
336 | * | |
337 | * @access public | |
338 | * | |
339 | * @return array - array reference of all pcp if any | |
340 | * @static | |
341 | */ | |
342 | public static function &pcPage($pageType = NULL, $id = NULL) { | |
343 | if (!isset(self::$pcPage[$pageType])) { | |
344 | if ($pageType) { | |
345 | $params = "page_type='{$pageType}'"; | |
346 | } | |
347 | else { | |
348 | $params = ''; | |
349 | } | |
350 | CRM_Core_PseudoConstant::populate(self::$pcPage[$pageType], | |
351 | 'CRM_PCP_DAO_PCP', | |
352 | FALSE, 'title', 'is_active', $params | |
353 | ); | |
354 | } | |
355 | $result = self::$pcPage[$pageType]; | |
356 | if ($id) { | |
357 | return $result = CRM_Utils_Array::value($id, $result); | |
358 | } | |
359 | ||
360 | return $result; | |
361 | } | |
362 | ||
363 | /** | |
364 | * Get all PCP Statuses. | |
365 | * | |
366 | * The static array pcpStatus is returned | |
367 | * | |
368 | * @access public | |
369 | * @static | |
370 | * | |
371 | * @return array - array reference of all PCP activity statuses | |
372 | */ | |
373 | public static function &pcpStatus($column = 'label') { | |
374 | if (NULL === self::$pcpStatus) { | |
375 | self::$pcpStatus = array(); | |
376 | } | |
377 | if (!array_key_exists($column, self::$pcpStatus)) { | |
378 | self::$pcpStatus[$column] = array(); | |
379 | ||
380 | self::$pcpStatus[$column] = CRM_Core_OptionGroup::values('pcp_status', FALSE, | |
381 | FALSE, FALSE, NULL, $column | |
382 | ); | |
383 | } | |
384 | return self::$pcpStatus[$column]; | |
385 | } | |
386 | ||
387 | /** | |
388 | * Get all financial accounts for a Financial type. | |
389 | * | |
390 | * The static array $financialTypeAccount is returned | |
391 | * | |
392 | * @access public | |
393 | * @static | |
394 | * | |
395 | * @return array - array reference of all financial accounts for a Financial type | |
396 | */ | |
397 | public static function financialAccountType($financialTypeId, $relationTypeId = NULL) { | |
398 | if (!CRM_Utils_Array::value($financialTypeId, self::$financialTypeAccount)) { | |
399 | $condition = " entity_id = $financialTypeId "; | |
400 | CRM_Core_PseudoConstant::populate( | |
401 | self::$financialTypeAccount[$financialTypeId], | |
402 | 'CRM_Financial_DAO_EntityFinancialAccount', | |
403 | $all = true, | |
404 | $retrieve = 'financial_account_id', | |
405 | $filter = NULL, | |
406 | $condition, | |
407 | NULL, | |
408 | 'account_relationship' | |
409 | ); | |
410 | } | |
411 | ||
412 | if ($relationTypeId) { | |
413 | return CRM_Utils_Array::value($relationTypeId, self::$financialTypeAccount[$financialTypeId]); | |
414 | } | |
415 | ||
416 | return self::$financialTypeAccount[$financialTypeId]; | |
417 | } | |
418 | } | |
419 |