Move buildRow to processor class
authoreileen <emcnaughton@wikimedia.org>
Fri, 16 Nov 2018 21:03:32 +0000 (10:03 +1300)
committereileen <emcnaughton@wikimedia.org>
Fri, 16 Nov 2018 21:39:16 +0000 (10:39 +1300)
CRM/Export/BAO/Export.php
CRM/Export/BAO/ExportProcessor.php

index 9425982570c3f202dddf63ed1296a94b27abd70d..30566387dd2c89c8527bdcb41f67dba04605556f 100644 (file)
@@ -471,7 +471,7 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
       while ($iterationDAO->fetch()) {
         $count++;
         $rowsThisIteration++;
-        $row = self::buildRow($query, $iterationDAO, $processor, $outputColumns,  $metadata, $paymentDetails, $addPaymentHeader, $paymentTableId);
+        $row = $processor->buildRow($query, $iterationDAO, $outputColumns, $metadata, $paymentDetails, $addPaymentHeader, $paymentTableId);
 
         // add component info
         // write the row to a file
@@ -1623,102 +1623,4 @@ WHERE  {$whereClause}";
     }
   }
 
-  /**
-   * Build the row for output.
-   *
-   * @param \CRM_Contact_BAO_Query $query
-   * @param CRM_Core_DAO $iterationDAO
-   * @param \CRM_Export_BAO_ExportProcessor$processor
-   * @param array $outputColumns
-   * @param $metadata
-   * @param $paymentDetails
-   * @param $addPaymentHeader
-   * @param $paymentTableId
-   *
-   * @return array
-   */
-  protected static function buildRow($query, $iterationDAO, $processor, $outputColumns, $metadata, $paymentDetails, $addPaymentHeader, $paymentTableId) {
-    $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
-    $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
-
-    $row = [];
-    $query->convertToPseudoNames($iterationDAO);
-
-    //first loop through output columns so that we return what is required, and in same order.
-    foreach ($outputColumns as $field => $value) {
-
-      // add im_provider to $dao object
-      if ($field == 'im_provider' && property_exists($iterationDAO, 'provider_id')) {
-        $iterationDAO->im_provider = $iterationDAO->provider_id;
-      }
-
-      //build row values (data)
-      $fieldValue = NULL;
-      if (property_exists($iterationDAO, $field)) {
-        $fieldValue = $iterationDAO->$field;
-        // to get phone type from phone type id
-        if ($field == 'phone_type_id' && isset($phoneTypes[$fieldValue])) {
-          $fieldValue = $phoneTypes[$fieldValue];
-        }
-        elseif ($field == 'provider_id' || $field == 'im_provider') {
-          $fieldValue = CRM_Utils_Array::value($fieldValue, $imProviders);
-        }
-        elseif (strstr($field, 'master_id')) {
-          $masterAddressId = NULL;
-          if (isset($iterationDAO->$field)) {
-            $masterAddressId = $iterationDAO->$field;
-          }
-          // get display name of contact that address is shared.
-          $fieldValue = CRM_Contact_BAO_Contact::getMasterDisplayName($masterAddressId);
-        }
-      }
-
-      if ($processor->isRelationshipTypeKey($field)) {
-        foreach (array_keys($value) as $property) {
-          if ($property === 'location') {
-            // @todo just undo all this nasty location wrangling!
-            foreach ($value['location'] as $locationKey => $locationFields) {
-              foreach (array_keys($locationFields) as $locationField) {
-                $fieldKey = str_replace(' ', '_', $locationKey . '-' . $locationField);
-                $row[$field . '_' . $fieldKey] = $processor->getRelationshipValue($field, $iterationDAO->contact_id, $fieldKey);
-              }
-            }
-          }
-          else {
-            $row[$field . '_' . $property] = $processor->getRelationshipValue($field, $iterationDAO->contact_id, $property);
-          }
-        }
-      }
-      else {
-        $row[$field] = $processor->getTransformedFieldValue($field, $iterationDAO, $fieldValue, $metadata, $paymentDetails);
-      }
-    }
-
-    // If specific payment fields have been selected for export, payment
-    // data will already be in $row. Otherwise, add payment related
-    // 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)) {
-            $paymentData = $nullContributionDetails;
-          }
-          $row = array_merge($row, $paymentData);
-        }
-        elseif (!empty($paymentDetails)) {
-          $row = array_merge($row, $nullContributionDetails);
-        }
-      }
-    }
-    //remove organization name for individuals if it is set for current employer
-    if (!empty($row['contact_type']) &&
-      $row['contact_type'] == 'Individual' && array_key_exists('organization_name', $row)
-    ) {
-      $row['organization_name'] = '';
-    }
-    return $row;
-  }
-
 }
index e454a8c30ea49bc631137c7ce37544cbe8489221..22c0b00ff62c0cbf63891cc99e4b2be156047eb2 100644 (file)
@@ -409,6 +409,103 @@ class CRM_Export_BAO_ExportProcessor {
     return array($query, $select, $from, $where, $having);
   }
 
+  /**
+   * Build the row for output.
+   *
+   * @param \CRM_Contact_BAO_Query $query
+   * @param CRM_Core_DAO $iterationDAO
+   * @param array $outputColumns
+   * @param $metadata
+   * @param $paymentDetails
+   * @param $addPaymentHeader
+   * @param $paymentTableId
+   *
+   * @return array
+   */
+  public function buildRow($query, $iterationDAO, $outputColumns, $metadata, $paymentDetails, $addPaymentHeader, $paymentTableId) {
+    $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
+    $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
+
+    $row = [];
+    $query->convertToPseudoNames($iterationDAO);
+
+    //first loop through output columns so that we return what is required, and in same order.
+    foreach ($outputColumns as $field => $value) {
+
+      // add im_provider to $dao object
+      if ($field == 'im_provider' && property_exists($iterationDAO, 'provider_id')) {
+        $iterationDAO->im_provider = $iterationDAO->provider_id;
+      }
+
+      //build row values (data)
+      $fieldValue = NULL;
+      if (property_exists($iterationDAO, $field)) {
+        $fieldValue = $iterationDAO->$field;
+        // to get phone type from phone type id
+        if ($field == 'phone_type_id' && isset($phoneTypes[$fieldValue])) {
+          $fieldValue = $phoneTypes[$fieldValue];
+        }
+        elseif ($field == 'provider_id' || $field == 'im_provider') {
+          $fieldValue = CRM_Utils_Array::value($fieldValue, $imProviders);
+        }
+        elseif (strstr($field, 'master_id')) {
+          $masterAddressId = NULL;
+          if (isset($iterationDAO->$field)) {
+            $masterAddressId = $iterationDAO->$field;
+          }
+          // get display name of contact that address is shared.
+          $fieldValue = CRM_Contact_BAO_Contact::getMasterDisplayName($masterAddressId);
+        }
+      }
+
+      if ($this->isRelationshipTypeKey($field)) {
+        foreach (array_keys($value) as $property) {
+          if ($property === 'location') {
+            // @todo just undo all this nasty location wrangling!
+            foreach ($value['location'] as $locationKey => $locationFields) {
+              foreach (array_keys($locationFields) as $locationField) {
+                $fieldKey = str_replace(' ', '_', $locationKey . '-' . $locationField);
+                $row[$field . '_' . $fieldKey] = $this->getRelationshipValue($field, $iterationDAO->contact_id, $fieldKey);
+              }
+            }
+          }
+          else {
+            $row[$field . '_' . $property] = $this->getRelationshipValue($field, $iterationDAO->contact_id, $property);
+          }
+        }
+      }
+      else {
+        $row[$field] = $this->getTransformedFieldValue($field, $iterationDAO, $fieldValue, $metadata, $paymentDetails);
+      }
+    }
+
+    // If specific payment fields have been selected for export, payment
+    // data will already be in $row. Otherwise, add payment related
+    // information, if appropriate.
+    if ($addPaymentHeader) {
+      if (!$this->isExportSpecifiedPaymentFields()) {
+        $nullContributionDetails = array_fill_keys(array_keys($this->getPaymentHeaders()), NULL);
+        if ($this->isExportPaymentFields()) {
+          $paymentData = CRM_Utils_Array::value($row[$paymentTableId], $paymentDetails);
+          if (!is_array($paymentData) || empty($paymentData)) {
+            $paymentData = $nullContributionDetails;
+          }
+          $row = array_merge($row, $paymentData);
+        }
+        elseif (!empty($paymentDetails)) {
+          $row = array_merge($row, $nullContributionDetails);
+        }
+      }
+    }
+    //remove organization name for individuals if it is set for current employer
+    if (!empty($row['contact_type']) &&
+      $row['contact_type'] == 'Individual' && array_key_exists('organization_name', $row)
+    ) {
+      $row['organization_name'] = '';
+    }
+    return $row;
+  }
+
   /**
    * @param $field
    * @param $iterationDAO