From 05ad310f1c2b4835bad9bb78529ebb4e50331489 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 12 Nov 2018 14:49:17 +1300 Subject: [PATCH] Refactor out getPaymentHeaders function --- CRM/Export/BAO/Export.php | 14 +++----------- CRM/Export/BAO/ExportProcessor.php | 13 +++++++++++++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 57a53f7fbe..99ba90ee5a 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -432,25 +432,16 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c $paymentDetails = array(); if ($processor->isExportPaymentFields()) { - // get payment related in for event and members $paymentDetails = CRM_Contribute_BAO_Contribution::getContributionDetails($exportMode, $ids); //get all payment headers. // If we haven't selected specific payment fields, load in all the // payment headers. if (!$processor->isExportSpecifiedPaymentFields()) { - $paymentHeaders = $processor->getcomponentPaymentFields(); if (!empty($paymentDetails)) { $addPaymentHeader = TRUE; } } - // If we have selected specific payment fields, leave the payment headers - // as an empty array; the headers for each selected field will be added - // elsewhere. - else { - $paymentHeaders = array(); - } - $nullContributionDetails = array_fill_keys(array_keys($paymentHeaders), NULL); } $componentDetails = array(); @@ -536,8 +527,8 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c if ($addPaymentHeader && $processor->isExportPaymentFields()) { // @todo rather than do this for every single row do it before the loop starts. // where other header definitions take place. - $headerRows = array_merge($headerRows, $paymentHeaders); - foreach (array_keys($paymentHeaders) as $paymentHdr) { + $headerRows = array_merge($headerRows, $processor->getPaymentHeaders()); + foreach (array_keys($processor->getPaymentHeaders()) as $paymentHdr) { self::sqlColumnDefn($processor, $sqlColumns, $paymentHdr); } } @@ -554,6 +545,7 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c // information, if appropriate. if ($addPaymentHeader) { if (!$processor->isExportSpecifiedPaymentFields()) { + $nullContributionDetails = array_fill_keys(array_keys($processor->getPaymentHeaders()), NULL); if ($processor->isExportPaymentFields()) { $paymentData = CRM_Utils_Array::value($row[$paymentTableId], $paymentDetails); if (!is_array($paymentData) || empty($paymentData)) { diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index 2cf81b34db..1e12629d9e 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -533,6 +533,19 @@ class CRM_Export_BAO_ExportProcessor { ]; } + /** + * Get headers for payment fields. + * + * Returns an array of contribution fields when the entity supports payment fields and specific fields + * are not specified. This is a transitional function for refactoring legacy code. + */ + public function getPaymentHeaders() { + if ($this->isExportPaymentFields() && !$this->isExportSpecifiedPaymentFields()) { + return $this->getcomponentPaymentFields(); + } + return []; + } + /** * Get the default properties when not specified. * -- 2.25.1