diff --git a/app/classes/Framadate/Services/NotificationService.php b/app/classes/Framadate/Services/NotificationService.php
index 38d51d3..fc0c2ba 100644
--- a/app/classes/Framadate/Services/NotificationService.php
+++ b/app/classes/Framadate/Services/NotificationService.php
@@ -13,6 +13,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;
@@ -46,35 +54,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}