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

link activity to message template #32

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 29 additions & 2 deletions CRM/Birthdays/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"<a href='%1'>%2</a>",
[
1 => $template_url,
2 => E::ts('Click here')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about the template's title instead of a catchy Click here and win a sports car 😄?

]
)
]
);

$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() ? '<br>' . $template_info_link_text : ''
]
)
);
}
Expand Down Expand Up @@ -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');
}
}