From 91aff94c17ac955229d6c2b5706d0d5a17eca129 Mon Sep 17 00:00:00 2001
From: kurund <kurund@civicrm.org>
Date: Sat, 10 Aug 2013 16:39:46 +0530
Subject: [PATCH] CRM-13170, fixed select to show all batches

----------------------------------------
* CRM-13170: Search Contribution by Batch no longer works since change to DB
  http://issues.civicrm.org/jira/browse/CRM-13170
---
 CRM/Contribute/BAO/Query.php      |  4 ++--
 CRM/Contribute/PseudoConstant.php | 36 +++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php
index 931b31861e..cde8746fae 100644
--- a/CRM/Contribute/BAO/Query.php
+++ b/CRM/Contribute/BAO/Query.php
@@ -528,7 +528,7 @@ class CRM_Contribute_BAO_Query {
         return;
 
       case 'contribution_batch_id':
-        $batches = CRM_Batch_BAO_Batch::getBatches();
+        $batches = CRM_Contribute_PseudoConstant::batch();
         $query->_where[$grouping][] = " civicrm_entity_batch.batch_id $op $value";
         $query->_qill[$grouping][] = ts('Batch Name %1 %2', array(1 => $op, 2 => $batches[$value]));
         $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
@@ -851,7 +851,7 @@ class CRM_Contribute_BAO_Query {
     CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'contribution_campaign_id');
 
     // Add batch select
-    $batches = CRM_Batch_BAO_Batch::getBatches();
+    $batches = CRM_Contribute_PseudoConstant::batch();
 
     if ( !empty( $batches ) ) {
       $form->add('select', 'contribution_batch_id',
diff --git a/CRM/Contribute/PseudoConstant.php b/CRM/Contribute/PseudoConstant.php
index fe69660b55..45ec9c270c 100644
--- a/CRM/Contribute/PseudoConstant.php
+++ b/CRM/Contribute/PseudoConstant.php
@@ -113,6 +113,13 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
    */
   private static $pcpStatus;
 
+  /**
+   * contribution / financial batches
+   * @var array
+   * @static
+   */
+  private static $batch;
+
   /**
    * Get all the financial types
    *
@@ -415,5 +422,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;
+  }
 }
 
-- 
GitLab