3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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
{
46 private static $financialType;
52 private static $financialTypeAccount;
59 private static $financialAccount;
65 private static $contributionPageActive = NULL;
71 private static $contributionPageAll = NULL;
78 private static $paymentInstrument;
85 private static $contributionStatus;
88 * Personal campaign pages
91 private static $pcPage;
94 * Status of personal campaign page
97 private static $pcpStatus;
100 * Contribution / financial batches
103 private static $batch;
106 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
108 * Get all the financial types
114 * array reference of all financial types if any
116 public static function &financialType($id = NULL) {
117 if (!self
::$financialType) {
118 $condition = " is_active = 1 ";
119 CRM_Core_PseudoConstant
::populate(
120 self
::$financialType,
121 'CRM_Financial_DAO_FinancialType',
130 $result = CRM_Utils_Array
::value($id, self
::$financialType);
133 return self
::$financialType;
137 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
139 * Get all the financial Accounts
143 * @param int $financialAccountTypeId
144 * @param string $retrieveColumn
148 * array reference of all financial accounts if any
150 public static function &financialAccount($id = NULL, $financialAccountTypeId = NULL, $retrieveColumn = 'name', $key = 'id') {
152 if ($financialAccountTypeId) {
153 $condition = " financial_account_type_id = " . $financialAccountTypeId;
155 $cacheKey = "{$id}_{$financialAccountTypeId}_{$retrieveColumn}_{$key}";
156 if (!isset(self
::$financialAccount[$cacheKey])) {
157 CRM_Core_PseudoConstant
::populate(
158 self
::$financialAccount[$cacheKey],
159 'CRM_Financial_DAO_FinancialAccount',
170 $result = CRM_Utils_Array
::value($id, self
::$financialAccount[$cacheKey]);
173 return self
::$financialAccount[$cacheKey];
177 * Flush given pseudoconstant so it can be reread from db
178 * nex time it's requested.
181 * @param bool|string $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
195 * Id of the contribution page.
197 * Do we want all pages or only active pages.
201 * array reference of all contribution pages if any
203 public static function &contributionPage($id = NULL, $all = FALSE) {
205 $cacheVarToUse = &self
::$contributionPageAll;
208 $cacheVarToUse = &self
::$contributionPageActive;
211 if (!$cacheVarToUse) {
212 CRM_Core_PseudoConstant
::populate($cacheVarToUse,
213 'CRM_Contribute_DAO_ContributionPage',
218 $pageTitle = CRM_Utils_Array
::value($id, $cacheVarToUse);
221 return $cacheVarToUse;
225 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
227 * Get all the payment instruments
230 * @param string $columnName
233 * array reference of all payment instruments if any
235 public static function &paymentInstrument($columnName = 'label') {
236 if (!isset(self
::$paymentInstrument[$columnName])) {
237 self
::$paymentInstrument[$columnName] = CRM_Core_OptionGroup
::values('payment_instrument',
238 FALSE, FALSE, FALSE, NULL, $columnName
242 return self
::$paymentInstrument[$columnName];
246 * Get all the valid accepted credit cards.
250 * array reference of all payment instruments if any
252 public static function &creditCard() {
253 return CRM_Core_OptionGroup
::values('accept_creditcard', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
262 * array of all Premiums if any
264 public static function products($pageID = NULL) {
266 $dao = new CRM_Contribute_DAO_Product();
271 while ($dao->fetch()) {
272 $products[$dao->id
] = $dao->name
;
275 $dao = new CRM_Contribute_DAO_Premium();
276 $dao->entity_table
= 'civicrm_contribution_page';
277 $dao->entity_id
= $pageID;
279 $premiumID = $dao->id
;
281 $productID = array();
283 $dao = new CRM_Contribute_DAO_PremiumsProduct();
284 $dao->premiums_id
= $premiumID;
286 while ($dao->fetch()) {
287 $productID[$dao->product_id
] = $dao->product_id
;
290 $tempProduct = array();
291 foreach ($products as $key => $value) {
292 if (!array_key_exists($key, $productID)) {
293 $tempProduct[$key] = $value;
304 * Get all the contribution statuses.
308 * @param string $columnName
310 * array reference of all contribution statuses
312 public static function &contributionStatus($id = NULL, $columnName = 'label') {
313 $cacheKey = $columnName;
314 if (!isset(self
::$contributionStatus[$cacheKey])) {
315 self
::$contributionStatus[$cacheKey] = CRM_Core_OptionGroup
::values('contribution_status',
316 FALSE, FALSE, FALSE, NULL, $columnName
319 $result = self
::$contributionStatus[$cacheKey];
321 $result = CRM_Utils_Array
::value($id, $result);
328 * Get all the Personal campaign pages.
331 * @param null $pageType
335 * array reference of all pcp if any
337 public static function &pcPage($pageType = NULL, $id = NULL) {
338 if (!isset(self
::$pcPage[$pageType])) {
340 $params = "page_type='{$pageType}'";
345 CRM_Core_PseudoConstant
::populate(self
::$pcPage[$pageType],
347 FALSE, 'title', 'is_active', $params
350 $result = self
::$pcPage[$pageType];
352 return $result = CRM_Utils_Array
::value($id, $result);
359 * Get all PCP Statuses.
361 * The static array pcpStatus is returned
364 * @param string $column
366 * array reference of all PCP activity statuses
368 public static function &pcpStatus($column = 'label') {
369 if (NULL === self
::$pcpStatus) {
370 self
::$pcpStatus = array();
372 if (!array_key_exists($column, self
::$pcpStatus)) {
373 self
::$pcpStatus[$column] = array();
375 self
::$pcpStatus[$column] = CRM_Core_OptionGroup
::values('pcp_status', FALSE,
376 FALSE, FALSE, NULL, $column
379 return self
::$pcpStatus[$column];
383 * Get all financial accounts for a Financial type.
385 * The static array $financialTypeAccount is returned
388 * @param int $financialTypeId
389 * @param int $relationTypeId
391 * 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];
421 * array reference of all batches if any
423 public static function &batch($id = NULL) {
425 $orderBy = " id DESC ";
426 CRM_Core_PseudoConstant
::populate(
428 'CRM_Batch_DAO_Batch',
438 $result = CRM_Utils_Array
::value($id, self
::$batch);