mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-11-23 12:27:44 +00:00
Ajouter une variable de localisation aux utilisateurs
This commit is contained in:
@@ -24,6 +24,8 @@ use Symfony\Component\Mime\Email;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
// use Symfony\Component\Translation\LocaleSwitcher;
|
||||
|
||||
readonly class NotificationMailer
|
||||
{
|
||||
public function __construct(
|
||||
@@ -31,6 +33,7 @@ readonly class NotificationMailer
|
||||
private LoggerInterface $logger,
|
||||
private MessageBusInterface $messageBus,
|
||||
private TranslatorInterface $translator,
|
||||
// private LocaleSwitcher $localeSwitcher,
|
||||
) {}
|
||||
|
||||
public function postPersistComment(NotificationComment $comment, PostPersistEventArgs $eventArgs): void
|
||||
@@ -56,7 +59,7 @@ readonly class NotificationMailer
|
||||
$email
|
||||
->to($dest->getEmail())
|
||||
->subject('Re: '.$comment->getNotification()->getTitle())
|
||||
->textTemplate('@ChillMain/Notification/email_notification_comment_persist.fr.md.twig')
|
||||
->textTemplate('@ChillMain/Notification/email_notification_comment_persist.md.twig')
|
||||
->context([
|
||||
'comment' => $comment,
|
||||
'dest' => $dest,
|
||||
@@ -137,13 +140,53 @@ readonly class NotificationMailer
|
||||
return;
|
||||
}
|
||||
|
||||
// Implementation with LocaleSwitcher (commented out - to be activated after migration to sf7.2):
|
||||
/*
|
||||
$this->localeSwitcher->runWithLocale($addressee->getLocale(), function () use ($notification, $addressee) {
|
||||
if ($notification->isSystem()) {
|
||||
$email = new Email();
|
||||
$email->text($notification->getMessage());
|
||||
} else {
|
||||
$email = new TemplatedEmail();
|
||||
$email
|
||||
->textTemplate('@ChillMain/Notification/email_non_system_notification_content.md.twig')
|
||||
->context([
|
||||
'notification' => $notification,
|
||||
'dest' => $addressee,
|
||||
]);
|
||||
}
|
||||
|
||||
$email
|
||||
->subject($notification->getTitle())
|
||||
->to($addressee->getEmail());
|
||||
|
||||
try {
|
||||
$this->mailer->send($email);
|
||||
$this->logger->info('[NotificationMailer] Email sent successfully', [
|
||||
'notification_id' => $notification->getId(),
|
||||
'addressee_email' => $addressee->getEmail(),
|
||||
'locale' => $addressee->getLocale(),
|
||||
]);
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$this->logger->warning('[NotificationMailer] Could not send an email notification', [
|
||||
'to' => $addressee->getEmail(),
|
||||
'notification_id' => $notification->getId(),
|
||||
'error_message' => $e->getMessage(),
|
||||
'error_trace' => $e->getTraceAsString(),
|
||||
]);
|
||||
throw $e;
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
// Current implementation:
|
||||
if ($notification->isSystem()) {
|
||||
$email = new Email();
|
||||
$email->text($notification->getMessage());
|
||||
} else {
|
||||
$email = new TemplatedEmail();
|
||||
$email
|
||||
->textTemplate('@ChillMain/Notification/email_non_system_notification_content.fr.md.twig')
|
||||
->textTemplate('@ChillMain/Notification/email_non_system_notification_content.md.twig')
|
||||
->context([
|
||||
'notification' => $notification,
|
||||
'dest' => $addressee,
|
||||
@@ -182,9 +225,43 @@ readonly class NotificationMailer
|
||||
return;
|
||||
}
|
||||
|
||||
// Implementation with LocaleSwitcher (commented out - to be activated after migration to sf7.2):
|
||||
/*
|
||||
$this->localeSwitcher->runWithLocale($user->getLocale(), function () use ($user, $notifications) {
|
||||
$email = new TemplatedEmail();
|
||||
$email
|
||||
->htmlTemplate('@ChillMain/Notification/email_daily_digest.md.twig')
|
||||
->context([
|
||||
'user' => $user,
|
||||
'notifications' => $notifications,
|
||||
'notification_count' => count($notifications),
|
||||
])
|
||||
->subject($this->translator->trans('notification.Daily Notification Digest'))
|
||||
->to($user->getEmail());
|
||||
|
||||
try {
|
||||
$this->mailer->send($email);
|
||||
$this->logger->info('[NotificationMailer] Daily digest email sent successfully', [
|
||||
'user_email' => $user->getEmail(),
|
||||
'notification_count' => count($notifications),
|
||||
'locale' => $user->getLocale(),
|
||||
]);
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$this->logger->warning('[NotificationMailer] Could not send daily digest email', [
|
||||
'to' => $user->getEmail(),
|
||||
'notification_count' => count($notifications),
|
||||
'error_message' => $e->getMessage(),
|
||||
'error_trace' => $e->getTraceAsString(),
|
||||
]);
|
||||
throw $e;
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
// Current implementation:
|
||||
$email = new TemplatedEmail();
|
||||
$email
|
||||
->htmlTemplate('@ChillMain/Notification/email_daily_digest.fr.md.twig')
|
||||
->htmlTemplate('@ChillMain/Notification/email_daily_digest.md.twig')
|
||||
->context([
|
||||
'user' => $user,
|
||||
'notifications' => $notifications,
|
||||
@@ -222,7 +299,7 @@ readonly class NotificationMailer
|
||||
|
||||
$email = new TemplatedEmail();
|
||||
$email
|
||||
->textTemplate('@ChillMain/Notification/email_non_system_notification_content_to_email.fr.md.twig')
|
||||
->textTemplate('@ChillMain/Notification/email_non_system_notification_content_to_email.md.twig')
|
||||
->context([
|
||||
'notification' => $notification,
|
||||
'dest' => $emailAddress,
|
||||
|
||||
Reference in New Issue
Block a user