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 $creditCard;
100 private static $contributionStatus;
103 * Personal campaign pages
107 private static $pcPage;
110 * status of personal campaign page
114 private static $pcpStatus;
117 * Get all the financial types
121 * @return array - array reference of all financial types if any
124 public static function &financialType($id = NULL) {
125 if (!self
::$financialType) {
126 $condition = " is_active = 1 ";
127 CRM_Core_PseudoConstant
::populate(
128 self
::$financialType,
129 'CRM_Financial_DAO_FinancialType',
138 $result = CRM_Utils_Array
::value($id, self
::$financialType);
141 return self
::$financialType;
145 * Get all the financial Accounts
148 * @return array - array reference of all financial accounts if any
151 public static function &financialAccount($id = NULL, $financialAccountTypeId = NULL, $retrieveColumn = 'name', $key = 'id') {
153 if ($financialAccountTypeId) {
154 $condition = " financial_account_type_id = ". $financialAccountTypeId;
156 $cacheKey = "{$id}_{$financialAccountTypeId}_{$retrieveColumn}_{$key}";
157 if (!isset(self
::$financialAccount[$cacheKey])) {
158 CRM_Core_PseudoConstant
::populate(
159 self
::$financialAccount[$cacheKey],
160 'CRM_Financial_DAO_FinancialAccount',
171 $result = CRM_Utils_Array
::value($id, self
::$financialAccount[$cacheKey]);
174 return self
::$financialAccount[$cacheKey];
178 * Flush given pseudoconstant so it can be reread from db
179 * nex time it's requested.
184 * @param boolean $name pseudoconstant to be flushed
187 public static function flush($name) {
188 if (isset(self
::$
$name)) {
194 * Get all the contribution pages
196 * @param integer $id id of the contribution page
197 * @param boolean $all do we want all pages or only active pages
201 * @return array - array reference of all contribution pages if any
204 public static function &contributionPage($id = NULL, $all = FALSE) {
206 $cacheVarToUse = &self
::$contributionPageAll;
209 $cacheVarToUse = &self
::$contributionPageActive;
212 if (!$cacheVarToUse) {
213 CRM_Core_PseudoConstant
::populate($cacheVarToUse,
214 'CRM_Contribute_DAO_ContributionPage',
219 $pageTitle = CRM_Utils_Array
::value($id, $cacheVarToUse);
222 return $cacheVarToUse;
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 $acceptCreditCard = array();
253 $creditCard = CRM_Core_OptionGroup
::values('accept_creditcard');
256 $creditCard = array();
258 foreach ($creditCard as $key => $value) {
259 $acceptCreditCard[$value] = $value;
261 return $acceptCreditCard;
269 * @return array - array of all Premiums if any
272 public static function products($pageID = NULL) {
274 $dao = new CRM_Contribute_DAO_Product();
279 while ($dao->fetch()) {
280 $products[$dao->id
] = $dao->name
;
283 $dao = new CRM_Contribute_DAO_Premium();
284 $dao->entity_table
= 'civicrm_contribution_page';
285 $dao->entity_id
= $pageID;
287 $premiumID = $dao->id
;
289 $productID = array();
291 $dao = new CRM_Contribute_DAO_PremiumsProduct();
292 $dao->premiums_id
= $premiumID;
294 while ($dao->fetch()) {
295 $productID[$dao->product_id
] = $dao->product_id
;
298 $tempProduct = array();
299 foreach ($products as $key => $value) {
300 if (!array_key_exists($key, $productID)) {
301 $tempProduct[$key] = $value;
312 * Get all the contribution statuses
316 * @return array - array reference of all contribution statuses
319 public static function &contributionStatus($id = NULL, $columnName = 'label') {
320 $cacheKey = $columnName;
321 if (!isset(self
::$contributionStatus[$cacheKey])) {
322 self
::$contributionStatus[$cacheKey] = CRM_Core_OptionGroup
::values('contribution_status',
323 FALSE, FALSE, FALSE, NULL, $columnName
326 $result = self
::$contributionStatus[$cacheKey];
328 $result = CRM_Utils_Array
::value($id, $result);
335 * Get all the Personal campaign pages
339 * @return array - array reference of all pcp if any
342 public static function &pcPage($pageType = NULL, $id = NULL) {
343 if (!isset(self
::$pcPage[$pageType])) {
345 $params = "page_type='{$pageType}'";
350 CRM_Core_PseudoConstant
::populate(self
::$pcPage[$pageType],
352 FALSE, 'title', 'is_active', $params
355 $result = self
::$pcPage[$pageType];
357 return $result = CRM_Utils_Array
::value($id, $result);
364 * Get all PCP Statuses.
366 * The static array pcpStatus is returned
371 * @return array - array reference of all PCP activity statuses
373 public static function &pcpStatus($column = 'label') {
374 if (NULL === self
::$pcpStatus) {
375 self
::$pcpStatus = array();
377 if (!array_key_exists($column, self
::$pcpStatus)) {
378 self
::$pcpStatus[$column] = array();
380 self
::$pcpStatus[$column] = CRM_Core_OptionGroup
::values('pcp_status', FALSE,
381 FALSE, FALSE, NULL, $column
384 return self
::$pcpStatus[$column];
388 * Get all financial accounts for a Financial type.
390 * The static array $financialTypeAccount is returned
395 * @return array - array reference of all financial accounts for a Financial type
397 public static function financialAccountType($financialTypeId, $relationTypeId = NULL) {
398 if (!CRM_Utils_Array
::value($financialTypeId, self
::$financialTypeAccount)) {
399 $condition = " entity_id = $financialTypeId ";
400 CRM_Core_PseudoConstant
::populate(
401 self
::$financialTypeAccount[$financialTypeId],
402 'CRM_Financial_DAO_EntityFinancialAccount',
404 $retrieve = 'financial_account_id',
408 'account_relationship'
412 if ($relationTypeId) {
413 return CRM_Utils_Array
::value($relationTypeId, self
::$financialTypeAccount[$financialTypeId]);
416 return self
::$financialTypeAccount[$financialTypeId];