3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class holds all the Pseudo constants that are specific to Contributions.
21 * This avoids polluting the core class and isolates the mass mailer class.
23 class CRM_Contribute_PseudoConstant
extends CRM_Core_PseudoConstant
{
29 private static $financialType;
35 private static $financialAccount;
41 private static $contributionPageActive = NULL;
47 private static $contributionPageAll = NULL;
54 private static $paymentInstrument;
61 private static $contributionStatus;
64 * Personal campaign pages
67 private static $pcPage;
70 * Status of personal campaign page
74 private static $pcpStatus;
77 * Contribution / financial batches
80 private static $batch;
83 * @deprecated. Please use the buildOptions() method in the appropriate BAO object.
86 * Get all the financial types
90 * @param bool $includeDisabled
93 * array reference of all financial types if any
95 public static function &financialType($id = NULL, $includeDisabled = FALSE) {
96 if (!self
::$financialType) {
98 if (!$includeDisabled) {
99 $condition = " is_active = 1 ";
101 CRM_Core_PseudoConstant
::populate(
102 self
::$financialType,
103 'CRM_Financial_DAO_FinancialType',
112 $result = self
::$financialType[$id] ??
NULL;
115 return self
::$financialType;
119 * @deprecated. Please use the buildOptions() method in the appropriate BAO object.
120 * TODO: buildOptions() doesn't replace this as it doesn't support filtering, which is used with this function.
122 * Get all/filtered array of the financial Accounts
126 * @param int $financialAccountTypeId Optional filer to return only financial accounts of type
127 * @param string $retrieveColumn
131 * array reference of all financial accounts if any
133 public static function &financialAccount($id = NULL, $financialAccountTypeId = NULL, $retrieveColumn = 'name', $key = 'id') {
135 if ($financialAccountTypeId) {
136 $condition = " financial_account_type_id = " . $financialAccountTypeId;
138 $cacheKey = "{$id}_{$financialAccountTypeId}_{$retrieveColumn}_{$key}";
139 if (!isset(self
::$financialAccount[$cacheKey])) {
140 CRM_Core_PseudoConstant
::populate(
141 self
::$financialAccount[$cacheKey],
142 'CRM_Financial_DAO_FinancialAccount',
153 $result = self
::$financialAccount[$cacheKey][$id] ??
NULL;
156 return self
::$financialAccount[$cacheKey];
160 * Flush given pseudoconstant so it can be reread from db
161 * nex time it's requested.
164 * @param bool|string $name pseudoconstant to be flushed
166 public static function flush($name = 'cache') {
167 if (isset(self
::$
$name)) {
173 * @deprecated. Please use the buildOptions() method in the appropriate BAO object.
175 * Get all the contribution pages
178 * Id of the contribution page.
180 * Do we want all pages or only active pages.
184 * array reference of all contribution pages if any
186 public static function &contributionPage($id = NULL, $all = FALSE) {
188 $cacheVarToUse = &self
::$contributionPageAll;
191 $cacheVarToUse = &self
::$contributionPageActive;
194 if (!$cacheVarToUse) {
195 CRM_Core_PseudoConstant
::populate($cacheVarToUse,
196 'CRM_Contribute_DAO_ContributionPage',
201 $pageTitle = $cacheVarToUse[$id] ??
NULL;
204 return $cacheVarToUse;
208 * @deprecated. Please use the buildOptions() method in the appropriate BAO object.
210 * Get all the payment instruments
213 * @param string $columnName
216 * array reference of all payment instruments if any
218 public static function &paymentInstrument($columnName = 'label') {
219 if (!isset(self
::$paymentInstrument[$columnName])) {
220 self
::$paymentInstrument[$columnName] = CRM_Core_OptionGroup
::values('payment_instrument',
221 FALSE, FALSE, FALSE, NULL, $columnName
225 return self
::$paymentInstrument[$columnName];
229 * Get all the valid accepted credit cards.
233 * array reference of all payment instruments if any
235 public static function &creditCard() {
236 return CRM_Core_OptionGroup
::values('accept_creditcard', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
245 * array of all Premiums if any
247 public static function products($pageID = NULL) {
249 $dao = new CRM_Contribute_DAO_Product();
254 while ($dao->fetch()) {
255 $products[$dao->id
] = $dao->name
;
258 $dao = new CRM_Contribute_DAO_Premium();
259 $dao->entity_table
= 'civicrm_contribution_page';
260 $dao->entity_id
= $pageID;
262 $premiumID = $dao->id
;
266 $dao = new CRM_Contribute_DAO_PremiumsProduct();
267 $dao->premiums_id
= $premiumID;
269 while ($dao->fetch()) {
270 $productID[$dao->product_id
] = $dao->product_id
;
274 foreach ($products as $key => $value) {
275 if (!array_key_exists($key, $productID)) {
276 $tempProduct[$key] = $value;
287 * Get all the contribution statuses.
291 * @param string $columnName
293 * array reference of all contribution statuses
295 public static function &contributionStatus($id = NULL, $columnName = 'label') {
296 $cacheKey = $columnName;
297 if (!isset(self
::$contributionStatus[$cacheKey])) {
298 self
::$contributionStatus[$cacheKey] = CRM_Core_OptionGroup
::values('contribution_status',
299 FALSE, FALSE, FALSE, NULL, $columnName
302 $result = self
::$contributionStatus[$cacheKey];
304 $result = $result[$id] ??
NULL;
311 * Get all the Personal campaign pages.
314 * @param null $pageType
318 * array reference of all pcp if any
320 public static function &pcPage($pageType = NULL, $id = NULL) {
321 if (!isset(self
::$pcPage[$pageType])) {
323 $params = "page_type='{$pageType}'";
328 CRM_Core_PseudoConstant
::populate(self
::$pcPage[$pageType],
330 FALSE, 'title', 'is_active', $params
333 $result = self
::$pcPage[$pageType];
335 return $result = $result[$id] ??
NULL;
342 * Get all PCP Statuses.
344 * The static array pcpStatus is returned
347 * @param string $column
349 * array reference of all PCP activity statuses
351 public static function &pcpStatus($column = 'label') {
352 CRM_Core_Error
::deprecatedFunctionWarning('Function pcpStatus will be removed');
353 if (NULL === self
::$pcpStatus) {
354 self
::$pcpStatus = [];
356 if (!array_key_exists($column, self
::$pcpStatus)) {
357 self
::$pcpStatus[$column] = [];
359 self
::$pcpStatus[$column] = CRM_Core_OptionGroup
::values('pcp_status', FALSE,
360 FALSE, FALSE, NULL, $column
363 return self
::$pcpStatus[$column];
367 * Get financial account for a Financial type.
369 * @deprecated use the alternative with caching
370 * CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship
372 * @param int $entityId
373 * @param string $accountRelationType
374 * @param string $entityTable
375 * @param string $returnField
378 public static function getRelationalFinancialAccount($entityId, $accountRelationType, $entityTable = 'civicrm_financial_type', $returnField = 'financial_account_id') {
380 'return' => [$returnField],
381 'entity_table' => $entityTable,
382 'entity_id' => $entityId,
384 if ($accountRelationType) {
385 $params['account_relationship.name'] = $accountRelationType;
387 $result = civicrm_api3('EntityFinancialAccount', 'get', $params);
388 if (!$result['count']) {
391 return $result['values'][$result['id']][$returnField];
400 * array reference of all batches if any
402 public static function &batch($id = NULL) {
404 $orderBy = " id DESC ";
405 CRM_Core_PseudoConstant
::populate(
407 'CRM_Batch_DAO_Batch',
417 $result = self
::$batch[$id] ??
NULL;