summaryrefslogtreecommitdiff
path: root/app/Model/Notification.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-04-22 18:46:04 -0400
committerFrederic Guillot <fred@kanboard.net>2015-04-22 18:46:04 -0400
commitb5163c483c88914ac17e94e275871996f12fc210 (patch)
treebf8cbacf2f260e423d0c08d39fa6b3ed7d777c35 /app/Model/Notification.php
parentc09501497b75c3042471a3da5633f4c6b48e33e9 (diff)
Send notifications with the language of the recipient
Diffstat (limited to 'app/Model/Notification.php')
-rw-r--r--app/Model/Notification.php28
1 files changed, 22 insertions, 6 deletions
diff --git a/app/Model/Notification.php b/app/Model/Notification.php
index 8414b121..5835de54 100644
--- a/app/Model/Notification.php
+++ b/app/Model/Notification.php
@@ -3,6 +3,7 @@
namespace Model;
use Core\Session;
+use Core\Translator;
use Swift_Message;
use Swift_Mailer;
use Swift_TransportException;
@@ -36,7 +37,7 @@ class Notification extends Base
return $this->db
->table(User::TABLE)
- ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email')
+ ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email', User::TABLE.'.language')
->eq('notifications_enabled', '1')
->neq('email', '')
->notin(User::TABLE.'.id', $exclude_users)
@@ -45,7 +46,7 @@ class Notification extends Base
return $this->db
->table(ProjectPermission::TABLE)
- ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email')
+ ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email', User::TABLE.'.language')
->join(User::TABLE, 'id', 'user_id')
->eq('project_id', $project_id)
->eq('notifications_enabled', '1')
@@ -110,19 +111,34 @@ class Notification extends Base
$mailer = Swift_Mailer::newInstance($this->container['mailer']);
- $message = Swift_Message::newInstance()
+ foreach ($users as $user) {
+
+ $this->container['logger']->debug('Send email notification to '.$user['username'].' lang='.$user['language']);
+
+ // Use the user language otherwise use the application language (do not use the session language)
+ if (! empty($user['language'])) {
+ Translator::load($user['language']);
+ }
+ else {
+ Translator::load($this->config->get('application_language', 'en_US'));
+ }
+
+ // Send the message
+ $message = Swift_Message::newInstance()
->setSubject($this->getMailSubject($template, $data))
->setFrom(array(MAIL_FROM => $author ?: 'Kanboard'))
- ->setBody($this->getMailContent($template, $data), 'text/html');
+ ->setBody($this->getMailContent($template, $data), 'text/html')
+ ->setTo(array($user['email'] => $user['name'] ?: $user['username']));
- foreach ($users as $user) {
- $message->setTo(array($user['email'] => $user['name'] ?: $user['username']));
$mailer->send($message);
}
}
catch (Swift_TransportException $e) {
$this->container['logger']->error($e->getMessage());
}
+
+ // Restore locales
+ $this->config->setupTranslations();
}
/**