3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
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
107 * array reference of all financial types if any
109 public static function &financialType($id = NULL) {
110 if (!self
::$financialType) {
111 $condition = " is_active = 1 ";
112 CRM_Core_PseudoConstant
::populate(
113 self
::$financialType,
114 'CRM_Financial_DAO_FinancialType',
123 $result = CRM_Utils_Array
::value($id, self
::$financialType);
126 return self
::$financialType;
130 * @deprecated. Please use the buildOptions() method in the appropriate BAO object.
132 * Get all the financial Accounts
136 * @param int $financialAccountTypeId
137 * @param string $retrieveColumn
141 * array reference of all financial accounts if any
143 public static function &financialAccount($id = NULL, $financialAccountTypeId = NULL, $retrieveColumn = 'name', $key = 'id') {
145 if ($financialAccountTypeId) {
146 $condition = " financial_account_type_id = " . $financialAccountTypeId;
148 $cacheKey = "{$id}_{$financialAccountTypeId}_{$retrieveColumn}_{$key}";
149 if (!isset(self
::$financialAccount[$cacheKey])) {
150 CRM_Core_PseudoConstant
::populate(
151 self
::$financialAccount[$cacheKey],
152 'CRM_Financial_DAO_FinancialAccount',
163 $result = CRM_Utils_Array
::value($id, self
::$financialAccount[$cacheKey]);
166 return self
::$financialAccount[$cacheKey];
170 * Flush given pseudoconstant so it can be reread from db
171 * nex time it's requested.
174 * @param bool|string $name pseudoconstant to be flushed
176 public static function flush($name = 'cache') {
177 if (isset(self
::$
$name)) {
183 * @deprecated. Please use the buildOptions() method in the appropriate BAO object.
185 * Get all the contribution pages
188 * Id of the contribution page.
190 * Do we want all pages or only active pages.
194 * array reference of all contribution pages if any
196 public static function &contributionPage($id = NULL, $all = FALSE) {
198 $cacheVarToUse = &self
::$contributionPageAll;
201 $cacheVarToUse = &self
::$contributionPageActive;
204 if (!$cacheVarToUse) {
205 CRM_Core_PseudoConstant
::populate($cacheVarToUse,
206 'CRM_Contribute_DAO_ContributionPage',
211 $pageTitle = CRM_Utils_Array
::value($id, $cacheVarToUse);
214 return $cacheVarToUse;
218 * @deprecated. Please use the buildOptions() method in the appropriate BAO object.
220 * Get all the payment instruments
223 * @param string $columnName
226 * array reference of all payment instruments if any
228 public static function &paymentInstrument($columnName = 'label') {
229 if (!isset(self
::$paymentInstrument[$columnName])) {
230 self
::$paymentInstrument[$columnName] = CRM_Core_OptionGroup
::values('payment_instrument',
231 FALSE, FALSE, FALSE, NULL, $columnName
235 return self
::$paymentInstrument[$columnName];
239 * Get all the valid accepted credit cards.
243 * array reference of all payment instruments if any
245 public static function &creditCard() {
246 return CRM_Core_OptionGroup
::values('accept_creditcard', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
255 * array of all Premiums if any
257 public static function products($pageID = NULL) {
259 $dao = new CRM_Contribute_DAO_Product();
264 while ($dao->fetch()) {
265 $products[$dao->id
] = $dao->name
;
268 $dao = new CRM_Contribute_DAO_Premium();
269 $dao->entity_table
= 'civicrm_contribution_page';
270 $dao->entity_id
= $pageID;
272 $premiumID = $dao->id
;
274 $productID = array();
276 $dao = new CRM_Contribute_DAO_PremiumsProduct();
277 $dao->premiums_id
= $premiumID;
279 while ($dao->fetch()) {
280 $productID[$dao->product_id
] = $dao->product_id
;
283 $tempProduct = array();
284 foreach ($products as $key => $value) {
285 if (!array_key_exists($key, $productID)) {
286 $tempProduct[$key] = $value;
297 * Get all the contribution statuses.
301 * @param string $columnName
303 * array reference of all contribution statuses
305 public static function &contributionStatus($id = NULL, $columnName = 'label') {
306 $cacheKey = $columnName;
307 if (!isset(self
::$contributionStatus[$cacheKey])) {
308 self
::$contributionStatus[$cacheKey] = CRM_Core_OptionGroup
::values('contribution_status',
309 FALSE, FALSE, FALSE, NULL, $columnName
312 $result = self
::$contributionStatus[$cacheKey];
314 $result = CRM_Utils_Array
::value($id, $result);
321 * Get all the Personal campaign pages.
324 * @param null $pageType
328 * array reference of all pcp if any
330 public static function &pcPage($pageType = NULL, $id = NULL) {
331 if (!isset(self
::$pcPage[$pageType])) {
333 $params = "page_type='{$pageType}'";
338 CRM_Core_PseudoConstant
::populate(self
::$pcPage[$pageType],
340 FALSE, 'title', 'is_active', $params
343 $result = self
::$pcPage[$pageType];
345 return $result = CRM_Utils_Array
::value($id, $result);
352 * Get all PCP Statuses.
354 * The static array pcpStatus is returned
357 * @param string $column
359 * array reference of all PCP activity statuses
361 public static function &pcpStatus($column = 'label') {
362 if (NULL === self
::$pcpStatus) {
363 self
::$pcpStatus = array();
365 if (!array_key_exists($column, self
::$pcpStatus)) {
366 self
::$pcpStatus[$column] = array();
368 self
::$pcpStatus[$column] = CRM_Core_OptionGroup
::values('pcp_status', FALSE,
369 FALSE, FALSE, NULL, $column
372 return self
::$pcpStatus[$column];
376 * Get financial account for a Financial type.
379 * @param int $entityId
380 * @param string $accountRelationType
381 * @param string $entityTable
382 * @param string $returnField
385 public static function getRelationalFinancialAccount($entityId, $accountRelationType, $entityTable = 'civicrm_financial_type', $returnField = 'financial_account_id') {
387 'return' => array($returnField),
388 'entity_table' => $entityTable,
389 'entity_id' => $entityId,
391 if ($accountRelationType) {
392 $params['account_relationship.name'] = $accountRelationType;
394 $result = civicrm_api3('EntityFinancialAccount', 'get', $params);
395 if (!$result['count']) {
398 return $result['values'][$result['id']][$returnField];
407 * array reference of all batches if any
409 public static function &batch($id = NULL) {
411 $orderBy = " id DESC ";
412 CRM_Core_PseudoConstant
::populate(
414 'CRM_Batch_DAO_Batch',
424 $result = CRM_Utils_Array
::value($id, self
::$batch);