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
73 private static $pcpStatus;
76 * Contribution / financial batches
79 private static $batch;
82 * @deprecated. Please use the buildOptions() method in the appropriate BAO object.
85 * Get all the financial types
89 * @param bool $includeDisabled
92 * array reference of all financial types if any
94 public static function &financialType($id = NULL, $includeDisabled = FALSE) {
95 if (!self
::$financialType) {
97 if (!$includeDisabled) {
98 $condition = " is_active = 1 ";
100 CRM_Core_PseudoConstant
::populate(
101 self
::$financialType,
102 'CRM_Financial_DAO_FinancialType',
111 $result = CRM_Utils_Array
::value($id, self
::$financialType);
114 return self
::$financialType;
118 * @deprecated. Please use the buildOptions() method in the appropriate BAO object.
119 * TODO: buildOptions() doesn't replace this as it doesn't support filtering, which is used with this function.
121 * Get all/filtered array of the financial Accounts
125 * @param int $financialAccountTypeId Optional filer to return only financial accounts of type
126 * @param string $retrieveColumn
130 * array reference of all financial accounts if any
132 public static function &financialAccount($id = NULL, $financialAccountTypeId = NULL, $retrieveColumn = 'name', $key = 'id') {
134 if ($financialAccountTypeId) {
135 $condition = " financial_account_type_id = " . $financialAccountTypeId;
137 $cacheKey = "{$id}_{$financialAccountTypeId}_{$retrieveColumn}_{$key}";
138 if (!isset(self
::$financialAccount[$cacheKey])) {
139 CRM_Core_PseudoConstant
::populate(
140 self
::$financialAccount[$cacheKey],
141 'CRM_Financial_DAO_FinancialAccount',
152 $result = CRM_Utils_Array
::value($id, self
::$financialAccount[$cacheKey]);
155 return self
::$financialAccount[$cacheKey];
159 * Flush given pseudoconstant so it can be reread from db
160 * nex time it's requested.
163 * @param bool|string $name pseudoconstant to be flushed
165 public static function flush($name = 'cache') {
166 if (isset(self
::$
$name)) {
172 * @deprecated. Please use the buildOptions() method in the appropriate BAO object.
174 * Get all the contribution pages
177 * Id of the contribution page.
179 * Do we want all pages or only active pages.
183 * array reference of all contribution pages if any
185 public static function &contributionPage($id = NULL, $all = FALSE) {
187 $cacheVarToUse = &self
::$contributionPageAll;
190 $cacheVarToUse = &self
::$contributionPageActive;
193 if (!$cacheVarToUse) {
194 CRM_Core_PseudoConstant
::populate($cacheVarToUse,
195 'CRM_Contribute_DAO_ContributionPage',
200 $pageTitle = CRM_Utils_Array
::value($id, $cacheVarToUse);
203 return $cacheVarToUse;
207 * @deprecated. Please use the buildOptions() method in the appropriate BAO object.
209 * Get all the payment instruments
212 * @param string $columnName
215 * array reference of all payment instruments if any
217 public static function &paymentInstrument($columnName = 'label') {
218 if (!isset(self
::$paymentInstrument[$columnName])) {
219 self
::$paymentInstrument[$columnName] = CRM_Core_OptionGroup
::values('payment_instrument',
220 FALSE, FALSE, FALSE, NULL, $columnName
224 return self
::$paymentInstrument[$columnName];
228 * Get all the valid accepted credit cards.
232 * array reference of all payment instruments if any
234 public static function &creditCard() {
235 return CRM_Core_OptionGroup
::values('accept_creditcard', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
244 * array of all Premiums if any
246 public static function products($pageID = NULL) {
248 $dao = new CRM_Contribute_DAO_Product();
253 while ($dao->fetch()) {
254 $products[$dao->id
] = $dao->name
;
257 $dao = new CRM_Contribute_DAO_Premium();
258 $dao->entity_table
= 'civicrm_contribution_page';
259 $dao->entity_id
= $pageID;
261 $premiumID = $dao->id
;
265 $dao = new CRM_Contribute_DAO_PremiumsProduct();
266 $dao->premiums_id
= $premiumID;
268 while ($dao->fetch()) {
269 $productID[$dao->product_id
] = $dao->product_id
;
273 foreach ($products as $key => $value) {
274 if (!array_key_exists($key, $productID)) {
275 $tempProduct[$key] = $value;
286 * Get all the contribution statuses.
290 * @param string $columnName
292 * array reference of all contribution statuses
294 public static function &contributionStatus($id = NULL, $columnName = 'label') {
295 $cacheKey = $columnName;
296 if (!isset(self
::$contributionStatus[$cacheKey])) {
297 self
::$contributionStatus[$cacheKey] = CRM_Core_OptionGroup
::values('contribution_status',
298 FALSE, FALSE, FALSE, NULL, $columnName
301 $result = self
::$contributionStatus[$cacheKey];
303 $result = CRM_Utils_Array
::value($id, $result);
310 * Get all the Personal campaign pages.
313 * @param null $pageType
317 * array reference of all pcp if any
319 public static function &pcPage($pageType = NULL, $id = NULL) {
320 if (!isset(self
::$pcPage[$pageType])) {
322 $params = "page_type='{$pageType}'";
327 CRM_Core_PseudoConstant
::populate(self
::$pcPage[$pageType],
329 FALSE, 'title', 'is_active', $params
332 $result = self
::$pcPage[$pageType];
334 return $result = CRM_Utils_Array
::value($id, $result);
341 * Get all PCP Statuses.
343 * The static array pcpStatus is returned
346 * @param string $column
348 * array reference of all PCP activity statuses
350 public static function &pcpStatus($column = 'label') {
351 if (NULL === self
::$pcpStatus) {
352 self
::$pcpStatus = [];
354 if (!array_key_exists($column, self
::$pcpStatus)) {
355 self
::$pcpStatus[$column] = [];
357 self
::$pcpStatus[$column] = CRM_Core_OptionGroup
::values('pcp_status', FALSE,
358 FALSE, FALSE, NULL, $column
361 return self
::$pcpStatus[$column];
365 * Get financial account for a Financial type.
367 * @deprecated use the alternative with caching
368 * CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship
370 * @param int $entityId
371 * @param string $accountRelationType
372 * @param string $entityTable
373 * @param string $returnField
376 public static function getRelationalFinancialAccount($entityId, $accountRelationType, $entityTable = 'civicrm_financial_type', $returnField = 'financial_account_id') {
378 'return' => [$returnField],
379 'entity_table' => $entityTable,
380 'entity_id' => $entityId,
382 if ($accountRelationType) {
383 $params['account_relationship.name'] = $accountRelationType;
385 $result = civicrm_api3('EntityFinancialAccount', 'get', $params);
386 if (!$result['count']) {
389 return $result['values'][$result['id']][$returnField];
398 * array reference of all batches if any
400 public static function &batch($id = NULL) {
402 $orderBy = " id DESC ";
403 CRM_Core_PseudoConstant
::populate(
405 'CRM_Batch_DAO_Batch',
415 $result = CRM_Utils_Array
::value($id, self
::$batch);