Remove call to getMappingFields in favour of api call.
authoreileen <emcnaughton@wikimedia.org>
Mon, 8 Jul 2019 23:08:18 +0000 (11:08 +1200)
committereileen <emcnaughton@wikimedia.org>
Mon, 8 Jul 2019 23:32:14 +0000 (11:32 +1200)
The getMappingFields function is confusing - it turns out we just need an array of names

CRM/Activity/Import/Form/MapField.php
CRM/Core/BAO/Mapping.php

index 2b2e78053b6f877a0779924b5d29b2186cef3523..4e6f8e79c5b9de26a91bbcf0919e966b045f3d86 100644 (file)
@@ -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);
index 039edd4fd3d6cd50e2c2985fd29dafbbecc573d5..04fb71b0435ef8e05c614d15cb9e5201521c4f49 100644 (file)
@@ -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.
    *