From 49c591b4ac855624d75128dc8319410120959834 Mon Sep 17 00:00:00 2001 From: Jo Franz Date: Tue, 21 Feb 2023 11:26:18 +0100 Subject: [PATCH] [#31] link activity to message template --- CRM/Birthdays/Mailer.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/CRM/Birthdays/Mailer.php b/CRM/Birthdays/Mailer.php index f432826..6672082 100644 --- a/CRM/Birthdays/Mailer.php +++ b/CRM/Birthdays/Mailer.php @@ -68,13 +68,35 @@ public function sendMailsAndWriteActivity($contacts, $write_activity): int foreach ($contacts as $contact_id => $contact_info) { try { $this->sendMail($contact_id, $this->email_address_from, $contact_info['email'], $this->template_id); + if ($write_activity) { + $template_url = CRM_Utils_System::url( + 'civicrm/admin/messageTemplates/add?action=update', + "id=$this->template_id&reset=1" + ); + + $template_info_link_text = E::ts( + "%1 to edit or see the template. Please note: This might have been changed since sending", + [ + 1 => E::ts( + "%2", + [ + 1 => $template_url, + 2 => E::ts('Click here') + ] + ) + ] + ); + $this->createActivity( $contact_id, E::ts('Successful birthday greeting mail'), E::ts( - 'Successful birthday greeting mail! Template ID %1 has been used.', - [1 => $this->template_id] + "Successful birthday greeting mail! Template ID %1 has been used.%2", + [ + 1 => $this->template_id, + 2 => $this->mayEditTemplates() ? '
' . $template_info_link_text : '' + ] ) ); } @@ -140,4 +162,9 @@ private function createActivity($target_id, $title, $description): void Civi::log()->debug(E::LONG_NAME . ' ' . "Unable to write activity: $exception"); } } + + private function mayEditTemplates(): bool + { + return CRM_Core_Permission::check('edit message templates'); + } } \ No newline at end of file