From 8aeeea00b7877acb34492be781b1a588b7511980 Mon Sep 17 00:00:00 2001 From: Erik Hommel Date: Tue, 4 Apr 2017 09:17:43 +0200 Subject: [PATCH] CRM-20308 added method getReceiptFrom to set FROM in sendActivityCopy - send email to assignee --- CRM/Case/BAO/Case.php | 60 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 78943a5254..7290a33207 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -1347,9 +1347,8 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c } $result = array(); - list($name, $address) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID); - - $receiptFrom = "$name <$address>"; + // CRM-20308 get receiptFrom defaults see https://issues.civicrm.org/jira/browse/CRM-20308 + $receiptFrom = self::getReceiptFrom($activityId); $recordedActivityParams = array(); @@ -3170,4 +3169,59 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')'; return $clauses; } + /** + * CRM-20308 + * Method to get the contact id to use as from contact for email copy + * 1. Activity Added by Contact's email address + * 2. System Default From Address + * 3. Default Organization Contact email address + * 4. Logged in user + * + * @param int $activityId + * @return mixed $emailFromContactId + * @see https://issues.civicrm.org/jira/browse/CRM-20308 + */ + private static function getReceiptFrom($activityId) { + $emailFromContactId = NULL; + if (!empty($activityId)) { + try { + $emailFromContactId = civicrm_api3('ActivityContact', 'getvalue', array( + 'activity_id' => $activityId, + 'record_type_id' => 'Activity Source', + 'return' => 'contact_id', + )); + } + catch (CiviCRM_API3_Exception $ex) { + // get default from address from domain + try { + $domain = civicrm_api3('Domain', 'getsingle', array('id' => CRM_Core_Config::domainID())); + if (isset($domain['from_email'])) { + $emailFromContactId = $domain['from_email']; + } + } + catch (CiviCRM_API3_Exception $ex) { + } + // if not found get email for contact_id 1 + if (!$emailFromContactId) { + try { + $emailFromContactId = civicrm_api3('Email', 'getvalue', array( + 'contact_id' => 1, + 'return' => 'email', + )); + } + catch (CiviCRM_API3_Exception $ex) { + } + } + } + + } + // if not found, use logged in user + if (!$emailFromContactId) { + $session = CRM_Core_Session::singleton(); + $emailFromContactId = $session->get('userID'); + } + list($name, $address) = CRM_Contact_BAO_Contact_Location::getEmailDetails($emailFromContactId); + return "$name <$address>"; + } + } -- 2.25.1