3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
37 * This class holds all the Pseudo constants that are specific to Contributions. This avoids
38 * polluting the core class and isolates the mass mailer class
40 class CRM_Contribute_PseudoConstant
extends CRM_Core_PseudoConstant
{
47 private static $financialType;
54 private static $financialTypeAccount;
62 private static $financialAccount;
69 private static $contributionPageActive = NULL;
76 private static $contributionPageAll = NULL;
84 private static $paymentInstrument;
92 private static $contributionStatus;
95 * Personal campaign pages
99 private static $pcPage;
102 * status of personal campaign page
106 private static $pcpStatus;
109 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
111 * Get all the financial types
115 * @return array - array reference of all financial types if any
118 public static function &financialType($id = NULL) {
119 if (!self
::$financialType) {
120 $condition = " is_active = 1 ";
121 CRM_Core_PseudoConstant
::populate(
122 self
::$financialType,
123 'CRM_Financial_DAO_FinancialType',
132 $result = CRM_Utils_Array
::value($id, self
::$financialType);
135 return self
::$financialType;
139 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
141 * Get all the financial Accounts
144 * @return array - array reference of all financial accounts if any
147 public static function &financialAccount($id = NULL, $financialAccountTypeId = NULL, $retrieveColumn = 'name', $key = 'id') {
149 if ($financialAccountTypeId) {
150 $condition = " financial_account_type_id = ". $financialAccountTypeId;
152 $cacheKey = "{$id}_{$financialAccountTypeId}_{$retrieveColumn}_{$key}";
153 if (!isset(self
::$financialAccount[$cacheKey])) {
154 CRM_Core_PseudoConstant
::populate(
155 self
::$financialAccount[$cacheKey],
156 'CRM_Financial_DAO_FinancialAccount',
167 $result = CRM_Utils_Array
::value($id, self
::$financialAccount[$cacheKey]);
170 return self
::$financialAccount[$cacheKey];
174 * Flush given pseudoconstant so it can be reread from db
175 * nex time it's requested.
180 * @param boolean $name pseudoconstant to be flushed
183 public static function flush($name = 'cache') {
184 if (isset(self
::$
$name)) {
190 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
192 * Get all the contribution pages
194 * @param integer $id id of the contribution page
195 * @param boolean $all do we want all pages or only active pages
199 * @return array - array reference of all contribution pages if any
202 public static function &contributionPage($id = NULL, $all = FALSE) {
204 $cacheVarToUse = &self
::$contributionPageAll;
207 $cacheVarToUse = &self
::$contributionPageActive;
210 if (!$cacheVarToUse) {
211 CRM_Core_PseudoConstant
::populate($cacheVarToUse,
212 'CRM_Contribute_DAO_ContributionPage',
217 $pageTitle = CRM_Utils_Array
::value($id, $cacheVarToUse);
220 return $cacheVarToUse;
224 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
226 * Get all the payment instruments
230 * @return array - 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 * @return array - array reference of all payment instruments if any
251 public static function &creditCard() {
252 return CRM_Core_OptionGroup
::values('accept_creditcard', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
260 * @return array - array of all Premiums if any
263 public static function products($pageID = NULL) {
265 $dao = new CRM_Contribute_DAO_Product();
270 while ($dao->fetch()) {
271 $products[$dao->id
] = $dao->name
;
274 $dao = new CRM_Contribute_DAO_Premium();
275 $dao->entity_table
= 'civicrm_contribution_page';
276 $dao->entity_id
= $pageID;
278 $premiumID = $dao->id
;
280 $productID = array();
282 $dao = new CRM_Contribute_DAO_PremiumsProduct();
283 $dao->premiums_id
= $premiumID;
285 while ($dao->fetch()) {
286 $productID[$dao->product_id
] = $dao->product_id
;
289 $tempProduct = array();
290 foreach ($products as $key => $value) {
291 if (!array_key_exists($key, $productID)) {
292 $tempProduct[$key] = $value;
303 * Get all the contribution statuses
307 * @return array - 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
330 * @return array - 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
362 * @return array - 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 all financial accounts for a Financial type.
381 * The static array $financialTypeAccount is returned
386 * @return array - array reference of all financial accounts for a Financial type
388 public static function financialAccountType($financialTypeId, $relationTypeId = NULL) {
389 if (!CRM_Utils_Array
::value($financialTypeId, self
::$financialTypeAccount)) {
390 $condition = " entity_id = $financialTypeId ";
391 CRM_Core_PseudoConstant
::populate(
392 self
::$financialTypeAccount[$financialTypeId],
393 'CRM_Financial_DAO_EntityFinancialAccount',
395 $retrieve = 'financial_account_id',
399 'account_relationship'
403 if ($relationTypeId) {
404 return CRM_Utils_Array
::value($relationTypeId, self
::$financialTypeAccount[$financialTypeId]);
407 return self
::$financialTypeAccount[$financialTypeId];