CRM-18708: subtype custom field import issue
authorroot <nishant.bhorodia@gmail.com>
Thu, 2 Jun 2016 12:08:17 +0000 (17:38 +0530)
committerSeamus Lee <seamuslee001@gmail.com>
Sun, 5 Jun 2016 06:19:23 +0000 (16:19 +1000)
CRM/Contact/Import/Parser/Contact.php

index 1fc0cde3a8406c33a31f5061034777e87d9edd7d..96464689bb72d6b1e856c187e5a0a1ba1a21aac8 100644 (file)
@@ -1139,7 +1139,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;
@@ -2142,4 +2158,22 @@ 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;
+  }
+
 }