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
{
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
123 * @return array - array reference of all financial types if any
126 public static function &financialType($id = NULL) {
127 if (!self
::$financialType) {
128 $condition = " is_active = 1 ";
129 CRM_Core_PseudoConstant
::populate(
130 self
::$financialType,
131 'CRM_Financial_DAO_FinancialType',
140 $result = CRM_Utils_Array
::value($id, self
::$financialType);
143 return self
::$financialType;
147 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
149 * Get all the financial Accounts
153 * @param int $financialAccountTypeId
154 * @param string $retrieveColumn
157 * @return array - array reference of all financial accounts if any
160 public static function &financialAccount($id = NULL, $financialAccountTypeId = NULL, $retrieveColumn = 'name', $key = 'id') {
162 if ($financialAccountTypeId) {
163 $condition = " financial_account_type_id = ". $financialAccountTypeId;
165 $cacheKey = "{$id}_{$financialAccountTypeId}_{$retrieveColumn}_{$key}";
166 if (!isset(self
::$financialAccount[$cacheKey])) {
167 CRM_Core_PseudoConstant
::populate(
168 self
::$financialAccount[$cacheKey],
169 'CRM_Financial_DAO_FinancialAccount',
180 $result = CRM_Utils_Array
::value($id, self
::$financialAccount[$cacheKey]);
183 return self
::$financialAccount[$cacheKey];
187 * Flush given pseudoconstant so it can be reread from db
188 * nex time it's requested.
192 * @param bool|string $name pseudoconstant to be flushed
194 public static function flush($name = 'cache') {
195 if (isset(self
::$
$name)) {
201 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
203 * Get all the contribution pages
205 * @param integer $id id of the contribution page
206 * @param boolean $all do we want all pages or only active pages
209 * @return array - array reference of all contribution pages if any
212 public static function &contributionPage($id = NULL, $all = FALSE) {
214 $cacheVarToUse = &self
::$contributionPageAll;
217 $cacheVarToUse = &self
::$contributionPageActive;
220 if (!$cacheVarToUse) {
221 CRM_Core_PseudoConstant
::populate($cacheVarToUse,
222 'CRM_Contribute_DAO_ContributionPage',
227 $pageTitle = CRM_Utils_Array
::value($id, $cacheVarToUse);
230 return $cacheVarToUse;
234 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
236 * Get all the payment instruments
239 * @param string $columnName
241 * @return array - array reference of all payment instruments if any
244 public static function &paymentInstrument($columnName = 'label') {
245 if (!isset(self
::$paymentInstrument[$columnName])) {
246 self
::$paymentInstrument[$columnName] = CRM_Core_OptionGroup
::values('payment_instrument',
247 FALSE, FALSE, FALSE, NULL, $columnName
251 return self
::$paymentInstrument[$columnName];
255 * Get all the valid accepted credit cards
258 * @return array - array reference of all payment instruments if any
261 public static function &creditCard() {
262 return CRM_Core_OptionGroup
::values('accept_creditcard', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
270 * @return array - array of all Premiums if any
273 public static function products($pageID = NULL) {
275 $dao = new CRM_Contribute_DAO_Product();
280 while ($dao->fetch()) {
281 $products[$dao->id
] = $dao->name
;
284 $dao = new CRM_Contribute_DAO_Premium();
285 $dao->entity_table
= 'civicrm_contribution_page';
286 $dao->entity_id
= $pageID;
288 $premiumID = $dao->id
;
290 $productID = array();
292 $dao = new CRM_Contribute_DAO_PremiumsProduct();
293 $dao->premiums_id
= $premiumID;
295 while ($dao->fetch()) {
296 $productID[$dao->product_id
] = $dao->product_id
;
299 $tempProduct = array();
300 foreach ($products as $key => $value) {
301 if (!array_key_exists($key, $productID)) {
302 $tempProduct[$key] = $value;
313 * Get all the contribution statuses
317 * @param string $columnName
318 * @return array - array reference of all contribution statuses
321 public static function &contributionStatus($id = NULL, $columnName = 'label') {
322 $cacheKey = $columnName;
323 if (!isset(self
::$contributionStatus[$cacheKey])) {
324 self
::$contributionStatus[$cacheKey] = CRM_Core_OptionGroup
::values('contribution_status',
325 FALSE, FALSE, FALSE, NULL, $columnName
328 $result = self
::$contributionStatus[$cacheKey];
330 $result = CRM_Utils_Array
::value($id, $result);
337 * Get all the Personal campaign pages
340 * @param null $pageType
343 * @return array - array reference of all pcp if any
346 public static function &pcPage($pageType = NULL, $id = NULL) {
347 if (!isset(self
::$pcPage[$pageType])) {
349 $params = "page_type='{$pageType}'";
354 CRM_Core_PseudoConstant
::populate(self
::$pcPage[$pageType],
356 FALSE, 'title', 'is_active', $params
359 $result = self
::$pcPage[$pageType];
361 return $result = CRM_Utils_Array
::value($id, $result);
368 * Get all PCP Statuses.
370 * The static array pcpStatus is returned
374 * @param string $column
375 * @return array - array reference of all PCP activity statuses
377 public static function &pcpStatus($column = 'label') {
378 if (NULL === self
::$pcpStatus) {
379 self
::$pcpStatus = array();
381 if (!array_key_exists($column, self
::$pcpStatus)) {
382 self
::$pcpStatus[$column] = array();
384 self
::$pcpStatus[$column] = CRM_Core_OptionGroup
::values('pcp_status', FALSE,
385 FALSE, FALSE, NULL, $column
388 return self
::$pcpStatus[$column];
392 * Get all financial accounts for a Financial type.
394 * The static array $financialTypeAccount is returned
398 * @param int $financialTypeId
399 * @param int $relationTypeId
400 * @return array - array reference of all financial accounts for a Financial type
402 public static function financialAccountType($financialTypeId, $relationTypeId = NULL) {
403 if (!CRM_Utils_Array
::value($financialTypeId, self
::$financialTypeAccount)) {
404 $condition = " entity_id = $financialTypeId ";
405 CRM_Core_PseudoConstant
::populate(
406 self
::$financialTypeAccount[$financialTypeId],
407 'CRM_Financial_DAO_EntityFinancialAccount',
409 $retrieve = 'financial_account_id',
413 'account_relationship'
417 if ($relationTypeId) {
418 return CRM_Utils_Array
::value($relationTypeId, self
::$financialTypeAccount[$financialTypeId]);
421 return self
::$financialTypeAccount[$financialTypeId];
429 * @return array - array reference of all batches if any
432 public static function &batch($id = NULL) {
434 $orderBy = " id DESC ";
435 CRM_Core_PseudoConstant
::populate(
437 'CRM_Batch_DAO_Batch',
447 $result = CRM_Utils_Array
::value($id, self
::$batch);