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.
100 * Get all the financial types
104 * @param bool $includeDisabled
107 * array reference of all financial types if any
109 public static function &financialType($id = NULL, $includeDisabled = FALSE) {
110 if (!self
::$financialType) {
112 if (!$includeDisabled) {
113 $condition = " is_active = 1 ";
115 CRM_Core_PseudoConstant
::populate(
116 self
::$financialType,
117 'CRM_Financial_DAO_FinancialType',
126 $result = CRM_Utils_Array
::value($id, self
::$financialType);
129 return self
::$financialType;
133 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
135 * Get all the financial Accounts
139 * @param int $financialAccountTypeId
140 * @param string $retrieveColumn
144 * array reference of all financial accounts if any
146 public static function &financialAccount($id = NULL, $financialAccountTypeId = NULL, $retrieveColumn = 'name', $key = 'id') {
148 if ($financialAccountTypeId) {
149 $condition = " financial_account_type_id = " . $financialAccountTypeId;
151 $cacheKey = "{$id}_{$financialAccountTypeId}_{$retrieveColumn}_{$key}";
152 if (!isset(self
::$financialAccount[$cacheKey])) {
153 CRM_Core_PseudoConstant
::populate(
154 self
::$financialAccount[$cacheKey],
155 'CRM_Financial_DAO_FinancialAccount',
166 $result = CRM_Utils_Array
::value($id, self
::$financialAccount[$cacheKey]);
169 return self
::$financialAccount[$cacheKey];
173 * Flush given pseudoconstant so it can be reread from db
174 * nex time it's requested.
177 * @param bool|string $name pseudoconstant to be flushed
179 public static function flush($name = 'cache') {
180 if (isset(self
::$
$name)) {
186 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
188 * Get all the contribution pages
191 * Id of the contribution page.
193 * Do we want all pages or only active pages.
197 * array reference of all contribution pages if any
199 public static function &contributionPage($id = NULL, $all = FALSE) {
201 $cacheVarToUse = &self
::$contributionPageAll;
204 $cacheVarToUse = &self
::$contributionPageActive;
207 if (!$cacheVarToUse) {
208 CRM_Core_PseudoConstant
::populate($cacheVarToUse,
209 'CRM_Contribute_DAO_ContributionPage',
214 $pageTitle = CRM_Utils_Array
::value($id, $cacheVarToUse);
217 return $cacheVarToUse;
221 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
223 * Get all the payment instruments
226 * @param string $columnName
229 * array reference of all payment instruments if any
231 public static function &paymentInstrument($columnName = 'label') {
232 if (!isset(self
::$paymentInstrument[$columnName])) {
233 self
::$paymentInstrument[$columnName] = CRM_Core_OptionGroup
::values('payment_instrument',
234 FALSE, FALSE, FALSE, NULL, $columnName
238 return self
::$paymentInstrument[$columnName];
242 * Get all the valid accepted credit cards.
246 * array reference of all payment instruments if any
248 public static function &creditCard() {
249 return CRM_Core_OptionGroup
::values('accept_creditcard', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
258 * array of all Premiums if any
260 public static function products($pageID = NULL) {
262 $dao = new CRM_Contribute_DAO_Product();
267 while ($dao->fetch()) {
268 $products[$dao->id
] = $dao->name
;
271 $dao = new CRM_Contribute_DAO_Premium();
272 $dao->entity_table
= 'civicrm_contribution_page';
273 $dao->entity_id
= $pageID;
275 $premiumID = $dao->id
;
277 $productID = array();
279 $dao = new CRM_Contribute_DAO_PremiumsProduct();
280 $dao->premiums_id
= $premiumID;
282 while ($dao->fetch()) {
283 $productID[$dao->product_id
] = $dao->product_id
;
286 $tempProduct = array();
287 foreach ($products as $key => $value) {
288 if (!array_key_exists($key, $productID)) {
289 $tempProduct[$key] = $value;
300 * Get all the contribution statuses.
304 * @param string $columnName
306 * array reference of all contribution statuses
308 public static function &contributionStatus($id = NULL, $columnName = 'label') {
309 $cacheKey = $columnName;
310 if (!isset(self
::$contributionStatus[$cacheKey])) {
311 self
::$contributionStatus[$cacheKey] = CRM_Core_OptionGroup
::values('contribution_status',
312 FALSE, FALSE, FALSE, NULL, $columnName
315 $result = self
::$contributionStatus[$cacheKey];
317 $result = CRM_Utils_Array
::value($id, $result);
324 * Get all the Personal campaign pages.
327 * @param null $pageType
331 * array reference of all pcp if any
333 public static function &pcPage($pageType = NULL, $id = NULL) {
334 if (!isset(self
::$pcPage[$pageType])) {
336 $params = "page_type='{$pageType}'";
341 CRM_Core_PseudoConstant
::populate(self
::$pcPage[$pageType],
343 FALSE, 'title', 'is_active', $params
346 $result = self
::$pcPage[$pageType];
348 return $result = CRM_Utils_Array
::value($id, $result);
355 * Get all PCP Statuses.
357 * The static array pcpStatus is returned
360 * @param string $column
362 * array reference of all PCP activity statuses
364 public static function &pcpStatus($column = 'label') {
365 if (NULL === self
::$pcpStatus) {
366 self
::$pcpStatus = array();
368 if (!array_key_exists($column, self
::$pcpStatus)) {
369 self
::$pcpStatus[$column] = array();
371 self
::$pcpStatus[$column] = CRM_Core_OptionGroup
::values('pcp_status', FALSE,
372 FALSE, FALSE, NULL, $column
375 return self
::$pcpStatus[$column];
379 * Get financial account for a Financial type.
382 * @param int $entityId
383 * @param string $accountRelationType
384 * @param string $entityTable
385 * @param string $returnField
388 public static function getRelationalFinancialAccount($entityId, $accountRelationType, $entityTable = 'civicrm_financial_type', $returnField = 'financial_account_id') {
390 'return' => array($returnField),
391 'entity_table' => $entityTable,
392 'entity_id' => $entityId,
394 if ($accountRelationType) {
395 $params['account_relationship.name'] = $accountRelationType;
397 $result = civicrm_api3('EntityFinancialAccount', 'get', $params);
398 if (!$result['count']) {
401 return $result['values'][$result['id']][$returnField];
410 * array reference of all batches if any
412 public static function &batch($id = NULL) {
414 $orderBy = " id DESC ";
415 CRM_Core_PseudoConstant
::populate(
417 'CRM_Batch_DAO_Batch',
427 $result = CRM_Utils_Array
::value($id, self
::$batch);