From 288db2d22a766b17ca65271f2afad7d9bf1b1143 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 31 May 2022 15:56:53 +1200 Subject: [PATCH] [Import] [Ref] Additional functions, typo fix The functions are not yet used -in the interests of managing conflicts" --- CRM/Contribute/Import/Parser/Contribution.php | 30 +++++++++++++++++++ CRM/Import/Parser.php | 23 +++++++++++++- .../CRM/Contribute/Import/Form/MapField.tpl | 2 +- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/CRM/Contribute/Import/Parser/Contribution.php b/CRM/Contribute/Import/Parser/Contribution.php index 9cccef2f90..0daba3335e 100644 --- a/CRM/Contribute/Import/Parser/Contribution.php +++ b/CRM/Contribute/Import/Parser/Contribution.php @@ -466,6 +466,36 @@ class CRM_Contribute_Import_Parser_Contribution extends CRM_Import_Parser { return $params; } + /** + * Transform the input parameters into the form handled by the input routine. + * + * @param array $values + * Input parameters as they come in from the datasource + * eg. ['Bob', 'Smith', 'bob@example.org', '123-456'] + * + * @return array + * Parameters mapped to CiviCRM fields based on the mapping. eg. + * [ + * 'total_amount' => '1230.99', + * 'financial_type_id' => 1, + * 'external_identifier' => 'abcd', + * 'soft_credit' => [3 => ['external_identifier' => '123', 'soft_credit_type_id' => 1]] + * + * @throws \API_Exception + */ + public function getMappedRow(array $values): array { + $params = []; + foreach ($this->getFieldMappings() as $i => $mappedField) { + if (!empty($mappedField['soft_credit_match_field'])) { + $params['soft_credit'][$i] = ['soft_credit_type_id' => $mappedField['soft_credit_type_id'], $mappedField['soft_credit_match_field'] => $values[$i]]; + } + else { + $params[$this->getFieldMetadata($mappedField['name'])['name']] = $values[$i]; + } + } + return $params; + } + /** * @param string $name * @param $title diff --git a/CRM/Import/Parser.php b/CRM/Import/Parser.php index dd4bd916de..4ea35b98c4 100644 --- a/CRM/Import/Parser.php +++ b/CRM/Import/Parser.php @@ -330,7 +330,7 @@ abstract class CRM_Import_Parser { * file * @var array */ - protected $_activeFields; + protected $_activeFields = []; /** * Cache the count of active fields @@ -1512,4 +1512,25 @@ abstract class CRM_Import_Parser { return !empty($this->ambiguousOptions[$fieldName][mb_strtolower($importedValue)]); } + /** + * Get the field mappings for the import. + * + * This is the same format as saved in civicrm_mapping_field except + * that location_type_id = 'Primary' rather than empty where relevant. + * Also 'im_provider_id' is mapped to the 'real' field name 'provider_id' + * + * @return array + * @throws \API_Exception + */ + protected function getFieldMappings(): array { + $mappedFields = []; + foreach ($this->getSubmittedValue('mapper') as $i => $mapperRow) { + $mappedField = $this->getMappingFieldFromMapperInput($mapperRow, 0, $i); + // Just for clarity since 0 is a pseudo-value + unset($mappedField['mapping_id']); + $mappedFields[] = $mappedField; + } + return $mappedFields; + } + } diff --git a/templates/CRM/Contribute/Import/Form/MapField.tpl b/templates/CRM/Contribute/Import/Form/MapField.tpl index 817b2a0c48..6ab1ca0585 100644 --- a/templates/CRM/Contribute/Import/Form/MapField.tpl +++ b/templates/CRM/Contribute/Import/Form/MapField.tpl @@ -19,7 +19,7 @@
{include file="CRM/common/formButtons.tpl" location="top"}
{* Table for mapping data to CRM fields *} - {include file="CRM/Contribute/Import/Form/MapTable.tpl} + {include file="CRM/Contribute/Import/Form/MapTable.tpl"}
{include file="CRM/common/formButtons.tpl" location="bottom"}
{$initHideBoxes|smarty:nodefaults} -- 2.25.1