From ee20d7be140a13200b809be84acf16f462994e04 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Tue, 23 May 2017 16:33:55 +0530 Subject: [PATCH] CRM-20590. moved entity batch function to entityBatch file ---------------------------------------- * CRM-20590: Add pre and post hook for EntityBatch https://issues.civicrm.org/jira/browse/CRM-20590 --- CRM/Batch/BAO/Batch.php | 35 ------------------- CRM/Batch/BAO/EntityBatch.php | 35 +++++++++++++++++++ CRM/Contribute/BAO/Contribution.php | 2 +- CRM/Financial/Page/AJAX.php | 8 ++--- .../CRM/Financial/Page/BatchTransaction.tpl | 3 ++ 5 files changed, 43 insertions(+), 40 deletions(-) diff --git a/CRM/Batch/BAO/Batch.php b/CRM/Batch/BAO/Batch.php index a697d9bb64..39b402c14b 100644 --- a/CRM/Batch/BAO/Batch.php +++ b/CRM/Batch/BAO/Batch.php @@ -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. * diff --git a/CRM/Batch/BAO/EntityBatch.php b/CRM/Batch/BAO/EntityBatch.php index fcb4a2c22c..85b70490ef 100644 --- a/CRM/Batch/BAO/EntityBatch.php +++ b/CRM/Batch/BAO/EntityBatch.php @@ -32,4 +32,39 @@ */ 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; + } + } diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 89bd90869e..64e0ed7596 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -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 diff --git a/CRM/Financial/Page/AJAX.php b/CRM/Financial/Page/AJAX.php index c1d9656c14..b9fd85e18b 100644 --- a/CRM/Financial/Page/AJAX.php +++ b/CRM/Financial/Page/AJAX.php @@ -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); } } } diff --git a/templates/CRM/Financial/Page/BatchTransaction.tpl b/templates/CRM/Financial/Page/BatchTransaction.tpl index 0ee62d687a..2cf771184f 100644 --- a/templates/CRM/Financial/Page/BatchTransaction.tpl +++ b/templates/CRM/Financial/Page/BatchTransaction.tpl @@ -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(); -- 2.25.1