From 806c5e1e200a79c374c7d8d9a6068963873441a7 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 9 Jul 2019 11:22:00 +1200 Subject: [PATCH] Extract field wrangling to determineReturnProperties This encases the wrangling of the field format to it's own function --- CRM/Export/BAO/Export.php | 46 +------------------------ CRM/Export/BAO/ExportProcessor.php | 54 +++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 46 deletions(-) diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 1320d24f61..b4a3c76319 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -180,51 +180,7 @@ class CRM_Export_BAO_Export { ); $processor = new CRM_Export_BAO_ExportProcessor($exportMode, $fields, $queryOperator, $mergeSameHousehold, $isPostalOnly); - $returnProperties = []; - - if ($fields) { - foreach ($fields as $key => $value) { - $fieldName = CRM_Utils_Array::value(1, $value); - if (!$fieldName || $processor->isHouseholdMergeRelationshipTypeKey($fieldName)) { - continue; - } - - if ($processor->isRelationshipTypeKey($fieldName) && (!empty($value[2]) || !empty($value[4]))) { - $returnProperties[$fieldName] = $processor->setRelationshipReturnProperties($value, $fieldName); - } - elseif (is_numeric(CRM_Utils_Array::value(2, $value))) { - $locationName = CRM_Core_PseudoConstant::getName('CRM_Core_BAO_Address', 'location_type_id', $value[2]); - if ($fieldName == 'phone') { - $returnProperties['location'][$locationName]['phone-' . CRM_Utils_Array::value(3, $value)] = 1; - } - elseif ($fieldName == 'im') { - $returnProperties['location'][$locationName]['im-' . CRM_Utils_Array::value(3, $value)] = 1; - } - else { - $returnProperties['location'][$locationName][$fieldName] = 1; - } - } - else { - //hack to fix component fields - //revert mix of event_id and title - if ($fieldName == 'event_id') { - $returnProperties['event_id'] = 1; - } - else { - $returnProperties[$fieldName] = 1; - } - } - } - $defaultExportMode = $processor->defaultReturnProperty(); - if ($defaultExportMode) { - $returnProperties[$defaultExportMode] = 1; - } - } - else { - $returnProperties = $processor->getDefaultReturnProperties(); - } - // @todo - we are working towards this being entirely a property of the processor - $processor->setReturnProperties($returnProperties); + $returnProperties = $processor->getReturnProperties(); $paymentTableId = $processor->getPaymentTableID(); if ($mergeSameAddress) { diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index e83faf4673..b2707dea11 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -184,7 +184,8 @@ class CRM_Export_BAO_ExportProcessor { $this->setRequestedFields($requestedFields); $this->setRelationshipTypes(); $this->setIsMergeSameHousehold($isMergeSameHousehold); - $this->setisPostalableOnly($isPostalableOnly); + $this->setIsPostalableOnly($isPostalableOnly); + $this->setReturnProperties($this->determineReturnProperties()); } /** @@ -1439,4 +1440,55 @@ class CRM_Export_BAO_ExportProcessor { return $property; } + /** + * Determine the required return properties from the input parameters. + * + * @return array + */ + public function determineReturnProperties() { + if ($this->getRequestedFields()) { + $returnProperties = []; + foreach ($this->getRequestedFields() as $key => $value) { + $fieldName = CRM_Utils_Array::value(1, $value); + if (!$fieldName || $this->isHouseholdMergeRelationshipTypeKey($fieldName)) { + continue; + } + + if ($this->isRelationshipTypeKey($fieldName) && (!empty($value[2]) || !empty($value[4]))) { + $returnProperties[$fieldName] = $this->setRelationshipReturnProperties($value, $fieldName); + } + elseif (is_numeric(CRM_Utils_Array::value(2, $value))) { + $locationName = CRM_Core_PseudoConstant::getName('CRM_Core_BAO_Address', 'location_type_id', $value[2]); + if ($fieldName == 'phone') { + $returnProperties['location'][$locationName]['phone-' . CRM_Utils_Array::value(3, $value)] = 1; + } + elseif ($fieldName == 'im') { + $returnProperties['location'][$locationName]['im-' . CRM_Utils_Array::value(3, $value)] = 1; + } + else { + $returnProperties['location'][$locationName][$fieldName] = 1; + } + } + else { + //hack to fix component fields + //revert mix of event_id and title + if ($fieldName == 'event_id') { + $returnProperties['event_id'] = 1; + } + else { + $returnProperties[$fieldName] = 1; + } + } + } + $defaultExportMode = $this->defaultReturnProperty(); + if ($defaultExportMode) { + $returnProperties[$defaultExportMode] = 1; + } + } + else { + $returnProperties = $this->getDefaultReturnProperties(); + } + return $returnProperties; + } + } -- 2.25.1