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 | ||
91aff94c | 116 | /** |
117 | * contribution / financial batches | |
118 | * @var array | |
119 | * @static | |
120 | */ | |
121 | private static $batch; | |
122 | ||
6a488035 TO |
123 | /** |
124 | * Get all the financial types | |
125 | * | |
126 | * @access public | |
127 | * | |
128 | * @return array - array reference of all financial types if any | |
129 | * @static | |
130 | */ | |
131 | public static function &financialType($id = NULL) { | |
132 | if (!self::$financialType) { | |
133 | $condition = " is_active = 1 "; | |
134 | CRM_Core_PseudoConstant::populate( | |
135 | self::$financialType, | |
136 | 'CRM_Financial_DAO_FinancialType', | |
137 | TRUE, | |
138 | 'name', | |
139 | NULL, | |
140 | $condition | |
141 | ); | |
142 | } | |
143 | ||
144 | if ($id) { | |
145 | $result = CRM_Utils_Array::value($id, self::$financialType); | |
146 | return $result; | |
147 | } | |
148 | return self::$financialType; | |
149 | } | |
150 | ||
151 | /** | |
152 | * Get all the financial Accounts | |
153 | * | |
154 | * @access public | |
155 | * @return array - array reference of all financial accounts if any | |
156 | * @static | |
157 | */ | |
086ca649 | 158 | public static function &financialAccount($id = NULL, $financialAccountTypeId = NULL, $retrieveColumn = 'name', $key = 'id') { |
6a488035 TO |
159 | $condition = NUll; |
160 | if ($financialAccountTypeId) { | |
161 | $condition = " financial_account_type_id = ". $financialAccountTypeId; | |
162 | } | |
086ca649 | 163 | $cacheKey = "{$id}_{$financialAccountTypeId}_{$retrieveColumn}_{$key}"; |
6a488035 TO |
164 | if (!isset(self::$financialAccount[$cacheKey])) { |
165 | CRM_Core_PseudoConstant::populate( | |
166 | self::$financialAccount[$cacheKey], | |
167 | 'CRM_Financial_DAO_FinancialAccount', | |
168 | TRUE, | |
086ca649 | 169 | $retrieveColumn, |
6a488035 | 170 | 'is_active', |
086ca649 PN |
171 | $condition, |
172 | NULL, | |
173 | $key | |
6a488035 TO |
174 | ); |
175 | ||
176 | } | |
177 | if ($id) { | |
178 | $result = CRM_Utils_Array::value($id, self::$financialAccount[$cacheKey]); | |
179 | return $result; | |
180 | } | |
181 | return self::$financialAccount[$cacheKey]; | |
182 | } | |
183 | ||
184 | /** | |
185 | * Flush given pseudoconstant so it can be reread from db | |
186 | * nex time it's requested. | |
187 | * | |
188 | * @access public | |
189 | * @static | |
190 | * | |
191 | * @param boolean $name pseudoconstant to be flushed | |
192 | * | |
193 | */ | |
194 | public static function flush($name) { | |
fa56270d CW |
195 | if (isset(self::$$name)) { |
196 | self::$$name = NULL; | |
197 | } | |
6a488035 TO |
198 | } |
199 | ||
200 | /** | |
201 | * Get all the contribution pages | |
202 | * | |
203 | * @param integer $id id of the contribution page | |
204 | * @param boolean $all do we want all pages or only active pages | |
205 | * | |
206 | * @access public | |
207 | * | |
208 | * @return array - array reference of all contribution pages if any | |
209 | * @static | |
210 | */ | |
211 | public static function &contributionPage($id = NULL, $all = FALSE) { | |
212 | if ($all) { | |
213 | $cacheVarToUse = &self::$contributionPageAll; | |
214 | } | |
215 | else { | |
216 | $cacheVarToUse = &self::$contributionPageActive; | |
217 | } | |
218 | ||
219 | if (!$cacheVarToUse) { | |
220 | CRM_Core_PseudoConstant::populate($cacheVarToUse, | |
221 | 'CRM_Contribute_DAO_ContributionPage', | |
222 | $all, 'title' | |
223 | ); | |
224 | } | |
225 | if ($id) { | |
226 | $pageTitle = CRM_Utils_Array::value($id, $cacheVarToUse); | |
227 | return $pageTitle; | |
228 | } | |
229 | return $cacheVarToUse; | |
230 | } | |
231 | ||
232 | /** | |
233 | * Get all the payment instruments | |
234 | * | |
235 | * @access public | |
236 | * | |
237 | * @return array - array reference of all payment instruments if any | |
238 | * @static | |
239 | */ | |
240 | public static function &paymentInstrument($columnName = 'label') { | |
241 | if (!isset(self::$paymentInstrument[$columnName])) { | |
242 | self::$paymentInstrument[$columnName] = CRM_Core_OptionGroup::values('payment_instrument', | |
243 | FALSE, FALSE, FALSE, NULL, $columnName | |
244 | ); | |
245 | } | |
246 | ||
247 | return self::$paymentInstrument[$columnName]; | |
248 | } | |
249 | ||
250 | /** | |
251 | * Get all the valid accepted credit cards | |
252 | * | |
253 | * @access public | |
254 | * | |
255 | * @return array - array reference of all payment instruments if any | |
256 | * @static | |
257 | */ | |
258 | public static function &creditCard() { | |
259 | $acceptCreditCard = array(); | |
260 | $creditCard = CRM_Core_OptionGroup::values('accept_creditcard'); | |
261 | ||
262 | if (!$creditCard) { | |
263 | $creditCard = array(); | |
264 | } | |
265 | foreach ($creditCard as $key => $value) { | |
266 | $acceptCreditCard[$value] = $value; | |
267 | } | |
268 | return $acceptCreditCard; | |
269 | } | |
270 | ||
271 | /** | |
272 | * Get all premiums | |
273 | * | |
274 | * @access public | |
275 | * | |
276 | * @return array - array of all Premiums if any | |
277 | * @static | |
278 | */ | |
279 | public static function products($pageID = NULL) { | |
280 | $products = array(); | |
281 | $dao = new CRM_Contribute_DAO_Product(); | |
282 | $dao->is_active = 1; | |
283 | $dao->orderBy('id'); | |
284 | $dao->find(); | |
285 | ||
286 | while ($dao->fetch()) { | |
287 | $products[$dao->id] = $dao->name; | |
288 | } | |
289 | if ($pageID) { | |
290 | $dao = new CRM_Contribute_DAO_Premium(); | |
291 | $dao->entity_table = 'civicrm_contribution_page'; | |
292 | $dao->entity_id = $pageID; | |
293 | $dao->find(TRUE); | |
294 | $premiumID = $dao->id; | |
295 | ||
296 | $productID = array(); | |
297 | ||
298 | $dao = new CRM_Contribute_DAO_PremiumsProduct(); | |
299 | $dao->premiums_id = $premiumID; | |
300 | $dao->find(); | |
301 | while ($dao->fetch()) { | |
302 | $productID[$dao->product_id] = $dao->product_id; | |
303 | } | |
304 | ||
305 | $tempProduct = array(); | |
306 | foreach ($products as $key => $value) { | |
307 | if (!array_key_exists($key, $productID)) { | |
308 | $tempProduct[$key] = $value; | |
309 | } | |
310 | } | |
311 | ||
312 | return $tempProduct; | |
313 | } | |
314 | ||
315 | return $products; | |
316 | } | |
317 | ||
318 | /** | |
319 | * Get all the contribution statuses | |
320 | * | |
321 | * @access public | |
322 | * | |
323 | * @return array - array reference of all contribution statuses | |
324 | * @static | |
325 | */ | |
326 | public static function &contributionStatus($id = NULL, $columnName = 'label') { | |
327 | $cacheKey = $columnName; | |
328 | if (!isset(self::$contributionStatus[$cacheKey])) { | |
329 | self::$contributionStatus[$cacheKey] = CRM_Core_OptionGroup::values('contribution_status', | |
330 | FALSE, FALSE, FALSE, NULL, $columnName | |
331 | ); | |
332 | } | |
333 | $result = self::$contributionStatus[$cacheKey]; | |
334 | if ($id) { | |
335 | $result = CRM_Utils_Array::value($id, $result); | |
336 | } | |
337 | ||
338 | return $result; | |
339 | } | |
340 | ||
341 | /** | |
342 | * Get all the Personal campaign pages | |
343 | * | |
344 | * @access public | |
345 | * | |
346 | * @return array - array reference of all pcp if any | |
347 | * @static | |
348 | */ | |
349 | public static function &pcPage($pageType = NULL, $id = NULL) { | |
350 | if (!isset(self::$pcPage[$pageType])) { | |
351 | if ($pageType) { | |
352 | $params = "page_type='{$pageType}'"; | |
353 | } | |
354 | else { | |
355 | $params = ''; | |
356 | } | |
357 | CRM_Core_PseudoConstant::populate(self::$pcPage[$pageType], | |
358 | 'CRM_PCP_DAO_PCP', | |
359 | FALSE, 'title', 'is_active', $params | |
360 | ); | |
361 | } | |
362 | $result = self::$pcPage[$pageType]; | |
363 | if ($id) { | |
364 | return $result = CRM_Utils_Array::value($id, $result); | |
365 | } | |
366 | ||
367 | return $result; | |
368 | } | |
369 | ||
370 | /** | |
371 | * Get all PCP Statuses. | |
372 | * | |
373 | * The static array pcpStatus is returned | |
374 | * | |
375 | * @access public | |
376 | * @static | |
377 | * | |
378 | * @return array - array reference of all PCP activity statuses | |
379 | */ | |
380 | public static function &pcpStatus($column = 'label') { | |
381 | if (NULL === self::$pcpStatus) { | |
382 | self::$pcpStatus = array(); | |
383 | } | |
384 | if (!array_key_exists($column, self::$pcpStatus)) { | |
385 | self::$pcpStatus[$column] = array(); | |
386 | ||
387 | self::$pcpStatus[$column] = CRM_Core_OptionGroup::values('pcp_status', FALSE, | |
388 | FALSE, FALSE, NULL, $column | |
389 | ); | |
390 | } | |
391 | return self::$pcpStatus[$column]; | |
392 | } | |
393 | ||
394 | /** | |
395 | * Get all financial accounts for a Financial type. | |
396 | * | |
397 | * The static array $financialTypeAccount is returned | |
398 | * | |
399 | * @access public | |
400 | * @static | |
401 | * | |
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 | * | |
429 | * @access public | |
430 | * | |
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 TO |
454 | } |
455 |