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