From cefcb834d7d500afa1a431ff95600c2fdcc73369 Mon Sep 17 00:00:00 2001 From: Liquidsoul Date: Thu, 18 Apr 2019 11:10:45 +0200 Subject: [PATCH] Extract poll update notification mails into smarty templates --- .../Services/NotificationService.php | 42 +++++++------------ tpl/mail/added_comment.html.tpl | 3 ++ tpl/mail/added_vote.html.tpl | 3 ++ tpl/mail/deleted_poll.html.tpl | 1 + tpl/mail/updated_poll.html.tpl | 1 + tpl/mail/updated_vote.html.tpl | 3 ++ 6 files changed, 27 insertions(+), 26 deletions(-) create mode 100644 tpl/mail/added_comment.html.tpl create mode 100644 tpl/mail/added_vote.html.tpl create mode 100644 tpl/mail/deleted_poll.html.tpl create mode 100644 tpl/mail/updated_poll.html.tpl create mode 100644 tpl/mail/updated_vote.html.tpl diff --git a/app/classes/Framadate/Services/NotificationService.php b/app/classes/Framadate/Services/NotificationService.php index d0941a3..18ff1a3 100644 --- a/app/classes/Framadate/Services/NotificationService.php +++ b/app/classes/Framadate/Services/NotificationService.php @@ -14,6 +14,14 @@ class NotificationService { const UPDATE_POLL = 10; const DELETED_POLL = 11; + const TEMPLATES_MAPPING = [ + self::UPDATE_VOTE => 'mail/updated_vote.html.tpl', + self::ADD_VOTE => 'mail/added_vote.html.tpl', + self::ADD_COMMENT => 'mail/added_comment.html.tpl', + self::UPDATE_POLL => 'mail/updated_poll.html.tpl', + self::DELETED_POLL => 'mail/deleted_poll.html.tpl' + ]; + private $mailService; private $smarty; @@ -47,35 +55,17 @@ class NotificationService { $subject = '[' . NOMAPPLICATION . '] ' . __f('Mail', $translationString, $poll->title); - $message = ''; + $this->smarty->assign('username', $name); + $this->smarty->assign('poll_title', $poll->title); + $this->smarty->assign('poll_url', Utils::getUrlSondage($poll->admin_id, true)); - $urlSondage = Utils::getUrlSondage($poll->admin_id, true); - $link = '' . $urlSondage . '' . "\n\n"; + $template_name = self::TEMPLATES_MAPPING[$type]; - switch ($type) { - case self::UPDATE_VOTE: - $message .= $name . ' '; - $message .= __('Mail', "updated a vote.
You can visit your poll at the link") . " :\n\n"; - $message .= $link; - break; - case self::ADD_VOTE: - $message .= $name . ' '; - $message .= __('Mail', "added a vote.
You can visit your poll at the link") . " :\n\n"; - $message .= $link; - break; - case self::ADD_COMMENT: - $message .= $name . ' '; - $message .= __('Mail', "wrote a comment.
You can visit your poll at the link") . " :\n\n"; - $message .= $link; - break; - case self::UPDATE_POLL: - $message = __f('Mail', 'Someone just changed your poll at the following link %1$s.', Utils::getUrlSondage($poll->admin_id, true)) . "\n\n"; - break; - case self::DELETED_POLL: - $message = __f('Mail', 'Someone just deleted your poll "%s".', Utils::htmlEscape($poll->title)) . "\n\n"; - break; + if (!is_null($template_name)) { + $message = $this->smarty->fetch($template_name); + } else { + $message = ''; } - $messageTypeKey = $type . '-' . $poll->id; $this->mailService->send($poll->admin_mail, $subject, $message, $messageTypeKey); } diff --git a/tpl/mail/added_comment.html.tpl b/tpl/mail/added_comment.html.tpl new file mode 100644 index 0000000..2492dbb --- /dev/null +++ b/tpl/mail/added_comment.html.tpl @@ -0,0 +1,3 @@ +{$username|html} {__('Mail', "wrote a comment.
You can visit your poll at the link")} + +{$poll_url} diff --git a/tpl/mail/added_vote.html.tpl b/tpl/mail/added_vote.html.tpl new file mode 100644 index 0000000..3ae0514 --- /dev/null +++ b/tpl/mail/added_vote.html.tpl @@ -0,0 +1,3 @@ +{$username|html} {__('Mail', "added a vote.
You can visit your poll at the link")} + +{$poll_url} diff --git a/tpl/mail/deleted_poll.html.tpl b/tpl/mail/deleted_poll.html.tpl new file mode 100644 index 0000000..99ac13b --- /dev/null +++ b/tpl/mail/deleted_poll.html.tpl @@ -0,0 +1 @@ +{__f('Mail', 'Someone just deleted your poll "%s".', $poll_title|html)} diff --git a/tpl/mail/updated_poll.html.tpl b/tpl/mail/updated_poll.html.tpl new file mode 100644 index 0000000..cb04d5c --- /dev/null +++ b/tpl/mail/updated_poll.html.tpl @@ -0,0 +1 @@ +{__f('Mail', 'Someone just changed your poll at the following link %1$s.', $poll_url)} diff --git a/tpl/mail/updated_vote.html.tpl b/tpl/mail/updated_vote.html.tpl new file mode 100644 index 0000000..55b8b47 --- /dev/null +++ b/tpl/mail/updated_vote.html.tpl @@ -0,0 +1,3 @@ +{$username|html} {__('Mail', "updated a vote.
You can visit your poll at the link")} + +{$poll_url}