CRM-13170, fixed select to show all batches
authorkurund <kurund@civicrm.org>
Sat, 10 Aug 2013 11:09:46 +0000 (16:39 +0530)
committerkurund <kurund@civicrm.org>
Sat, 10 Aug 2013 11:09:46 +0000 (16:39 +0530)
----------------------------------------
* 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
CRM/Contribute/PseudoConstant.php

index 931b31861e43caeebd26abd734e642e0d1b34166..cde8746fae1d0c71e3284bbc821ce04a75cefb94 100644 (file)
@@ -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',
index fe69660b55ab6bb737092c0b73f9fa7f526e9e6c..45ec9c270c8b8c0bdc5d9adf71648ad03697b8d2 100644 (file)
@@ -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;
+  }
 }