Rationalise 'getExportFilename'
authoreileen <emcnaughton@wikimedia.org>
Mon, 24 Sep 2018 22:47:05 +0000 (10:47 +1200)
committereileen <emcnaughton@wikimedia.org>
Tue, 25 Sep 2018 05:37:41 +0000 (17:37 +1200)
CRM/Export/BAO/Export.php
CRM/Export/BAO/ExportProcessor.php

index deb2890c5097d7784fec891cb762e84f7b2b3e1e..dede641e78e0badef69f5f1c83fbf408a7e18b5b 100644 (file)
@@ -624,45 +624,6 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
     }
   }
 
-  /**
-   * 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 @@ LIMIT $offset, $limit
         }
         $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,
index b038424a4daabff8b1cfbf25f5cf94e53301463f..026befc13373076bbf96260a0f553fca4bf75eec 100644 (file)
@@ -301,6 +301,45 @@ class CRM_Export_BAO_ExportProcessor {
     $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