Merge pull request #2853 from colemanw/js
[civicrm-core.git] / CRM / Contribute / PseudoConstant.php
index fe69660b55ab6bb737092c0b73f9fa7f526e9e6c..dd5977c2512967b1ebdd8a23a500cd815343afa8 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | 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$
  *
  */
@@ -83,14 +83,6 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
    */
   private static $paymentInstrument;
 
-  /**
-   * credit card
-   *
-   * @var array
-   * @static
-   */
-  private static $creditCard;
-
   /**
    * contribution status
    *
@@ -114,6 +106,15 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
   private static $pcpStatus;
 
   /**
+   * contribution / financial batches
+   * @var array
+   * @static
+   */
+  private static $batch;
+
+  /**
+   * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
+   *
    * Get all the financial types
    *
    * @access public
@@ -142,6 +143,8 @@ 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
@@ -184,13 +187,15 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
    * @param boolean $name pseudoconstant to be flushed
    *
    */
-  public static function flush($name) {
+  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
@@ -223,6 +228,8 @@ 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
@@ -249,16 +256,7 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
    * @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');
   }
 
   /**
@@ -415,5 +413,34 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
 
     return self::$financialTypeAccount[$financialTypeId];
   }
+
+  /**
+   * Get all batches
+   *
+   * @access public
+   *
+   * @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;
+  }
 }