Skip to content

Commit

Permalink
Merge pull request #16222 from colemanw/importable
Browse files Browse the repository at this point in the history
Refactor CRM_Contact_BAO_Contact::importableFields() to use metadata
  • Loading branch information
eileenmcnaughton authored Jan 7, 2020
2 parents d6e58a7 + b383d04 commit 44841fe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 48 deletions.
53 changes: 7 additions & 46 deletions CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -1384,54 +1384,15 @@ public static function importableFields(
$withMultiCustomFields
)
);
//unset the fields, which are not related to their
//contact type.
$commonValues = [
'Individual' => [
'household_name',
'legal_name',
'sic_code',
'organization_name',
],
'Household' => [
'first_name',
'middle_name',
'last_name',
'formal_title',
'job_title',
'gender_id',
'prefix_id',
'suffix_id',
'birth_date',
'organization_name',
'legal_name',
'legal_identifier',
'sic_code',
'home_URL',
'is_deceased',
'deceased_date',
],
'Organization' => [
'first_name',
'middle_name',
'last_name',
'formal_title',
'job_title',
'gender_id',
'prefix_id',
'suffix_id',
'birth_date',
'household_name',
'is_deceased',
'deceased_date',
],
];
foreach ($commonValues[$contactType] as $value) {
unset($fields[$value]);
// Unset the fields which are not related to their contact type.
foreach (CRM_Contact_DAO_Contact::import() as $name => $value) {
if (!empty($value['contactType']) && $value['contactType'] !== $contactType) {
unset($fields[$name]);
}
}
}
else {
foreach (['Individual', 'Household', 'Organization'] as $type) {
foreach (CRM_Contact_BAO_ContactType::basicTypes() as $type) {
$fields = array_merge($fields,
CRM_Core_BAO_CustomField::getFieldsForImport($type,
$showAll,
Expand Down Expand Up @@ -1604,7 +1565,7 @@ public static function &exportableFields($contactType = 'Individual', $status =
);
}
else {
foreach (['Individual', 'Household', 'Organization'] as $type) {
foreach (CRM_Contact_BAO_ContactType::basicTypes() as $type) {
$fields = array_merge($fields,
CRM_Core_BAO_CustomField::getFieldsForImport($type, FALSE, FALSE, $search, $checkPermissions, $withMultiRecord)
);
Expand Down
3 changes: 2 additions & 1 deletion CRM/Contact/DAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Contact/Contact.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:773bf2fc16c1af3c283f6ecc7098e927)
* (GenCodeChecksum:4b1e2ef9f5c431f59befcc000cb35577)
*/

/**
Expand Down Expand Up @@ -688,6 +688,7 @@ public static function &fields() {
'where' => 'civicrm_contact.legal_name',
'headerPattern' => '/^legal|(l(egal\s)?name)$/i',
'export' => TRUE,
'contactType' => 'Organization',
'table_name' => 'civicrm_contact',
'entity' => 'Contact',
'bao' => 'CRM_Contact_BAO_Contact',
Expand Down
2 changes: 1 addition & 1 deletion xml/schema/Contact/Contact.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
<type>Text</type>
<size>30</size>
</html>

<contactType>Organization</contactType>
<import>true</import>
<headerPattern>/^legal|(l(egal\s)?name)$/i</headerPattern>
<comment>Legal Name.</comment>
Expand Down

0 comments on commit 44841fe

Please sign in to comment.