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) {
153 if ($financialAccountTypeId) {
154 $condition = " financial_account_type_id = ". $financialAccountTypeId;
156 $cacheKey = "{$id}_{$financialAccountTypeId}";
157 if (!isset(self
::$financialAccount[$cacheKey])) {
158 CRM_Core_PseudoConstant
::populate(
159 self
::$financialAccount[$cacheKey],
160 'CRM_Financial_DAO_FinancialAccount',
169 $result = CRM_Utils_Array
::value($id, self
::$financialAccount[$cacheKey]);
172 return self
::$financialAccount[$cacheKey];
176 * Flush given pseudoconstant so it can be reread from db
177 * nex time it's requested.
182 * @param boolean $name pseudoconstant to be flushed
185 public static function flush($name) {
190 * Get all the contribution pages
192 * @param integer $id id of the contribution page
193 * @param boolean $all do we want all pages or only active pages
197 * @return array - array reference of all contribution pages if any
200 public static function &contributionPage($id = NULL, $all = FALSE) {
202 $cacheVarToUse = &self
::$contributionPageAll;
205 $cacheVarToUse = &self
::$contributionPageActive;
208 if (!$cacheVarToUse) {
209 CRM_Core_PseudoConstant
::populate($cacheVarToUse,
210 'CRM_Contribute_DAO_ContributionPage',
215 $pageTitle = CRM_Utils_Array
::value($id, $cacheVarToUse);
218 return $cacheVarToUse;
222 * Get all the payment instruments
226 * @return array - array reference of all payment instruments if any
229 public static function &paymentInstrument($columnName = 'label') {
230 if (!isset(self
::$paymentInstrument[$columnName])) {
231 self
::$paymentInstrument[$columnName] = CRM_Core_OptionGroup
::values('payment_instrument',
232 FALSE, FALSE, FALSE, NULL, $columnName
236 return self
::$paymentInstrument[$columnName];
240 * Get all the valid accepted credit cards
244 * @return array - array reference of all payment instruments if any
247 public static function &creditCard() {
248 $acceptCreditCard = array();
249 $creditCard = CRM_Core_OptionGroup
::values('accept_creditcard');
252 $creditCard = array();
254 foreach ($creditCard as $key => $value) {
255 $acceptCreditCard[$value] = $value;
257 return $acceptCreditCard;
265 * @return array - array of all Premiums if any
268 public static function products($pageID = NULL) {
270 $dao = new CRM_Contribute_DAO_Product();
275 while ($dao->fetch()) {
276 $products[$dao->id
] = $dao->name
;
279 $dao = new CRM_Contribute_DAO_Premium();
280 $dao->entity_table
= 'civicrm_contribution_page';
281 $dao->entity_id
= $pageID;
283 $premiumID = $dao->id
;
285 $productID = array();
287 $dao = new CRM_Contribute_DAO_PremiumsProduct();
288 $dao->premiums_id
= $premiumID;
290 while ($dao->fetch()) {
291 $productID[$dao->product_id
] = $dao->product_id
;
294 $tempProduct = array();
295 foreach ($products as $key => $value) {
296 if (!array_key_exists($key, $productID)) {
297 $tempProduct[$key] = $value;
308 * Get all the contribution statuses
312 * @return array - array reference of all contribution statuses
315 public static function &contributionStatus($id = NULL, $columnName = 'label') {
316 $cacheKey = $columnName;
317 if (!isset(self
::$contributionStatus[$cacheKey])) {
318 self
::$contributionStatus[$cacheKey] = CRM_Core_OptionGroup
::values('contribution_status',
319 FALSE, FALSE, FALSE, NULL, $columnName
322 $result = self
::$contributionStatus[$cacheKey];
324 $result = CRM_Utils_Array
::value($id, $result);
331 * Get all the Personal campaign pages
335 * @return array - array reference of all pcp if any
338 public static function &pcPage($pageType = NULL, $id = NULL) {
339 if (!isset(self
::$pcPage[$pageType])) {
341 $params = "page_type='{$pageType}'";
346 CRM_Core_PseudoConstant
::populate(self
::$pcPage[$pageType],
348 FALSE, 'title', 'is_active', $params
351 $result = self
::$pcPage[$pageType];
353 return $result = CRM_Utils_Array
::value($id, $result);
360 * Get all PCP Statuses.
362 * The static array pcpStatus is returned
367 * @return array - array reference of all PCP activity statuses
369 public static function &pcpStatus($column = 'label') {
370 if (NULL === self
::$pcpStatus) {
371 self
::$pcpStatus = array();
373 if (!array_key_exists($column, self
::$pcpStatus)) {
374 self
::$pcpStatus[$column] = array();
376 self
::$pcpStatus[$column] = CRM_Core_OptionGroup
::values('pcp_status', FALSE,
377 FALSE, FALSE, NULL, $column
380 return self
::$pcpStatus[$column];
384 * Get all financial accounts for a Financial type.
386 * The static array $financialTypeAccount is returned
391 * @return array - array reference of all financial accounts for a Financial type
393 public static function financialAccountType($financialTypeId, $relationTypeId = NULL) {
394 if (!CRM_Utils_Array
::value($financialTypeId, self
::$financialTypeAccount)) {
395 $condition = " entity_id = $financialTypeId ";
396 CRM_Core_PseudoConstant
::populate(
397 self
::$financialTypeAccount[$financialTypeId],
398 'CRM_Financial_DAO_EntityFinancialAccount',
400 $retrieve = 'financial_account_id',
404 'account_relationship'
408 if ($relationTypeId) {
409 return CRM_Utils_Array
::value($relationTypeId, self
::$financialTypeAccount[$financialTypeId]);
412 return self
::$financialTypeAccount[$financialTypeId];