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 * contribution / financial batches
121 private static $batch;
124 * Get all the financial types
128 * @return array - array reference of all financial types if any
131 public static function &financialType($id = NULL) {
132 if (!self
::$financialType) {
133 $condition = " is_active = 1 ";
134 CRM_Core_PseudoConstant
::populate(
135 self
::$financialType,
136 'CRM_Financial_DAO_FinancialType',
145 $result = CRM_Utils_Array
::value($id, self
::$financialType);
148 return self
::$financialType;
152 * Get all the financial Accounts
155 * @return array - array reference of all financial accounts if any
158 public static function &financialAccount($id = NULL, $financialAccountTypeId = NULL, $retrieveColumn = 'name', $key = 'id') {
160 if ($financialAccountTypeId) {
161 $condition = " financial_account_type_id = ". $financialAccountTypeId;
163 $cacheKey = "{$id}_{$financialAccountTypeId}_{$retrieveColumn}_{$key}";
164 if (!isset(self
::$financialAccount[$cacheKey])) {
165 CRM_Core_PseudoConstant
::populate(
166 self
::$financialAccount[$cacheKey],
167 'CRM_Financial_DAO_FinancialAccount',
178 $result = CRM_Utils_Array
::value($id, self
::$financialAccount[$cacheKey]);
181 return self
::$financialAccount[$cacheKey];
185 * Flush given pseudoconstant so it can be reread from db
186 * nex time it's requested.
191 * @param boolean $name pseudoconstant to be flushed
194 public static function flush($name) {
195 if (isset(self
::$
$name)) {
201 * Get all the contribution pages
203 * @param integer $id id of the contribution page
204 * @param boolean $all do we want all pages or only active pages
208 * @return array - array reference of all contribution pages if any
211 public static function &contributionPage($id = NULL, $all = FALSE) {
213 $cacheVarToUse = &self
::$contributionPageAll;
216 $cacheVarToUse = &self
::$contributionPageActive;
219 if (!$cacheVarToUse) {
220 CRM_Core_PseudoConstant
::populate($cacheVarToUse,
221 'CRM_Contribute_DAO_ContributionPage',
226 $pageTitle = CRM_Utils_Array
::value($id, $cacheVarToUse);
229 return $cacheVarToUse;
233 * Get all the payment instruments
237 * @return array - array reference of all payment instruments if any
240 public static function &paymentInstrument($columnName = 'label') {
241 if (!isset(self
::$paymentInstrument[$columnName])) {
242 self
::$paymentInstrument[$columnName] = CRM_Core_OptionGroup
::values('payment_instrument',
243 FALSE, FALSE, FALSE, NULL, $columnName
247 return self
::$paymentInstrument[$columnName];
251 * Get all the valid accepted credit cards
255 * @return array - array reference of all payment instruments if any
258 public static function &creditCard() {
259 $acceptCreditCard = array();
260 $creditCard = CRM_Core_OptionGroup
::values('accept_creditcard');
263 $creditCard = array();
265 foreach ($creditCard as $key => $value) {
266 $acceptCreditCard[$value] = $value;
268 return $acceptCreditCard;
276 * @return array - array of all Premiums if any
279 public static function products($pageID = NULL) {
281 $dao = new CRM_Contribute_DAO_Product();
286 while ($dao->fetch()) {
287 $products[$dao->id
] = $dao->name
;
290 $dao = new CRM_Contribute_DAO_Premium();
291 $dao->entity_table
= 'civicrm_contribution_page';
292 $dao->entity_id
= $pageID;
294 $premiumID = $dao->id
;
296 $productID = array();
298 $dao = new CRM_Contribute_DAO_PremiumsProduct();
299 $dao->premiums_id
= $premiumID;
301 while ($dao->fetch()) {
302 $productID[$dao->product_id
] = $dao->product_id
;
305 $tempProduct = array();
306 foreach ($products as $key => $value) {
307 if (!array_key_exists($key, $productID)) {
308 $tempProduct[$key] = $value;
319 * Get all the contribution statuses
323 * @return array - array reference of all contribution statuses
326 public static function &contributionStatus($id = NULL, $columnName = 'label') {
327 $cacheKey = $columnName;
328 if (!isset(self
::$contributionStatus[$cacheKey])) {
329 self
::$contributionStatus[$cacheKey] = CRM_Core_OptionGroup
::values('contribution_status',
330 FALSE, FALSE, FALSE, NULL, $columnName
333 $result = self
::$contributionStatus[$cacheKey];
335 $result = CRM_Utils_Array
::value($id, $result);
342 * Get all the Personal campaign pages
346 * @return array - array reference of all pcp if any
349 public static function &pcPage($pageType = NULL, $id = NULL) {
350 if (!isset(self
::$pcPage[$pageType])) {
352 $params = "page_type='{$pageType}'";
357 CRM_Core_PseudoConstant
::populate(self
::$pcPage[$pageType],
359 FALSE, 'title', 'is_active', $params
362 $result = self
::$pcPage[$pageType];
364 return $result = CRM_Utils_Array
::value($id, $result);
371 * Get all PCP Statuses.
373 * The static array pcpStatus is returned
378 * @return array - array reference of all PCP activity statuses
380 public static function &pcpStatus($column = 'label') {
381 if (NULL === self
::$pcpStatus) {
382 self
::$pcpStatus = array();
384 if (!array_key_exists($column, self
::$pcpStatus)) {
385 self
::$pcpStatus[$column] = array();
387 self
::$pcpStatus[$column] = CRM_Core_OptionGroup
::values('pcp_status', FALSE,
388 FALSE, FALSE, NULL, $column
391 return self
::$pcpStatus[$column];
395 * Get all financial accounts for a Financial type.
397 * The static array $financialTypeAccount is returned
402 * @return array - array reference of all financial accounts for a Financial type
404 public static function financialAccountType($financialTypeId, $relationTypeId = NULL) {
405 if (!CRM_Utils_Array
::value($financialTypeId, self
::$financialTypeAccount)) {
406 $condition = " entity_id = $financialTypeId ";
407 CRM_Core_PseudoConstant
::populate(
408 self
::$financialTypeAccount[$financialTypeId],
409 'CRM_Financial_DAO_EntityFinancialAccount',
411 $retrieve = 'financial_account_id',
415 'account_relationship'
419 if ($relationTypeId) {
420 return CRM_Utils_Array
::value($relationTypeId, self
::$financialTypeAccount[$financialTypeId]);
423 return self
::$financialTypeAccount[$financialTypeId];
431 * @return array - array reference of all batches if any
434 public static function &batch($id = NULL) {
436 $orderBy = " id DESC ";
437 CRM_Core_PseudoConstant
::populate(
439 'CRM_Batch_DAO_Batch',
449 $result = CRM_Utils_Array
::value($id, self
::$batch);