diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 1320d24f6124..b4a3c7631930 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -180,51 +180,7 @@ public static function exportComponents( ); $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 e83faf46731a..b2707dea11f7 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -184,7 +184,8 @@ public function __construct($exportMode, $requestedFields, $queryOperator, $isMe $this->setRequestedFields($requestedFields); $this->setRelationshipTypes(); $this->setIsMergeSameHousehold($isMergeSameHousehold); - $this->setisPostalableOnly($isPostalableOnly); + $this->setIsPostalableOnly($isPostalableOnly); + $this->setReturnProperties($this->determineReturnProperties()); } /** @@ -1439,4 +1440,55 @@ public function defaultReturnProperty() { 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; + } + }