Merge pull request #4893 from colemanw/INFRA-132
[civicrm-core.git] / CRM / Contribute / PseudoConstant.php
index fc0085ffa61b5e60fd9de4ab40c7ed2c90c6bab9..8128236b90205eb6db5e0d746dc7eceefb7d595f 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
 class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
 
   /**
-   * financial types
+   * Financial types
    * @var array
    * @static
    */
   private static $financialType;
 
   /**
-   * financial types
+   * Financial types
    * @var array
    * @static
    */
@@ -55,28 +55,28 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
 
 
   /**
-   * financial types
+   * Financial types
    * @var array
    * @static
    */
   private static $financialAccount;
 
-    /**
-   * contribution pages
-   * @var array
-   * @static
-   */
+  /**
+     * Contribution pages
+     * @var array
+     * @static
+     */
   private static $contributionPageActive = NULL;
 
   /**
-   * contribution pages
+   * Contribution pages
    * @var array
    * @static
    */
   private static $contributionPageAll = NULL;
 
   /**
-   * payment instruments
+   * Payment instruments
    *
    * @var array
    * @static
@@ -84,41 +84,44 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
   private static $paymentInstrument;
 
   /**
-   * credit card
+   * Contribution status
    *
    * @var array
    * @static
    */
-  private static $creditCard;
+  private static $contributionStatus;
 
   /**
-   * contribution status
-   *
+   * Personal campaign pages
    * @var array
    * @static
    */
-  private static $contributionStatus;
+  private static $pcPage;
 
   /**
-   * Personal campaign pages
+   * Status of personal campaign page
    * @var array
    * @static
    */
-  private static $pcPage;
+  private static $pcpStatus;
 
   /**
-   * status of personal campaign page
+   * Contribution / financial batches
    * @var array
    * @static
    */
-  private static $pcpStatus;
+  private static $batch;
 
   /**
+   * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
+   *
    * Get all the financial types
    *
-   * @access public
    *
-   * @return array - array reference of all financial types if any
+   * @param int $id
+   *
+   * @return array
+   *   array reference of all financial types if any
    * @static
    */
   public static function &financialType($id = NULL) {
@@ -142,16 +145,24 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
   }
 
   /**
+   * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
+   *
    * Get all the financial Accounts
    *
-   * @access public
-   * @return array - array reference of all financial accounts if any
+   *
+   * @param int $id
+   * @param int $financialAccountTypeId
+   * @param string $retrieveColumn
+   * @param string $key
+   *
+   * @return array
+   *   array reference of all financial accounts if any
    * @static
    */
   public static function &financialAccount($id = NULL, $financialAccountTypeId = NULL, $retrieveColumn = 'name', $key = 'id') {
-    $condition = NUll;
+    $condition = NULL;
     if ($financialAccountTypeId) {
-      $condition = " financial_account_type_id = ". $financialAccountTypeId;
+      $condition = " financial_account_type_id = " . $financialAccountTypeId;
     }
     $cacheKey = "{$id}_{$financialAccountTypeId}_{$retrieveColumn}_{$key}";
     if (!isset(self::$financialAccount[$cacheKey])) {
@@ -178,25 +189,29 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
    * Flush given pseudoconstant so it can be reread from db
    * nex time it's requested.
    *
-   * @access public
    * @static
    *
-   * @param boolean $name pseudoconstant to be flushed
-   *
+   * @param bool|string $name pseudoconstant to be flushed
    */
-  public static function flush($name) {
-    self::$$name = NULL;
+  public static function flush($name = 'cache') {
+    if (isset(self::$$name)) {
+      self::$$name = NULL;
+   }
   }
 
   /**
+   * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
+   *
    * Get all the contribution pages
    *
-   * @param integer $id  id of the contribution page
-   * @param boolean $all do we want all pages or only active pages
+   * @param int $id
+   *   Id of the contribution page.
+   * @param bool $all
+   *   Do we want all pages or only active pages.
    *
-   * @access public
    *
-   * @return array - array reference of all contribution pages if any
+   * @return array
+   *   array reference of all contribution pages if any
    * @static
    */
   public static function &contributionPage($id = NULL, $all = FALSE) {
@@ -221,11 +236,15 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
   }
 
   /**
+   * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
+   *
    * Get all the payment instruments
    *
-   * @access public
    *
-   * @return array - array reference of all payment instruments if any
+   * @param string $columnName
+   *
+   * @return array
+   *   array reference of all payment instruments if any
    * @static
    */
   public static function &paymentInstrument($columnName = 'label') {
@@ -241,30 +260,22 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
   /**
    * Get all the valid accepted credit cards
    *
-   * @access public
    *
-   * @return array - array reference of all payment instruments if any
+   * @return array
+   *   array reference of all payment instruments if any
    * @static
    */
   public static function &creditCard() {
-    $acceptCreditCard = array();
-    $creditCard = CRM_Core_OptionGroup::values('accept_creditcard');
-
-    if (!$creditCard) {
-      $creditCard = array();
-    }
-    foreach ($creditCard as $key => $value) {
-      $acceptCreditCard[$value] = $value;
-    }
-    return $acceptCreditCard;
+    return CRM_Core_OptionGroup::values('accept_creditcard', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
   }
 
   /**
    * Get all premiums
    *
-   * @access public
    *
-   * @return array - array of all Premiums if any
+   * @param int $pageID
+   * @return array
+   *   array of all Premiums if any
    * @static
    */
   public static function products($pageID = NULL) {
@@ -309,9 +320,11 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
   /**
    * Get all the contribution statuses
    *
-   * @access public
    *
-   * @return array - array reference of all contribution statuses
+   * @param int $id
+   * @param string $columnName
+   * @return array
+   *   array reference of all contribution statuses
    * @static
    */
   public static function &contributionStatus($id = NULL, $columnName = 'label') {
@@ -332,9 +345,12 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
   /**
    * Get all the Personal campaign pages
    *
-   * @access public
    *
-   * @return array - array reference of all pcp if any
+   * @param null $pageType
+   * @param int $id
+   *
+   * @return array
+   *   array reference of all pcp if any
    * @static
    */
   public static function &pcPage($pageType = NULL, $id = NULL) {
@@ -363,10 +379,11 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
    *
    * The static array pcpStatus is returned
    *
-   * @access public
    * @static
    *
-   * @return array - array reference of all PCP activity statuses
+   * @param string $column
+   * @return array
+   *   array reference of all PCP activity statuses
    */
   public static function &pcpStatus($column = 'label') {
     if (NULL === self::$pcpStatus) {
@@ -387,10 +404,12 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
    *
    * The static array  $financialTypeAccount is returned
    *
-   * @access public
    * @static
    *
-   * @return array - array reference of all financial accounts for a Financial type
+   * @param int $financialTypeId
+   * @param int $relationTypeId
+   * @return array
+   *   array reference of all financial accounts for a Financial type
    */
   public static function financialAccountType($financialTypeId, $relationTypeId = NULL) {
     if (!CRM_Utils_Array::value($financialTypeId, self::$financialTypeAccount)) {
@@ -398,7 +417,7 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
       CRM_Core_PseudoConstant::populate(
         self::$financialTypeAccount[$financialTypeId],
         'CRM_Financial_DAO_EntityFinancialAccount',
-        $all = true,
+        $all = TRUE,
         $retrieve = 'financial_account_id',
         $filter = NULL,
         $condition,
@@ -413,5 +432,34 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
 
     return self::$financialTypeAccount[$financialTypeId];
   }
-}
 
+  /**
+   * Get all batches
+   *
+   *
+   * @param int $id
+   * @return array
+   *   array reference of all batches if any
+   * @static
+   */
+  public static function &batch($id = NULL) {
+    if (!self::$batch) {
+      $orderBy = " id DESC ";
+      CRM_Core_PseudoConstant::populate(
+        self::$batch,
+        'CRM_Batch_DAO_Batch',
+        TRUE,
+        'title',
+        NULL,
+        NULL,
+        $orderBy
+      );
+    }
+
+    if ($id) {
+      $result = CRM_Utils_Array::value($id, self::$batch);
+      return $result;
+    }
+    return self::$batch;
+  }
+}