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
124 * @return array - array reference of all financial types if any
127 public static function &financialType($id = NULL) {
128 if (!self
::$financialType) {
129 $condition = " is_active = 1 ";
130 CRM_Core_PseudoConstant
::populate(
131 self
::$financialType,
132 'CRM_Financial_DAO_FinancialType',
141 $result = CRM_Utils_Array
::value($id, self
::$financialType);
144 return self
::$financialType;
148 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
150 * Get all the financial Accounts
155 * @param null $financialAccountTypeId
156 * @param string $retrieveColumn
159 * @return array - array reference of all financial accounts if any
162 public static function &financialAccount($id = NULL, $financialAccountTypeId = NULL, $retrieveColumn = 'name', $key = 'id') {
164 if ($financialAccountTypeId) {
165 $condition = " financial_account_type_id = ". $financialAccountTypeId;
167 $cacheKey = "{$id}_{$financialAccountTypeId}_{$retrieveColumn}_{$key}";
168 if (!isset(self
::$financialAccount[$cacheKey])) {
169 CRM_Core_PseudoConstant
::populate(
170 self
::$financialAccount[$cacheKey],
171 'CRM_Financial_DAO_FinancialAccount',
182 $result = CRM_Utils_Array
::value($id, self
::$financialAccount[$cacheKey]);
185 return self
::$financialAccount[$cacheKey];
189 * Flush given pseudoconstant so it can be reread from db
190 * nex time it's requested.
195 * @param bool|string $name pseudoconstant to be flushed
197 public static function flush($name = 'cache') {
198 if (isset(self
::$
$name)) {
204 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
206 * Get all the contribution pages
208 * @param integer $id id of the contribution page
209 * @param boolean $all do we want all pages or only active pages
213 * @return array - array reference of all contribution pages if any
216 public static function &contributionPage($id = NULL, $all = FALSE) {
218 $cacheVarToUse = &self
::$contributionPageAll;
221 $cacheVarToUse = &self
::$contributionPageActive;
224 if (!$cacheVarToUse) {
225 CRM_Core_PseudoConstant
::populate($cacheVarToUse,
226 'CRM_Contribute_DAO_ContributionPage',
231 $pageTitle = CRM_Utils_Array
::value($id, $cacheVarToUse);
234 return $cacheVarToUse;
238 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
240 * Get all the payment instruments
244 * @param string $columnName
246 * @return array - array reference of all payment instruments if any
249 public static function &paymentInstrument($columnName = 'label') {
250 if (!isset(self
::$paymentInstrument[$columnName])) {
251 self
::$paymentInstrument[$columnName] = CRM_Core_OptionGroup
::values('payment_instrument',
252 FALSE, FALSE, FALSE, NULL, $columnName
256 return self
::$paymentInstrument[$columnName];
260 * Get all the valid accepted credit cards
264 * @return array - array reference of all payment instruments if any
267 public static function &creditCard() {
268 return CRM_Core_OptionGroup
::values('accept_creditcard', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
276 * @param null $pageID
277 * @return array - array of all Premiums if any
280 public static function products($pageID = NULL) {
282 $dao = new CRM_Contribute_DAO_Product();
287 while ($dao->fetch()) {
288 $products[$dao->id
] = $dao->name
;
291 $dao = new CRM_Contribute_DAO_Premium();
292 $dao->entity_table
= 'civicrm_contribution_page';
293 $dao->entity_id
= $pageID;
295 $premiumID = $dao->id
;
297 $productID = array();
299 $dao = new CRM_Contribute_DAO_PremiumsProduct();
300 $dao->premiums_id
= $premiumID;
302 while ($dao->fetch()) {
303 $productID[$dao->product_id
] = $dao->product_id
;
306 $tempProduct = array();
307 foreach ($products as $key => $value) {
308 if (!array_key_exists($key, $productID)) {
309 $tempProduct[$key] = $value;
320 * Get all the contribution statuses
325 * @param string $columnName
326 * @return array - array reference of all contribution statuses
329 public static function &contributionStatus($id = NULL, $columnName = 'label') {
330 $cacheKey = $columnName;
331 if (!isset(self
::$contributionStatus[$cacheKey])) {
332 self
::$contributionStatus[$cacheKey] = CRM_Core_OptionGroup
::values('contribution_status',
333 FALSE, FALSE, FALSE, NULL, $columnName
336 $result = self
::$contributionStatus[$cacheKey];
338 $result = CRM_Utils_Array
::value($id, $result);
345 * Get all the Personal campaign pages
349 * @param null $pageType
352 * @return array - array reference of all pcp if any
355 public static function &pcPage($pageType = NULL, $id = NULL) {
356 if (!isset(self
::$pcPage[$pageType])) {
358 $params = "page_type='{$pageType}'";
363 CRM_Core_PseudoConstant
::populate(self
::$pcPage[$pageType],
365 FALSE, 'title', 'is_active', $params
368 $result = self
::$pcPage[$pageType];
370 return $result = CRM_Utils_Array
::value($id, $result);
377 * Get all PCP Statuses.
379 * The static array pcpStatus is returned
384 * @param string $column
385 * @return array - array reference of all PCP activity statuses
387 public static function &pcpStatus($column = 'label') {
388 if (NULL === self
::$pcpStatus) {
389 self
::$pcpStatus = array();
391 if (!array_key_exists($column, self
::$pcpStatus)) {
392 self
::$pcpStatus[$column] = array();
394 self
::$pcpStatus[$column] = CRM_Core_OptionGroup
::values('pcp_status', FALSE,
395 FALSE, FALSE, NULL, $column
398 return self
::$pcpStatus[$column];
402 * Get all financial accounts for a Financial type.
404 * The static array $financialTypeAccount is returned
409 * @param $financialTypeId
410 * @param null $relationTypeId
411 * @return array - array reference of all financial accounts for a Financial type
413 public static function financialAccountType($financialTypeId, $relationTypeId = NULL) {
414 if (!CRM_Utils_Array
::value($financialTypeId, self
::$financialTypeAccount)) {
415 $condition = " entity_id = $financialTypeId ";
416 CRM_Core_PseudoConstant
::populate(
417 self
::$financialTypeAccount[$financialTypeId],
418 'CRM_Financial_DAO_EntityFinancialAccount',
420 $retrieve = 'financial_account_id',
424 'account_relationship'
428 if ($relationTypeId) {
429 return CRM_Utils_Array
::value($relationTypeId, self
::$financialTypeAccount[$financialTypeId]);
432 return self
::$financialTypeAccount[$financialTypeId];
441 * @return array - array reference of all batches if any
444 public static function &batch($id = NULL) {
446 $orderBy = " id DESC ";
447 CRM_Core_PseudoConstant
::populate(
449 'CRM_Batch_DAO_Batch',
459 $result = CRM_Utils_Array
::value($id, self
::$batch);