Add in fixes for CRM-18708 as well as its needed on 4.7 and make minor fix as suggest...
authorSeamus Lee <seamuslee001@gmail.com>
Sun, 5 Jun 2016 06:09:10 +0000 (16:09 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Sun, 5 Jun 2016 06:09:10 +0000 (16:09 +1000)
CRM/Contact/Import/Parser/Contact.php
CRM/Custom/Import/Form/DataSource.php

index 6c63c13429971dec12b749a4c448511a6df5b2a7..2cffc5dc911fcb7c7bff5c4a7b22f8628de1e777 100644 (file)
@@ -1129,7 +1129,23 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser {
     if (empty($params['contact_type'])) {
       $params['contact_type'] = 'Individual';
     }
-    $customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type'], FALSE, FALSE, $csType);
+
+    // get array of subtypes - CRM-18708
+    if (in_array($csType, array('Individual', 'Organization', 'Household'))) {
+      $csType = self::getSubtypes($params['contact_type']);
+    }
+
+    if (is_array($csType)) {
+      // fetch custom fields for every subtype and add it to $customFields array
+      // CRM-18708
+      $customFields = array();
+      foreach ($csType as $cType) {
+        $customFields += CRM_Core_BAO_CustomField::getFields($params['contact_type'], FALSE, FALSE, $cType);
+      }
+    }
+    else {
+      $customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type'], FALSE, FALSE, $csType);
+    }
 
     $addressCustomFields = CRM_Core_BAO_CustomField::getFields('Address');
     $customFields = $customFields + $addressCustomFields;
@@ -2139,6 +2155,24 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser {
     return $allowToCreate;
   }
 
+  /**
+   * get subtypes given the contact type
+   *
+   * @param string $contactType
+   * @return array $subTypes
+   */
+  public static function getSubtypes($contactType) {
+    $subTypes = array();
+    $types = CRM_Contact_BAO_ContactType::subTypeInfo($contactType);
+
+    if (count($types) > 0) {
+      foreach ($types as $type) {
+        $subTypes[] = $type['name'];
+      }
+    }
+    return $subTypes;
+  }
+
   /**
    * Get the possible contact matches.
    *
index fbfd8c3ecda867e19a050464cbeec715c79c131c..c8f72e1347c17fb55afa1272132519a23da23cb4 100644 (file)
@@ -88,9 +88,7 @@ class CRM_Custom_Import_Form_DataSource extends CRM_Import_Form_DataSource {
       'multipleCustomData',
     ));
 
-    $entity = 'multipleCustomData';
-
-    $this->submitFileForMapping('CRM_Custom_Import_Parser_Api', $entity);
+    $this->submitFileForMapping('CRM_Custom_Import_Parser_Api', 'multipleCustomData');
   }
 
 }