From 04f8f758ba8ae0a404a7dc7afdb39ab49549a174 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 10 Jul 2019 20:25:02 +1200 Subject: [PATCH] Update handling of input fields so that the mapping format is accepted. At this point we are converting to the mapping format AFTEr the function receives the fields but changing that is the next step --- CRM/Core/BAO/Mapping.php | 13 +++--- CRM/Export/BAO/Export.php | 6 ++- CRM/Export/BAO/ExportProcessor.php | 63 ++++++++++-------------------- 3 files changed, 34 insertions(+), 48 deletions(-) diff --git a/CRM/Core/BAO/Mapping.php b/CRM/Core/BAO/Mapping.php index d740ce2a27..c144b636e3 100644 --- a/CRM/Core/BAO/Mapping.php +++ b/CRM/Core/BAO/Mapping.php @@ -921,9 +921,8 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping { * * @return array */ - protected static function getMappingParams($defaults, $v) { + public static function getMappingParams($defaults, $v) { $locationTypeId = NULL; - $phoneTypeId = NULL; $saveMappingFields = $defaults; $saveMappingFields['name'] = CRM_Utils_Array::value('1', $v); @@ -958,14 +957,18 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping { } if (is_numeric(CRM_Utils_Array::value('4', $v))) { - $phoneTypeId = CRM_Utils_Array::value('4', $v); + if ($saveMappingFields['name'] === 'im') { + $saveMappingFields['im_provider_id'] = $v[4]; + } + else { + $saveMappingFields['phone_type_id'] = CRM_Utils_Array::value('4', $v); + } } elseif (is_numeric(CRM_Utils_Array::value('6', $v))) { - $phoneTypeId = CRM_Utils_Array::value('6', $v); + $saveMappingFields['phone_type_id'] = CRM_Utils_Array::value('6', $v); } $saveMappingFields['location_type_id'] = is_numeric($locationTypeId) ? $locationTypeId : NULL; - $saveMappingFields['phone_type_id'] = is_numeric($phoneTypeId) ? $phoneTypeId : NULL; $saveMappingFields['relationship_type_id'] = $id; $saveMappingFields['relationship_direction'] = "{$first}_{$second}"; } diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 587c1c7337..66499c8fcf 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -178,8 +178,12 @@ class CRM_Export_BAO_Export { isset($exportParams['postal_mailing_export']['postal_mailing_export']) && $exportParams['postal_mailing_export']['postal_mailing_export'] == 1 ); + $mappedFields = []; + foreach ((array) $fields as $field) { + $mappedFields[] = CRM_Core_BAO_Mapping::getMappingParams([], $field); + } - $processor = new CRM_Export_BAO_ExportProcessor($exportMode, $fields, $queryOperator, $mergeSameHousehold, $isPostalOnly, $mergeSameAddress); + $processor = new CRM_Export_BAO_ExportProcessor($exportMode, $mappedFields, $queryOperator, $mergeSameHousehold, $isPostalOnly, $mergeSameAddress); if ($moreReturnProperties) { $processor->setAdditionalRequestedReturnProperties($moreReturnProperties); } diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index 7e71e1cecb..e46800d8af 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -298,7 +298,7 @@ class CRM_Export_BAO_ExportProcessor { * @return array|null */ public function getRequestedFields() { - return $this->requestedFields; + return empty($this->requestedFields) ? NULL : $this->requestedFields; } /** @@ -1157,39 +1157,17 @@ class CRM_Export_BAO_ExportProcessor { * @return array */ public function setRelationshipReturnProperties($value, $relationshipKey) { - $relPhoneTypeId = $relIMProviderId = NULL; - if (!empty($value[2])) { - $relationField = CRM_Utils_Array::value(2, $value); - if (trim(CRM_Utils_Array::value(3, $value))) { - $relLocTypeId = CRM_Utils_Array::value(3, $value); - } - else { - $relLocTypeId = 'Primary'; - } - - if ($relationField == 'phone') { - $relPhoneTypeId = CRM_Utils_Array::value(4, $value); - } - elseif ($relationField == 'im') { - $relIMProviderId = CRM_Utils_Array::value(4, $value); - } - } - elseif (!empty($value[4])) { - $relationField = CRM_Utils_Array::value(4, $value); - $relLocTypeId = CRM_Utils_Array::value(5, $value); - if ($relationField == 'phone') { - $relPhoneTypeId = CRM_Utils_Array::value(6, $value); - } - elseif ($relationField == 'im') { - $relIMProviderId = CRM_Utils_Array::value(6, $value); - } - } - if (in_array($relationField, $this->getValidLocationFields()) && is_numeric($relLocTypeId)) { - $locationName = CRM_Core_PseudoConstant::getName('CRM_Core_BAO_Address', 'location_type_id', $relLocTypeId); - if ($relPhoneTypeId) { + $relationField = $value['name']; + $relIMProviderId = NULL; + $relLocTypeId = CRM_Utils_Array::value('location_type_id', $value); + $locationName = CRM_Core_PseudoConstant::getName('CRM_Core_BAO_Address', 'location_type_id', $relLocTypeId); + $relPhoneTypeId = CRM_Utils_Array::value('phone_type_id', $value, ($locationName ? 'Primary' : NULL)); + $relIMProviderId = CRM_Utils_Array::value('im_provider_id', $value, ($locationName ? 'Primary' : NULL)); + if (in_array($relationField, $this->getValidLocationFields()) && $locationName) { + if ($relationField === 'phone') { $this->relationshipReturnProperties[$relationshipKey]['location'][$locationName]['phone-' . $relPhoneTypeId] = 1; } - elseif ($relIMProviderId) { + elseif ($relationField === 'im') { $this->relationshipReturnProperties[$relationshipKey]['location'][$locationName]['im-' . $relIMProviderId] = 1; } else { @@ -1542,21 +1520,22 @@ class CRM_Export_BAO_ExportProcessor { if ($this->getRequestedFields()) { $returnProperties = []; foreach ($this->getRequestedFields() as $key => $value) { - $fieldName = CRM_Utils_Array::value(1, $value); - if (!$fieldName || $this->isHouseholdMergeRelationshipTypeKey($fieldName)) { + $fieldName = $value['name']; + $locationName = CRM_Core_PseudoConstant::getName('CRM_Core_BAO_Address', 'location_type_id', $value['location_type_id']); + $relationshipTypeKey = !empty($value['relationship_type_id']) ? $value['relationship_type_id'] . '_' . $value['relationship_direction'] : NULL; + if (!$fieldName || $this->isHouseholdMergeRelationshipTypeKey($relationshipTypeKey)) { continue; } - if ($this->isRelationshipTypeKey($fieldName) && (!empty($value[2]) || !empty($value[4]))) { - $returnProperties[$fieldName] = $this->setRelationshipReturnProperties($value, $fieldName); + if ($this->isRelationshipTypeKey($relationshipTypeKey)) { + $returnProperties[$relationshipTypeKey] = $this->setRelationshipReturnProperties($value, $relationshipTypeKey); } - 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 ($locationName) { + if ($fieldName === 'phone') { + $returnProperties['location'][$locationName]['phone-' . $value['phone_type_id'] ?? NULL] = 1; } - elseif ($fieldName == 'im') { - $returnProperties['location'][$locationName]['im-' . CRM_Utils_Array::value(3, $value)] = 1; + elseif ($fieldName === 'im') { + $returnProperties['location'][$locationName]['im-' . $value['im_provider_id'] ?? NULL] = 1; } else { $returnProperties['location'][$locationName][$fieldName] = 1; -- 2.25.1