mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-03-18 03:38:05 +00:00
Resolve "Notification aux groupes utilisateurs"
This commit is contained in:
@@ -14,6 +14,7 @@ namespace Chill\MainBundle\Notification\Email;
|
||||
use Chill\MainBundle\Entity\Notification;
|
||||
use Chill\MainBundle\Entity\NotificationComment;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\UserGroup;
|
||||
use Chill\MainBundle\Notification\Email\NotificationEmailMessages\SendImmediateNotificationEmailMessage;
|
||||
use Doctrine\ORM\Event\PostPersistEventArgs;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@@ -26,13 +27,13 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
// use Symfony\Component\Translation\LocaleSwitcher;
|
||||
|
||||
readonly class NotificationMailer
|
||||
class NotificationMailer
|
||||
{
|
||||
public function __construct(
|
||||
private MailerInterface $mailer,
|
||||
private LoggerInterface $logger,
|
||||
private MessageBusInterface $messageBus,
|
||||
private TranslatorInterface $translator,
|
||||
private readonly MailerInterface $mailer,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly MessageBusInterface $messageBus,
|
||||
private readonly TranslatorInterface $translator,
|
||||
// private LocaleSwitcher $localeSwitcher,
|
||||
) {}
|
||||
|
||||
@@ -100,25 +101,24 @@ readonly class NotificationMailer
|
||||
if (null === $addressee->getEmail()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->processNotificationForAddressee($notification, $addressee);
|
||||
}
|
||||
}
|
||||
|
||||
private function processNotificationForAddressee(Notification $notification, User $addressee): void
|
||||
private function processNotificationForAddressee(Notification $notification, User|UserGroup $addressee): void
|
||||
{
|
||||
$notificationType = $notification->getType();
|
||||
|
||||
if ($addressee->isNotificationSendImmediately($notificationType)) {
|
||||
if ($addressee instanceof UserGroup || $addressee->isNotificationSendImmediately($notificationType)) {
|
||||
$this->scheduleImmediateEmail($notification, $addressee);
|
||||
}
|
||||
}
|
||||
|
||||
private function scheduleImmediateEmail(Notification $notification, User $addressee): void
|
||||
private function scheduleImmediateEmail(Notification $notification, User|UserGroup $addressee): void
|
||||
{
|
||||
$message = new SendImmediateNotificationEmailMessage(
|
||||
$notification->getId(),
|
||||
$addressee->getId()
|
||||
$notification,
|
||||
$addressee,
|
||||
);
|
||||
|
||||
$this->messageBus->dispatch($message);
|
||||
@@ -130,13 +130,17 @@ readonly class NotificationMailer
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sends the email but is now called by the immediate notification email message handler.
|
||||
* Send an email about a Notification.
|
||||
*
|
||||
* It is called by immediate notification email message handler:
|
||||
*
|
||||
* @see{\Chill\MainBundle\Notification\Email\NotificationEmailHandlers\SendImmediateNotificationEmailHandler}
|
||||
*
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
public function sendEmailToAddressee(Notification $notification, User $addressee): void
|
||||
public function sendEmailToAddressee(Notification $notification, User|UserGroup $addressee): void
|
||||
{
|
||||
if (null === $addressee->getEmail()) {
|
||||
if (null === $addressee->getEmail() || '' === $addressee->getEmail()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user