From 9b05de295967b4c60aee17957ac64707165ec0fa Mon Sep 17 00:00:00 2001 From: Johan Vervloet Date: Mon, 30 May 2016 20:38:03 +0200 Subject: [PATCH] CRM-18697 - Make the function that performs the actual export abstract. ---------------------------------------- * CRM-18697: Make it possible to add new ExportFormats via extensions https://issues.civicrm.org/jira/browse/CRM-18697 --- CRM/Batch/BAO/Batch.php | 17 +++-------------- CRM/Financial/BAO/ExportFormat.php | 9 ++++++++- CRM/Financial/BAO/ExportFormat/CSV.php | 2 +- CRM/Financial/BAO/ExportFormat/IIF.php | 2 +- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/CRM/Batch/BAO/Batch.php b/CRM/Batch/BAO/Batch.php index 0cbb4eff05..bc1947bfaf 100644 --- a/CRM/Batch/BAO/Batch.php +++ b/CRM/Batch/BAO/Batch.php @@ -593,21 +593,10 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch { else { CRM_Core_Error::fatal("Could not locate exporter: $exporterClass"); } - switch (self::$_exportFormat) { - case 'CSV': - foreach ($batchIds as $batchId) { - $export[$batchId] = $exporter->generateExportQuery($batchId); - } - $exporter->makeCSV($export); - break; - - case 'IIF': - foreach ($batchIds as $batchId) { - $export[$batchId] = $exporter->generateExportQuery($batchId); - } - $exporter->makeIIF($export); - break; + foreach ($batchIds as $batchId) { + $export[$batchId] = $exporter->generateExportQuery($batchId); } + $exporter->makeExport($export); } /** diff --git a/CRM/Financial/BAO/ExportFormat.php b/CRM/Financial/BAO/ExportFormat.php index f404700b39..5cc800f6ff 100644 --- a/CRM/Financial/BAO/ExportFormat.php +++ b/CRM/Financial/BAO/ExportFormat.php @@ -36,7 +36,7 @@ * Create a subclass for a specific format. * @see http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+Specifications+-++Batches#CiviAccountsSpecifications-Batches-%C2%A0Overviewofimplementation */ -class CRM_Financial_BAO_ExportFormat { +abstract class CRM_Financial_BAO_ExportFormat { /** * data which the individual export formats will output in the desired format. @@ -88,6 +88,13 @@ class CRM_Financial_BAO_ExportFormat { } } + /** + * Abstract function that generates exports, and downloads them as zip file. + * + * @param $exportDaos array with DAO's for queries to be exported. + */ + public abstract function makeExport($exportDaos); + /** * @return string */ diff --git a/CRM/Financial/BAO/ExportFormat/CSV.php b/CRM/Financial/BAO/ExportFormat/CSV.php index 4a5330ea33..3030e40bea 100644 --- a/CRM/Financial/BAO/ExportFormat/CSV.php +++ b/CRM/Financial/BAO/ExportFormat/CSV.php @@ -172,7 +172,7 @@ class CRM_Financial_BAO_ExportFormat_CSV extends CRM_Financial_BAO_ExportFormat * * @param array $export */ - public function makeCSV($export) { + public function makeExport($export) { // getting data from admin page $prefixValue = Civi::settings()->get('contribution_invoice_settings'); diff --git a/CRM/Financial/BAO/ExportFormat/IIF.php b/CRM/Financial/BAO/ExportFormat/IIF.php index 66c1912d46..65a3795dc7 100644 --- a/CRM/Financial/BAO/ExportFormat/IIF.php +++ b/CRM/Financial/BAO/ExportFormat/IIF.php @@ -150,7 +150,7 @@ class CRM_Financial_BAO_ExportFormat_IIF extends CRM_Financial_BAO_ExportFormat /** * @param $export */ - public function makeIIF($export) { + public function makeExport($export) { // Keep running list of accounts and contacts used in this batch, since we need to // include those in the output. Only want to include ones used in the batch, not everything in the db, // since would increase the chance of messing up user's existing Quickbooks entries. -- 2.25.1