From edc6a486559890c1aa367464d86bb37b66cd371d Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 25 Sep 2018 10:47:05 +1200 Subject: [PATCH] Rationalise 'getExportFilename' --- CRM/Export/BAO/Export.php | 47 +----------------------------- CRM/Export/BAO/ExportProcessor.php | 39 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 46 deletions(-) diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index deb2890c5097..dede641e78e0 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -624,45 +624,6 @@ public static function exportComponents( } } - /** - * Name of the export file based on mode. - * - * @param string $output - * Type of output. - * @param int $mode - * Export mode. - * - * @return string - * name of the file - */ - public static function getExportFileName($output = 'csv', $mode = CRM_Export_Form_Select::CONTACT_EXPORT) { - switch ($mode) { - case CRM_Export_Form_Select::CONTACT_EXPORT: - return ts('CiviCRM Contact Search'); - - case CRM_Export_Form_Select::CONTRIBUTE_EXPORT: - return ts('CiviCRM Contribution Search'); - - case CRM_Export_Form_Select::MEMBER_EXPORT: - return ts('CiviCRM Member Search'); - - case CRM_Export_Form_Select::EVENT_EXPORT: - return ts('CiviCRM Participant Search'); - - case CRM_Export_Form_Select::PLEDGE_EXPORT: - return ts('CiviCRM Pledge Search'); - - case CRM_Export_Form_Select::CASE_EXPORT: - return ts('CiviCRM Case Search'); - - case CRM_Export_Form_Select::GRANT_EXPORT: - return ts('CiviCRM Grant Search'); - - case CRM_Export_Form_Select::ACTIVITY_EXPORT: - return ts('CiviCRM Activity Search'); - } - } - /** * Handle import error file creation. */ @@ -1249,13 +1210,7 @@ public static function writeCSVFromTable($exportTempTable, $headerRows, $sqlColu } $componentDetails[] = $row; } - if ($exportMode == 'financial') { - $getExportFileName = 'CiviCRM Contribution Search'; - } - else { - $getExportFileName = self::getExportFileName('csv', $exportMode); - } - CRM_Core_Report_Excel::writeCSVFile($getExportFileName, + CRM_Core_Report_Excel::writeCSVFile($processor->getExportFileName(), $headerRows, $componentDetails, NULL, diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index b038424a4daa..4cdbeae6c960 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -301,6 +301,45 @@ public function setExportMode($exportMode) { $this->exportMode = $exportMode; } + /** + * Get the name for the export file. + * + * @return string + */ + public function getExportFileName() { + switch ($this->getExportMode()) { + case CRM_Export_Form_Select::CONTACT_EXPORT: + return ts('CiviCRM Contact Search'); + + case CRM_Export_Form_Select::CONTRIBUTE_EXPORT: + return ts('CiviCRM Contribution Search'); + + case CRM_Export_Form_Select::MEMBER_EXPORT: + return ts('CiviCRM Member Search'); + + case CRM_Export_Form_Select::EVENT_EXPORT: + return ts('CiviCRM Participant Search'); + + case CRM_Export_Form_Select::PLEDGE_EXPORT: + return ts('CiviCRM Pledge Search'); + + case CRM_Export_Form_Select::CASE_EXPORT: + return ts('CiviCRM Case Search'); + + case CRM_Export_Form_Select::GRANT_EXPORT: + return ts('CiviCRM Grant Search'); + + case CRM_Export_Form_Select::ACTIVITY_EXPORT: + return ts('CiviCRM Activity Search'); + + default : + // Legacy code suggests the value could be 'financial' - ie. something + // other than what should be accepted. However, I suspect that this line is + // never hit. + return ts('CiviCRM Search'); + } + } + /** * @param $params * @param $order