3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
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 $financialAccount;
57 private static $contributionPageActive = NULL;
63 private static $contributionPageAll = NULL;
70 private static $paymentInstrument;
77 private static $contributionStatus;
80 * Personal campaign pages
83 private static $pcPage;
86 * Status of personal campaign page
89 private static $pcpStatus;
92 * Contribution / financial batches
95 private static $batch;
98 * @deprecated. Please use the buildOptions() method in the appropriate BAO object.
101 * Get all the financial types
105 * @param bool $includeDisabled
108 * array reference of all financial types if any
110 public static function &financialType($id = NULL, $includeDisabled = FALSE) {
111 if (!self
::$financialType) {
113 if (!$includeDisabled) {
114 $condition = " is_active = 1 ";
116 CRM_Core_PseudoConstant
::populate(
117 self
::$financialType,
118 'CRM_Financial_DAO_FinancialType',
127 $result = CRM_Utils_Array
::value($id, self
::$financialType);
130 return self
::$financialType;
134 * @deprecated. Please use the buildOptions() method in the appropriate BAO object.
135 * TODO: buildOptions() doesn't replace this as it doesn't support filtering, which is used with this function.
137 * Get all/filtered array of the financial Accounts
141 * @param int $financialAccountTypeId Optional filer to return only financial accounts of type
142 * @param string $retrieveColumn
146 * array reference of all financial accounts if any
148 public static function &financialAccount($id = NULL, $financialAccountTypeId = NULL, $retrieveColumn = 'name', $key = 'id') {
150 if ($financialAccountTypeId) {
151 $condition = " financial_account_type_id = " . $financialAccountTypeId;
153 $cacheKey = "{$id}_{$financialAccountTypeId}_{$retrieveColumn}_{$key}";
154 if (!isset(self
::$financialAccount[$cacheKey])) {
155 CRM_Core_PseudoConstant
::populate(
156 self
::$financialAccount[$cacheKey],
157 'CRM_Financial_DAO_FinancialAccount',
168 $result = CRM_Utils_Array
::value($id, self
::$financialAccount[$cacheKey]);
171 return self
::$financialAccount[$cacheKey];
175 * Flush given pseudoconstant so it can be reread from db
176 * nex time it's requested.
179 * @param bool|string $name pseudoconstant to be flushed
181 public static function flush($name = 'cache') {
182 if (isset(self
::$
$name)) {
188 * @deprecated. Please use the buildOptions() method in the appropriate BAO object.
190 * Get all the contribution pages
193 * Id of the contribution page.
195 * Do we want all pages or only active pages.
199 * array reference of all contribution pages if any
201 public static function &contributionPage($id = NULL, $all = FALSE) {
203 $cacheVarToUse = &self
::$contributionPageAll;
206 $cacheVarToUse = &self
::$contributionPageActive;
209 if (!$cacheVarToUse) {
210 CRM_Core_PseudoConstant
::populate($cacheVarToUse,
211 'CRM_Contribute_DAO_ContributionPage',
216 $pageTitle = CRM_Utils_Array
::value($id, $cacheVarToUse);
219 return $cacheVarToUse;
223 * @deprecated. Please use the buildOptions() method in the appropriate BAO object.
225 * Get all the payment instruments
228 * @param string $columnName
231 * array reference of all payment instruments if any
233 public static function &paymentInstrument($columnName = 'label') {
234 if (!isset(self
::$paymentInstrument[$columnName])) {
235 self
::$paymentInstrument[$columnName] = CRM_Core_OptionGroup
::values('payment_instrument',
236 FALSE, FALSE, FALSE, NULL, $columnName
240 return self
::$paymentInstrument[$columnName];
244 * Get all the valid accepted credit cards.
248 * array reference of all payment instruments if any
250 public static function &creditCard() {
251 return CRM_Core_OptionGroup
::values('accept_creditcard', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
260 * array of all Premiums if any
262 public static function products($pageID = NULL) {
264 $dao = new CRM_Contribute_DAO_Product();
269 while ($dao->fetch()) {
270 $products[$dao->id
] = $dao->name
;
273 $dao = new CRM_Contribute_DAO_Premium();
274 $dao->entity_table
= 'civicrm_contribution_page';
275 $dao->entity_id
= $pageID;
277 $premiumID = $dao->id
;
279 $productID = array();
281 $dao = new CRM_Contribute_DAO_PremiumsProduct();
282 $dao->premiums_id
= $premiumID;
284 while ($dao->fetch()) {
285 $productID[$dao->product_id
] = $dao->product_id
;
288 $tempProduct = array();
289 foreach ($products as $key => $value) {
290 if (!array_key_exists($key, $productID)) {
291 $tempProduct[$key] = $value;
302 * Get all the contribution statuses.
306 * @param string $columnName
308 * array reference of all contribution statuses
310 public static function &contributionStatus($id = NULL, $columnName = 'label') {
311 $cacheKey = $columnName;
312 if (!isset(self
::$contributionStatus[$cacheKey])) {
313 self
::$contributionStatus[$cacheKey] = CRM_Core_OptionGroup
::values('contribution_status',
314 FALSE, FALSE, FALSE, NULL, $columnName
317 $result = self
::$contributionStatus[$cacheKey];
319 $result = CRM_Utils_Array
::value($id, $result);
326 * Get all the Personal campaign pages.
329 * @param null $pageType
333 * array reference of all pcp if any
335 public static function &pcPage($pageType = NULL, $id = NULL) {
336 if (!isset(self
::$pcPage[$pageType])) {
338 $params = "page_type='{$pageType}'";
343 CRM_Core_PseudoConstant
::populate(self
::$pcPage[$pageType],
345 FALSE, 'title', 'is_active', $params
348 $result = self
::$pcPage[$pageType];
350 return $result = CRM_Utils_Array
::value($id, $result);
357 * Get all PCP Statuses.
359 * The static array pcpStatus is returned
362 * @param string $column
364 * array reference of all PCP activity statuses
366 public static function &pcpStatus($column = 'label') {
367 if (NULL === self
::$pcpStatus) {
368 self
::$pcpStatus = array();
370 if (!array_key_exists($column, self
::$pcpStatus)) {
371 self
::$pcpStatus[$column] = array();
373 self
::$pcpStatus[$column] = CRM_Core_OptionGroup
::values('pcp_status', FALSE,
374 FALSE, FALSE, NULL, $column
377 return self
::$pcpStatus[$column];
381 * Get financial account for a Financial type.
384 * @param int $entityId
385 * @param string $accountRelationType
386 * @param string $entityTable
387 * @param string $returnField
390 public static function getRelationalFinancialAccount($entityId, $accountRelationType, $entityTable = 'civicrm_financial_type', $returnField = 'financial_account_id') {
392 'return' => array($returnField),
393 'entity_table' => $entityTable,
394 'entity_id' => $entityId,
396 if ($accountRelationType) {
397 $params['account_relationship.name'] = $accountRelationType;
399 $result = civicrm_api3('EntityFinancialAccount', 'get', $params);
400 if (!$result['count']) {
403 return $result['values'][$result['id']][$returnField];
412 * array reference of all batches if any
414 public static function &batch($id = NULL) {
416 $orderBy = " id DESC ";
417 CRM_Core_PseudoConstant
::populate(
419 'CRM_Batch_DAO_Batch',
429 $result = CRM_Utils_Array
::value($id, self
::$batch);