Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] Minor code cleanup on the setting of contact greetings. #15949

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 35 additions & 23 deletions CRM/Export/BAO/ExportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1914,31 +1914,14 @@ public function buildMasterCopyArray($sql, $sharedAddress = FALSE) {
while ($dao->fetch()) {
$masterID = $dao->master_id;
$copyID = $dao->copy_id;
$masterPostalGreeting = $dao->master_postal_greeting;
$masterAddressee = $dao->master_addressee;
$copyAddressee = $dao->copy_addressee;

if (!$sharedAddress) {
if (!isset($this->contactGreetingFields[$dao->master_contact_id])) {
$this->contactGreetingFields[$dao->master_contact_id] = $this->replaceMergeTokens($dao->master_contact_id);
}
$masterPostalGreeting = CRM_Utils_Array::value('postal_greeting',
$this->contactGreetingFields[$dao->master_contact_id], $dao->master_postal_greeting
);
$masterAddressee = CRM_Utils_Array::value('addressee',
$this->contactGreetingFields[$dao->master_contact_id], $dao->master_addressee
);

if (!isset($contactGreetingTokens[$dao->copy_contact_id])) {
$this->contactGreetingFields[$dao->copy_contact_id] = $this->replaceMergeTokens($dao->copy_contact_id);
}
$copyPostalGreeting = CRM_Utils_Array::value('postal_greeting',
$this->contactGreetingFields[$dao->copy_contact_id], $dao->copy_postal_greeting
);
$copyAddressee = CRM_Utils_Array::value('addressee',
$this->contactGreetingFields[$dao->copy_contact_id], $dao->copy_addressee
);
}
$this->cacheContactGreetings((int) $dao->master_contact_id);
$this->cacheContactGreetings((int) $dao->copy_contact_id);
$masterPostalGreeting = $this->getContactGreeting((int) $dao->master_contact_id, 'postal_greeting', $dao->master_postal_greeting);
$masterAddressee = $this->getContactGreeting((int) $dao->master_contact_id, 'addressee', $dao->master_addressee);
$copyPostalGreeting = $this->getContactGreeting((int) $dao->copy_contact_id, 'postal_greeting', $dao->copy_postal_greeting);
$copyAddressee = $this->getContactGreeting((int) $dao->copy_contact_id, 'addressee', $dao->copy_addressee);

if (!isset($merge[$masterID])) {
// check if this is an intermediate child
Expand Down Expand Up @@ -2414,4 +2397,33 @@ protected function writeRows(array $headerRows, array $componentDetails) {
);
}

/**
* Cache the greeting fields for the given contact.
*
* @param int $contactID
*/
protected function cacheContactGreetings(int $contactID) {
if (!isset($this->contactGreetingFields[$contactID])) {
$this->contactGreetingFields[$contactID] = $this->replaceMergeTokens($contactID);
}
}

/**
* Get the greeting value for the given contact.
*
* The values have already been cached so we are grabbing the value at this point.
*
* @param int $contactID
* @param string $type
* postal_greeting|addressee|email_greeting
* @param string $default
*
* @return string
*/
protected function getContactGreeting(int $contactID, string $type, string $default) {
return CRM_Utils_Array::value($type,
$this->contactGreetingFields[$contactID], $default
);
}

}