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