CRM-20590. moved entity batch function to entityBatch file
authorPradeep Nayak <pradpnayak@gmail.com>
Tue, 23 May 2017 11:03:55 +0000 (16:33 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Tue, 23 May 2017 11:04:32 +0000 (16:34 +0530)
----------------------------------------
* CRM-20590: Add pre and post hook for EntityBatch
  https://issues.civicrm.org/jira/browse/CRM-20590

CRM/Batch/BAO/Batch.php
CRM/Batch/BAO/EntityBatch.php
CRM/Contribute/BAO/Contribution.php
CRM/Financial/Page/AJAX.php
templates/CRM/Financial/Page/BatchTransaction.tpl

index a697d9bb64c094b97bdc588eab0c38e09542f402..39b402c14b2881fcc52ebc6948bc0b0f8e5911c2 100644 (file)
@@ -133,41 +133,6 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch {
     return ts('Batch %1', array(1 => $batchNo)) . ': ' . date('Y-m-d');
   }
 
-  /**
-   * Create entity batch entry.
-   *
-   * @param array $params
-   * @return array
-   */
-  public static function addBatchEntity(&$params) {
-    $op = 'edit';
-    $entityId = CRM_Utils_Array::value('id', $params);
-    if (!$entityId) {
-      $op = 'create';
-    }
-    CRM_Utils_Hook::pre($op, 'EntityBatch', $entityId, $params);
-    $entityBatch = new CRM_Batch_DAO_EntityBatch();
-    $entityBatch->copyValues($params);
-    $entityBatch->save();
-    CRM_Utils_Hook::post($op, 'EntityBatch', $entityBatch->id, $entityBatch);
-    return $entityBatch;
-  }
-
-  /**
-   * Remove entries from entity batch.
-   * @param array $params
-   * @return CRM_Batch_DAO_EntityBatch
-   */
-  public static function removeBatchEntity($params) {
-    $entityBatch = new CRM_Batch_DAO_EntityBatch();
-    $entityId = CRM_Utils_Array::value('id', $params);
-    CRM_Utils_Hook::pre('delete', 'EntityBatch', $entityId, $params);
-    $entityBatch->copyValues($params);
-    $entityBatch->delete();
-    CRM_Utils_Hook::post('delete', 'EntityBatch', $entityBatch->id, $entityBatch);
-    return $entityBatch;
-  }
-
   /**
    * Delete batch entry.
    *
index fcb4a2c22cfd6debc5c8de853bcc8d3457ad4388..85b70490efa85c3bf66cd92579dcd58f3dca9f60 100644 (file)
  */
 class CRM_Batch_BAO_EntityBatch extends CRM_Batch_DAO_EntityBatch {
 
+  /**
+   * Create entity batch entry.
+   *
+   * @param array $params
+   * @return array
+   */
+  public static function create(&$params) {
+    $op = 'edit';
+    $entityId = CRM_Utils_Array::value('id', $params);
+    if (!$entityId) {
+      $op = 'create';
+    }
+    CRM_Utils_Hook::pre($op, 'EntityBatch', $entityId, $params);
+    $entityBatch = new CRM_Batch_DAO_EntityBatch();
+    $entityBatch->copyValues($params);
+    $entityBatch->save();
+    CRM_Utils_Hook::post($op, 'EntityBatch', $entityBatch->id, $entityBatch);
+    return $entityBatch;
+  }
+
+  /**
+   * Remove entries from entity batch.
+   * @param array $params
+   * @return CRM_Batch_DAO_EntityBatch
+   */
+  public static function del($params) {
+    $entityBatch = new CRM_Batch_DAO_EntityBatch();
+    $entityId = CRM_Utils_Array::value('id', $params);
+    CRM_Utils_Hook::pre('delete', 'EntityBatch', $entityId, $params);
+    $entityBatch->copyValues($params);
+    $entityBatch->delete();
+    CRM_Utils_Hook::post('delete', 'EntityBatch', $entityBatch->id, $entityBatch);
+    return $entityBatch;
+  }
+
 }
index 89bd90869e83a80024f9f7dad742cd1192a38fba..64e0ed7596a4fe3213af868d6a51e5e6b9a1709b 100644 (file)
@@ -3468,7 +3468,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
         'entity_table' => 'civicrm_financial_trxn',
         'entity_id' => $financialTxn->id,
       );
-      CRM_Batch_BAO_Batch::addBatchEntity($entityParams);
+      CRM_Batch_BAO_EntityBatch::create($entityParams);
     }
 
     // when a fee is charged
index c1d9656c14f893089998ba9a1cbb72ff886a37e0..b9fd85e18bce381e7bf3b02858758464ef5cb9eb 100644 (file)
@@ -165,8 +165,8 @@ class CRM_Financial_Page_AJAX {
 
     $entityID = CRM_Utils_Request::retrieve('entityID', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
     $methods = array(
-      'assign' => 'addBatchEntity',
-      'remove' => 'removeBatchEntity',
+      'assign' => 'create',
+      'remove' => 'del',
       'reopen' => 'create',
       'close' => 'create',
       'delete' => 'deleteBatch',
@@ -486,10 +486,10 @@ class CRM_Financial_Page_AJAX {
           'batch_id' => $entityID,
         );
         if ($action == 'Assign') {
-          $updated = CRM_Batch_BAO_Batch::addBatchEntity($params);
+          $updated = CRM_Batch_BAO_EntityBatch::create($params);
         }
         else {
-          $updated = CRM_Batch_BAO_Batch::removeBatchEntity($params);
+          $updated = CRM_Batch_BAO_EntityBatch::del($params);
         }
       }
     }
index 0ee62d687acf2b1732101f01ee33405a5034d0f2..2cf771184f9c32f772df7603bca42d8817d76aa0 100644 (file)
@@ -90,6 +90,9 @@ CRM.$(function($) {
 });
 function assignRemove(recordID, op) {
   var recordBAO = 'CRM_Batch_BAO_Batch';
+  if (op == 'assign' || op == 'remove') {
+    recordBAO = 'CRM_Batch_BAO_EntityBatch';   
+  }
   var entityID = {/literal}"{$entityID}"{literal};
   if (op == 'close' || op == 'export') {
     var mismatch = checkMismatch();