Skip to content

Commit

Permalink
Add import function to parser
Browse files Browse the repository at this point in the history
This function is not used in this PR but added in
#23288
- however, that PR is a bit stalled & getting the function added also allows
for other places to call it (ie kill off the enotices on the preview
screen and remove all the silly parameters in the construct)
so trying to get just the function merged
  • Loading branch information
eileenmcnaughton committed May 2, 2022
1 parent 1062500 commit 1c89bb3
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions CRM/Contact/Import/Parser/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -3533,4 +3533,38 @@ protected function fillPrimary(&$params, $values, $entity, $contactID) {
}
}

/**
* Get the civicrm_mapping_field appropriate layout for the mapper input.
*
* The input looks something like ['street_address', 1]
* and would be mapped to ['name' => 'street_address', 'location_type_id' => 1]
*
* @param array $fieldMapping
* @param int $mappingID
* @param int $columnNumber
*
* @return array
*/
public function getMappingFieldFromMapperInput(array $fieldMapping, int $mappingID, int $columnNumber): array {
$isRelationshipField = preg_match('/\d*_a_b|b_a$/', $fieldMapping[0]);
$fieldName = $isRelationshipField ? $fieldMapping[1] : $fieldMapping[0];
$locationTypeID = NULL;
$possibleLocationField = $isRelationshipField ? 2 : 1;
if ($fieldName !== 'url' && is_numeric($fieldMapping[$possibleLocationField] ?? NULL)) {
$locationTypeID = $fieldMapping[$possibleLocationField];
}
return [
'name' => $fieldName,
'mapping_id' => $mappingID,
'relationship_type_id' => $isRelationshipField ? substr($fieldMapping[1], 0, -4) : NULL,
'relationship_direction' => $isRelationshipField ? substr($fieldMapping[1], -4) : NULL,
'column_number' => $columnNumber,
'contact_type' => $this->getContactType(),
'website_type_id' => $fieldName !== 'url' ? NULL : ($isRelationshipField ? $fieldMapping[2] : $fieldMapping[1]),
'phone_type_id' => $fieldName !== 'phone' ? NULL : ($isRelationshipField ? $fieldMapping[3] : $fieldMapping[2]),
'im_provider_id' => $fieldName !== 'im' ? NULL : ($isRelationshipField ? $fieldMapping[3] : $fieldMapping[2]),
'location_type_id' => $locationTypeID,
];
}

}

0 comments on commit 1c89bb3

Please sign in to comment.