3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
35 * This class holds all the Pseudo constants that are specific to Contributions.
37 * This avoids polluting the core class and isolates the mass mailer class.
39 class CRM_Contribute_PseudoConstant
extends CRM_Core_PseudoConstant
{
45 private static $financialType;
51 private static $financialTypeAccount;
58 private static $financialAccount;
64 private static $contributionPageActive = NULL;
70 private static $contributionPageAll = NULL;
77 private static $paymentInstrument;
84 private static $contributionStatus;
87 * Personal campaign pages
90 private static $pcPage;
93 * Status of personal campaign page
96 private static $pcpStatus;
99 * Contribution / financial batches
102 private static $batch;
105 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
107 * Get all the financial types
113 * array reference of all financial types if any
115 public static function &financialType($id = NULL) {
116 if (!self
::$financialType) {
117 $condition = " is_active = 1 ";
118 CRM_Core_PseudoConstant
::populate(
119 self
::$financialType,
120 'CRM_Financial_DAO_FinancialType',
129 $result = CRM_Utils_Array
::value($id, self
::$financialType);
132 return self
::$financialType;
136 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
138 * Get all the financial Accounts
142 * @param int $financialAccountTypeId
143 * @param string $retrieveColumn
147 * array reference of all financial accounts if any
149 public static function &financialAccount($id = NULL, $financialAccountTypeId = NULL, $retrieveColumn = 'name', $key = 'id') {
151 if ($financialAccountTypeId) {
152 $condition = " financial_account_type_id = " . $financialAccountTypeId;
154 $cacheKey = "{$id}_{$financialAccountTypeId}_{$retrieveColumn}_{$key}";
155 if (!isset(self
::$financialAccount[$cacheKey])) {
156 CRM_Core_PseudoConstant
::populate(
157 self
::$financialAccount[$cacheKey],
158 'CRM_Financial_DAO_FinancialAccount',
169 $result = CRM_Utils_Array
::value($id, self
::$financialAccount[$cacheKey]);
172 return self
::$financialAccount[$cacheKey];
176 * Flush given pseudoconstant so it can be reread from db
177 * nex time it's requested.
180 * @param bool|string $name pseudoconstant to be flushed
182 public static function flush($name = 'cache') {
183 if (isset(self
::$
$name)) {
189 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
191 * Get all the contribution pages
194 * Id of the contribution page.
196 * Do we want all pages or only active pages.
200 * array reference of all contribution pages if any
202 public static function &contributionPage($id = NULL, $all = FALSE) {
204 $cacheVarToUse = &self
::$contributionPageAll;
207 $cacheVarToUse = &self
::$contributionPageActive;
210 if (!$cacheVarToUse) {
211 CRM_Core_PseudoConstant
::populate($cacheVarToUse,
212 'CRM_Contribute_DAO_ContributionPage',
217 $pageTitle = CRM_Utils_Array
::value($id, $cacheVarToUse);
220 return $cacheVarToUse;
224 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
226 * Get all the payment instruments
229 * @param string $columnName
232 * array reference of all payment instruments if any
234 public static function &paymentInstrument($columnName = 'label') {
235 if (!isset(self
::$paymentInstrument[$columnName])) {
236 self
::$paymentInstrument[$columnName] = CRM_Core_OptionGroup
::values('payment_instrument',
237 FALSE, FALSE, FALSE, NULL, $columnName
241 return self
::$paymentInstrument[$columnName];
245 * Get all the valid accepted credit cards.
249 * array reference of all payment instruments if any
251 public static function &creditCard() {
252 return CRM_Core_OptionGroup
::values('accept_creditcard', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
261 * array of all Premiums if any
263 public static function products($pageID = NULL) {
265 $dao = new CRM_Contribute_DAO_Product();
270 while ($dao->fetch()) {
271 $products[$dao->id
] = $dao->name
;
274 $dao = new CRM_Contribute_DAO_Premium();
275 $dao->entity_table
= 'civicrm_contribution_page';
276 $dao->entity_id
= $pageID;
278 $premiumID = $dao->id
;
280 $productID = array();
282 $dao = new CRM_Contribute_DAO_PremiumsProduct();
283 $dao->premiums_id
= $premiumID;
285 while ($dao->fetch()) {
286 $productID[$dao->product_id
] = $dao->product_id
;
289 $tempProduct = array();
290 foreach ($products as $key => $value) {
291 if (!array_key_exists($key, $productID)) {
292 $tempProduct[$key] = $value;
303 * Get all the contribution statuses.
307 * @param string $columnName
309 * array reference of all contribution statuses
311 public static function &contributionStatus($id = NULL, $columnName = 'label') {
312 $cacheKey = $columnName;
313 if (!isset(self
::$contributionStatus[$cacheKey])) {
314 self
::$contributionStatus[$cacheKey] = CRM_Core_OptionGroup
::values('contribution_status',
315 FALSE, FALSE, FALSE, NULL, $columnName
318 $result = self
::$contributionStatus[$cacheKey];
320 $result = CRM_Utils_Array
::value($id, $result);
327 * Get all the Personal campaign pages.
330 * @param null $pageType
334 * array reference of all pcp if any
336 public static function &pcPage($pageType = NULL, $id = NULL) {
337 if (!isset(self
::$pcPage[$pageType])) {
339 $params = "page_type='{$pageType}'";
344 CRM_Core_PseudoConstant
::populate(self
::$pcPage[$pageType],
346 FALSE, 'title', 'is_active', $params
349 $result = self
::$pcPage[$pageType];
351 return $result = CRM_Utils_Array
::value($id, $result);
358 * Get all PCP Statuses.
360 * The static array pcpStatus is returned
363 * @param string $column
365 * array reference of all PCP activity statuses
367 public static function &pcpStatus($column = 'label') {
368 if (NULL === self
::$pcpStatus) {
369 self
::$pcpStatus = array();
371 if (!array_key_exists($column, self
::$pcpStatus)) {
372 self
::$pcpStatus[$column] = array();
374 self
::$pcpStatus[$column] = CRM_Core_OptionGroup
::values('pcp_status', FALSE,
375 FALSE, FALSE, NULL, $column
378 return self
::$pcpStatus[$column];
382 * Get all financial accounts for a Financial type.
384 * The static array $financialTypeAccount is returned
387 * @param int $financialTypeId
388 * @param int $relationTypeId
390 * array reference of all financial accounts for a Financial type
392 public static function financialAccountType($financialTypeId, $relationTypeId = NULL) {
393 if (!CRM_Utils_Array
::value($financialTypeId, self
::$financialTypeAccount)) {
394 $condition = " entity_id = $financialTypeId ";
395 CRM_Core_PseudoConstant
::populate(
396 self
::$financialTypeAccount[$financialTypeId],
397 'CRM_Financial_DAO_EntityFinancialAccount',
399 $retrieve = 'financial_account_id',
403 'account_relationship'
407 if ($relationTypeId) {
408 return CRM_Utils_Array
::value($relationTypeId, self
::$financialTypeAccount[$financialTypeId]);
411 return self
::$financialTypeAccount[$financialTypeId];
420 * array reference of all batches if any
422 public static function &batch($id = NULL) {
424 $orderBy = " id DESC ";
425 CRM_Core_PseudoConstant
::populate(
427 'CRM_Batch_DAO_Batch',
437 $result = CRM_Utils_Array
::value($id, self
::$batch);