Update handling of input fields so that the mapping format is accepted.
authoreileen <emcnaughton@wikimedia.org>
Wed, 10 Jul 2019 08:25:02 +0000 (20:25 +1200)
committereileen <emcnaughton@wikimedia.org>
Thu, 11 Jul 2019 09:45:06 +0000 (21:45 +1200)
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
CRM/Export/BAO/Export.php
CRM/Export/BAO/ExportProcessor.php

index d740ce2a2723c5dc96b55dd405b700e6c92e0950..c144b636e33707b08759c495b746d220650c159a 100644 (file)
@@ -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}";
       }
index 587c1c73376cc448243b60018dc480b7037bac9f..66499c8fcf5bfeb1bef6c729874bced35f8808f5 100644 (file)
@@ -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);
     }
index 7e71e1cecb144ef5150254da7a3281ddc9b8bae3..e46800d8af62afd9e6cfb9c83017165397871116 100644 (file)
@@ -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;