From 8bfb13b94804842e741ab0deb718ee7562b06768 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 9 Jul 2019 11:08:18 +1200 Subject: [PATCH] Remove call to getMappingFields in favour of api call. The getMappingFields function is confusing - it turns out we just need an array of names --- CRM/Activity/Import/Form/MapField.php | 12 ++++-------- CRM/Core/BAO/Mapping.php | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CRM/Activity/Import/Form/MapField.php b/CRM/Activity/Import/Form/MapField.php index 2b2e78053b..4e6f8e79c5 100644 --- a/CRM/Activity/Import/Form/MapField.php +++ b/CRM/Activity/Import/Form/MapField.php @@ -77,6 +77,8 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { /** * Build the form object. + * + * @throws \CiviCRM_API3_Exception */ public function buildQuickForm() { // To save the current mappings. @@ -90,14 +92,8 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { $savedMapping = $this->get('savedMapping'); // Mapping is to be loaded from database. - list($mappingName, $mappingContactType, $mappingLocation, $mappingPhoneType, $mappingRelation) = CRM_Core_BAO_Mapping::getMappingFields($savedMapping); - - // Get loaded Mapping Fields. - $mappingName = CRM_Utils_Array::value('1', $mappingName); - $mappingContactType = CRM_Utils_Array::value('1', $mappingContactType); - $mappingLocation = CRM_Utils_Array::value('1', $mappingLocation); - $mappingPhoneType = CRM_Utils_Array::value('1', $mappingPhoneType); - $mappingRelation = CRM_Utils_Array::value('1', $mappingRelation); + // Get an array of the name values for mapping fields associated with this mapping_id. + $mappingName = CRM_Core_BAO_Mapping::getMappingFieldValues($savedMapping, 'name'); $this->assign('loadedMapping', $savedMapping); $this->set('loadedMapping', $savedMapping); diff --git a/CRM/Core/BAO/Mapping.php b/CRM/Core/BAO/Mapping.php index 039edd4fd3..04fb71b043 100644 --- a/CRM/Core/BAO/Mapping.php +++ b/CRM/Core/BAO/Mapping.php @@ -241,6 +241,22 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping { ]; } + /** + * Get un-indexed array of the field values for the given mapping id. + * + * For example if passing a mapping ID & name the returned array would look like + * ['First field name', 'second field name'] + * + * @param int $mappingID + * @param string $fieldName + * + * @return array + * @throws \CiviCRM_API3_Exception + */ + public static function getMappingFieldValues($mappingID, $fieldName) { + return array_merge(CRM_Utils_Array::collect($fieldName, civicrm_api3('MappingField', 'get', ['mapping_id' => $mappingID, 'return' => $fieldName])['values'])); + } + /** * Check Duplicate Mapping Name. * -- 2.25.1