Unverified Commit e9153e22 authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub
Browse files

Merge pull request #14799 from eileenmcnaughton/move_ex

[REF] [Export] Move replace merge tokens to processor class
parents 7ab4afbc 571f3b5b
......@@ -688,43 +688,6 @@ WHERE id IN ( $deleteIDString )
}
}
/**
* @param int $contactId
* @param array $exportParams
*
* @return array
*/
public static function _replaceMergeTokens($contactId, $exportParams) {
$greetings = [];
$contact = NULL;
$greetingFields = [
'postal_greeting',
'addressee',
];
foreach ($greetingFields as $greeting) {
if (!empty($exportParams[$greeting])) {
$greetingLabel = $exportParams[$greeting];
if (empty($contact)) {
$values = [
'id' => $contactId,
'version' => 3,
];
$contact = civicrm_api('contact', 'get', $values);
if (!empty($contact['is_error'])) {
return $greetings;
}
$contact = $contact['values'][$contact['id']];
}
$tokens = ['contact' => $greetingLabel];
$greetings[$greeting] = CRM_Utils_Token::replaceContactTokens($greetingLabel, $contact, NULL, $tokens);
}
}
return $greetings;
}
/**
* @param \CRM_Export_BAO_ExportProcessor $processor
* @param $sql
......@@ -751,7 +714,7 @@ WHERE id IN ( $deleteIDString )
if (!$sharedAddress) {
if (!isset($contactGreetingTokens[$dao->master_contact_id])) {
$contactGreetingTokens[$dao->master_contact_id] = self::_replaceMergeTokens($dao->master_contact_id, $exportParams);
$contactGreetingTokens[$dao->master_contact_id] = $processor->replaceMergeTokens($dao->master_contact_id, $exportParams);
}
$masterPostalGreeting = CRM_Utils_Array::value('postal_greeting',
$contactGreetingTokens[$dao->master_contact_id], $dao->master_postal_greeting
......@@ -761,7 +724,7 @@ WHERE id IN ( $deleteIDString )
);
if (!isset($contactGreetingTokens[$dao->copy_contact_id])) {
$contactGreetingTokens[$dao->copy_contact_id] = self::_replaceMergeTokens($dao->copy_contact_id, $exportParams);
$contactGreetingTokens[$dao->copy_contact_id] = $processor->replaceMergeTokens($dao->copy_contact_id, $exportParams);
}
$copyPostalGreeting = CRM_Utils_Array::value('postal_greeting',
$contactGreetingTokens[$dao->copy_contact_id], $dao->copy_postal_greeting
......
......@@ -1609,6 +1609,43 @@ class CRM_Export_BAO_ExportProcessor {
return $returnProperties;
}
/**
* @param int $contactId
* @param array $exportParams
*
* @return array
*/
public function replaceMergeTokens($contactId, $exportParams) {
$greetings = [];
$contact = NULL;
$greetingFields = [
'postal_greeting',
'addressee',
];
foreach ($greetingFields as $greeting) {
if (!empty($exportParams[$greeting])) {
$greetingLabel = $exportParams[$greeting];
if (empty($contact)) {
$values = [
'id' => $contactId,
'version' => 3,
];
$contact = civicrm_api('contact', 'get', $values);
if (!empty($contact['is_error'])) {
return $greetings;
}
$contact = $contact['values'][$contact['id']];
}
$tokens = ['contact' => $greetingLabel];
$greetings[$greeting] = CRM_Utils_Token::replaceContactTokens($greetingLabel, $contact, NULL, $tokens);
}
}
return $greetings;
}
/**
* The function unsets static part of the string, if token is the dynamic part.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment