Refactor out getPaymentHeaders function
authoreileen <emcnaughton@wikimedia.org>
Mon, 12 Nov 2018 01:49:17 +0000 (14:49 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 15 Nov 2018 23:26:14 +0000 (12:26 +1300)
CRM/Export/BAO/Export.php
CRM/Export/BAO/ExportProcessor.php

index 57a53f7fbe1afd23cb373b4440ce24e3361c134f..99ba90ee5a157ce7308062d0b7c1bfb56e4c1a5a 100644 (file)
@@ -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)) {
index 2cf81b34db0fbfb3fc266cebb05dee88c8f16cec..1e12629d9e180733e0c2031948390e1eabcba108 100644 (file)
@@ -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.
    *