From 75c8a3f7304bd83bec58c798c17ac87ed12bc078 Mon Sep 17 00:00:00 2001 From: Guanhuan Chen Date: Tue, 12 May 2015 18:38:16 +0100 Subject: [PATCH] Add batch hooks --- CRM/Financial/BAO/ExportFormat/CSV.php | 13 +++++++++++++ CRM/Utils/Hook.php | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/CRM/Financial/BAO/ExportFormat/CSV.php b/CRM/Financial/BAO/ExportFormat/CSV.php index eb44deed8e..f8bac88241 100644 --- a/CRM/Financial/BAO/ExportFormat/CSV.php +++ b/CRM/Financial/BAO/ExportFormat/CSV.php @@ -122,6 +122,8 @@ class CRM_Financial_BAO_ExportFormat_CSV extends CRM_Financial_BAO_ExportFormat LEFT JOIN civicrm_financial_account fa ON fa.id = fi.financial_account_id WHERE eb.batch_id = ( %1 )"; + CRM_Utils_Hook::batchQuery($sql); + $params = array(1 => array($batchId, 'String')); $dao = CRM_Core_DAO::executeQuery($sql, $params); @@ -175,6 +177,10 @@ class CRM_Financial_BAO_ExportFormat_CSV extends CRM_Financial_BAO_ExportFormat foreach ($export as $batchId => $dao) { $financialItems = array(); $this->_batchIds = $batchId; + + $batchItems = array(); + $queryResults = array(); + while ($dao->fetch()) { $creditAccountName = $creditAccountType = $creditAccount = NULL; if ($dao->credit_account) { @@ -211,7 +217,14 @@ class CRM_Financial_BAO_ExportFormat_CSV extends CRM_Financial_BAO_ExportFormat 'Credit Account Type' => $creditAccountType, 'Item Description' => $dao->item_description, ); + + end($financialItems); + $batchItems[] = &$financialItems[key($financialItems)]; + $queryResults[] = get_object_vars($dao); } + + CRM_Utils_Hook::batchItems($queryResults, $batchItems); + $financialItems['headers'] = self::formatHeaders($financialItems); self::export($financialItems); } diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index 915f830943..b998553b53 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -1927,4 +1927,24 @@ abstract class CRM_Utils_Hook { ); } + /** + * This hook is called when a query string of the CSV Batch export is generated. + */ + public static function batchQuery(&$query) { + return self::singleton()->invoke(1, $query, self::$_nullObject, + self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, + 'civicrm_batchQuery' + ); + } + + /** + * This hook is called when the entries of the CSV Batch export are mapped. + */ + public static function batchItems(&$results, &$items) { + return self::singleton()->invoke(2, $results, $items, + self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, + 'civicrm_batchItems' + ); + } + } -- 2.25.1