From b5bfb58fca3e4e618bd261a38a326eecda139ef6 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Thu, 6 Apr 2017 18:56:23 +1000 Subject: [PATCH] Toward CRM-20308 & support CRM-19657 Extract using domain from and logged in user from email details into separate function for re-use --- CRM/Contribute/BAO/Contribution.php | 19 ++----------------- CRM/Core/BAO/Domain.php | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 92829c1c0b..a259fb270c 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -4777,23 +4777,8 @@ LIMIT 1;"; if (!empty($pageValues['receipt_from_email'])) { return array($pageValues['receipt_from_name'], $pageValues['receipt_from_email']); } - // If we are still empty fall back to the domain. - $domain = civicrm_api3('domain', 'getsingle', array('id' => CRM_Core_Config::domainID())); - if (!empty($domain['from_email'])) { - return array($domain['from_name'], $domain['from_email']); - } - if (!empty($domain['domain_email'])) { - return array($domain['name'], $domain['domain_email']); - } - $userID = CRM_Core_Session::singleton()->getLoggedInContactID(); - $userName = ''; - $userEmail = ''; - if (!empty($userID)) { - list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID); - } - // If still empty fall back to the logged in user details. - // return empty values no matter what. - return array($userName, $userEmail); + // If we are still empty fall back to the domain or logged in user information. + return CRM_Core_BAO_Domain::getDefaultReceiptFrom(); } /** diff --git a/CRM/Core/BAO/Domain.php b/CRM/Core/BAO/Domain.php index 6b1f6cf2db..6779ff12dc 100644 --- a/CRM/Core/BAO/Domain.php +++ b/CRM/Core/BAO/Domain.php @@ -286,4 +286,28 @@ class CRM_Core_BAO_Domain extends CRM_Core_DAO_Domain { return $siteContacts; } + /** + * CRM-20308 & CRM-19657 + * Return domain information / user information for the useage in receipts + * Try default from adress then fall back to using logged in user details + */ + public function getDefaultReceiptFrom() { + $domain = civicrm_api3('domain', 'getsingle', array('id' => CRM_Core_Config::domainID())); + if (!empty($domain['from_email'])) { + return array($domain['from_name'], $domain['from_email']); + } + if (!empty($domain['domain_email'])) { + return array($domain['name'], $domain['domain_email']); + } + $userID = CRM_Core_Session::singleton()->getLoggedInContactID(); + $userName = ''; + $userEmail = ''; + if (!empty($userID)) { + list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID); + } + // If still empty fall back to the logged in user details. + // return empty values no matter what. + return array($userName, $userEmail); + } + } -- 2.25.1