Resolve "Notification aux groupes utilisateurs"

This commit is contained in:
2026-03-16 14:08:35 +00:00
parent 81193376a4
commit dd429ca02a
13 changed files with 562 additions and 48 deletions

View File

@@ -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;
}