From 6aa6310f853553136bc4fc8f18fa94514ccf641c Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sun, 5 Jun 2016 16:09:10 +1000 Subject: [PATCH] Add in fixes for CRM-18708 as well as its needed on 4.7 and make minor fix as suggested by Coleman --- CRM/Contact/Import/Parser/Contact.php | 36 ++++++++++++++++++++++++++- CRM/Custom/Import/Form/DataSource.php | 4 +-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index 6c63c13429..2cffc5dc91 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -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. * diff --git a/CRM/Custom/Import/Form/DataSource.php b/CRM/Custom/Import/Form/DataSource.php index fbfd8c3ecd..c8f72e1347 100644 --- a/CRM/Custom/Import/Form/DataSource.php +++ b/CRM/Custom/Import/Form/DataSource.php @@ -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'); } } -- 2.25.1