3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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 * contribution / financial batches
113 private static $batch;
116 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
118 * Get all the financial types
122 * @return array - array reference of all financial types if any
125 public static function &financialType($id = NULL) {
126 if (!self
::$financialType) {
127 $condition = " is_active = 1 ";
128 CRM_Core_PseudoConstant
::populate(
129 self
::$financialType,
130 'CRM_Financial_DAO_FinancialType',
139 $result = CRM_Utils_Array
::value($id, self
::$financialType);
142 return self
::$financialType;
146 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
148 * Get all the financial Accounts
151 * @return array - array reference of all financial accounts if any
154 public static function &financialAccount($id = NULL, $financialAccountTypeId = NULL, $retrieveColumn = 'name', $key = 'id') {
156 if ($financialAccountTypeId) {
157 $condition = " financial_account_type_id = ". $financialAccountTypeId;
159 $cacheKey = "{$id}_{$financialAccountTypeId}_{$retrieveColumn}_{$key}";
160 if (!isset(self
::$financialAccount[$cacheKey])) {
161 CRM_Core_PseudoConstant
::populate(
162 self
::$financialAccount[$cacheKey],
163 'CRM_Financial_DAO_FinancialAccount',
174 $result = CRM_Utils_Array
::value($id, self
::$financialAccount[$cacheKey]);
177 return self
::$financialAccount[$cacheKey];
181 * Flush given pseudoconstant so it can be reread from db
182 * nex time it's requested.
187 * @param boolean $name pseudoconstant to be flushed
190 public static function flush($name = 'cache') {
191 if (isset(self
::$
$name)) {
197 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
199 * Get all the contribution pages
201 * @param integer $id id of the contribution page
202 * @param boolean $all do we want all pages or only active pages
206 * @return array - array reference of all contribution pages if any
209 public static function &contributionPage($id = NULL, $all = FALSE) {
211 $cacheVarToUse = &self
::$contributionPageAll;
214 $cacheVarToUse = &self
::$contributionPageActive;
217 if (!$cacheVarToUse) {
218 CRM_Core_PseudoConstant
::populate($cacheVarToUse,
219 'CRM_Contribute_DAO_ContributionPage',
224 $pageTitle = CRM_Utils_Array
::value($id, $cacheVarToUse);
227 return $cacheVarToUse;
231 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
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 return CRM_Core_OptionGroup
::values('accept_creditcard', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
267 * @return array - array of all Premiums if any
270 public static function products($pageID = NULL) {
272 $dao = new CRM_Contribute_DAO_Product();
277 while ($dao->fetch()) {
278 $products[$dao->id
] = $dao->name
;
281 $dao = new CRM_Contribute_DAO_Premium();
282 $dao->entity_table
= 'civicrm_contribution_page';
283 $dao->entity_id
= $pageID;
285 $premiumID = $dao->id
;
287 $productID = array();
289 $dao = new CRM_Contribute_DAO_PremiumsProduct();
290 $dao->premiums_id
= $premiumID;
292 while ($dao->fetch()) {
293 $productID[$dao->product_id
] = $dao->product_id
;
296 $tempProduct = array();
297 foreach ($products as $key => $value) {
298 if (!array_key_exists($key, $productID)) {
299 $tempProduct[$key] = $value;
310 * Get all the contribution statuses
314 * @return array - array reference of all contribution statuses
317 public static function &contributionStatus($id = NULL, $columnName = 'label') {
318 $cacheKey = $columnName;
319 if (!isset(self
::$contributionStatus[$cacheKey])) {
320 self
::$contributionStatus[$cacheKey] = CRM_Core_OptionGroup
::values('contribution_status',
321 FALSE, FALSE, FALSE, NULL, $columnName
324 $result = self
::$contributionStatus[$cacheKey];
326 $result = CRM_Utils_Array
::value($id, $result);
333 * Get all the Personal campaign pages
337 * @return array - array reference of all pcp if any
340 public static function &pcPage($pageType = NULL, $id = NULL) {
341 if (!isset(self
::$pcPage[$pageType])) {
343 $params = "page_type='{$pageType}'";
348 CRM_Core_PseudoConstant
::populate(self
::$pcPage[$pageType],
350 FALSE, 'title', 'is_active', $params
353 $result = self
::$pcPage[$pageType];
355 return $result = CRM_Utils_Array
::value($id, $result);
362 * Get all PCP Statuses.
364 * The static array pcpStatus is returned
369 * @return array - array reference of all PCP activity statuses
371 public static function &pcpStatus($column = 'label') {
372 if (NULL === self
::$pcpStatus) {
373 self
::$pcpStatus = array();
375 if (!array_key_exists($column, self
::$pcpStatus)) {
376 self
::$pcpStatus[$column] = array();
378 self
::$pcpStatus[$column] = CRM_Core_OptionGroup
::values('pcp_status', FALSE,
379 FALSE, FALSE, NULL, $column
382 return self
::$pcpStatus[$column];
386 * Get all financial accounts for a Financial type.
388 * The static array $financialTypeAccount is returned
393 * @return array - array reference of all financial accounts for a Financial type
395 public static function financialAccountType($financialTypeId, $relationTypeId = NULL) {
396 if (!CRM_Utils_Array
::value($financialTypeId, self
::$financialTypeAccount)) {
397 $condition = " entity_id = $financialTypeId ";
398 CRM_Core_PseudoConstant
::populate(
399 self
::$financialTypeAccount[$financialTypeId],
400 'CRM_Financial_DAO_EntityFinancialAccount',
402 $retrieve = 'financial_account_id',
406 'account_relationship'
410 if ($relationTypeId) {
411 return CRM_Utils_Array
::value($relationTypeId, self
::$financialTypeAccount[$financialTypeId]);
414 return self
::$financialTypeAccount[$financialTypeId];
422 * @return array - array reference of all batches if any
425 public static function &batch($id = NULL) {
427 $orderBy = " id DESC ";
428 CRM_Core_PseudoConstant
::populate(
430 'CRM_Batch_DAO_Batch',
440 $result = CRM_Utils_Array
::value($id, self
::$batch);