Feat: Implement email notification about new disposition
This commit is contained in:
@@ -4,17 +4,20 @@ namespace App\Controller\Admin\Application;
|
||||
|
||||
use App\Entity\Application;
|
||||
use App\Entity\Disposition;
|
||||
use App\Event\DispositionCreatedEvent;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
class DisposeController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly EventDispatcherInterface $eventDispatcher,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
@@ -30,6 +33,8 @@ class DisposeController extends AbstractController
|
||||
$this->entityManager->remove($application);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->eventDispatcher->dispatch(new DispositionCreatedEvent($disposition), DispositionCreatedEvent::NAME);
|
||||
|
||||
$this->addFlash('success', 'Der Teamer wurde eingeteilt');
|
||||
$this->logger->info('Create disposition', [
|
||||
'disposition_id' => $disposition->getId(),
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Email;
|
||||
|
||||
use App\Entity\User;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class WelcomeEmailMailer
|
||||
{
|
||||
public function __construct(private readonly Mailer $mailer, private readonly LoggerInterface $logger)
|
||||
{}
|
||||
|
||||
public function send(User $user): void
|
||||
{
|
||||
$this->mailer->createAndSendEmail([
|
||||
'user' => $user,
|
||||
], [
|
||||
'to' => $user->getEmail(),
|
||||
'subject' => 'Willkommen bei MyE&P Team',
|
||||
'template' => 'email/welcome.html.twig',
|
||||
]);
|
||||
|
||||
$this->logger->info('Send welcome email', [
|
||||
'user_id' => $user->getId(),
|
||||
'user_email' => $user->getEmail(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -51,11 +51,10 @@ class Destination implements TimestampableEntityInterface, SoftDeletableEntityIn
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return sprintf('%s - %s: %s, %s',
|
||||
return sprintf('%s - %s %s',
|
||||
$this->getDateFrom()->format('d.m.y'),
|
||||
$this->getDateTo()->format('d.m.y'),
|
||||
$this->getProduct(),
|
||||
$this->getHotel()
|
||||
$this->getProduct()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Event;
|
||||
|
||||
use App\Entity\Disposition;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
class DispositionCreatedEvent extends Event
|
||||
{
|
||||
public const NAME = 'disposition.created';
|
||||
|
||||
public function __construct(private readonly Disposition $disposition)
|
||||
{}
|
||||
|
||||
public function getDisposition(): Disposition
|
||||
{
|
||||
return $this->disposition;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\EventListener;
|
||||
|
||||
use App\Email\Mailer;
|
||||
use App\Event\DispositionCreatedEvent;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
class EmailNotificationSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public function __construct(private readonly Mailer $mailer)
|
||||
{
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
DispositionCreatedEvent::NAME => 'onDispositionCreated',
|
||||
];
|
||||
}
|
||||
|
||||
public function onDispositionCreated(DispositionCreatedEvent $event): void
|
||||
{
|
||||
$disposition = $event->getDisposition();
|
||||
$teamer = $disposition->getTeamer();
|
||||
|
||||
$this->mailer->createAndSendEmail([
|
||||
'disposition' => $disposition,
|
||||
], [
|
||||
'to' => $teamer->getCommunication()->getEmail(),
|
||||
'subject' => 'Dein Einsatz wurde angenommen',
|
||||
'template' => 'email/application_accepted.html.twig',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user