feat: send disposition reminder emails

This commit is contained in:
Björn Fromme
2025-01-13 16:09:07 +01:00
parent c5df1c2a67
commit f3840425b1
3 changed files with 99 additions and 1 deletions
+6 -1
View File
@@ -2,6 +2,7 @@
namespace App\Command;
use App\Service\Cron\DispositionReminderService;
use App\Service\Cron\DispositionStatusService;
use App\Service\Cron\FeedbackReminderService;
use App\Service\Cron\FlushLogsService;
@@ -22,7 +23,8 @@ class CronCommand extends Command
private readonly FlushLogsService $flushLogsService,
private readonly UploadReminderService $uploadReminderService,
private readonly FeedbackReminderService $feedbackReminderService,
private readonly DispositionStatusService $dispositionStatusService
private readonly DispositionStatusService $dispositionStatusService,
private readonly DispositionReminderService $dispositionReminderService,
) {
parent::__construct();
}
@@ -50,6 +52,9 @@ class CronCommand extends Command
$message = $this->dispositionStatusService->setEndedStatus();
$io->info($message);
$message = $this->dispositionReminderService->sendDispositionReminders();
$io->info($message);
return Command::SUCCESS;
}
}
@@ -0,0 +1,62 @@
<?php
namespace App\Service\Cron;
use App\Email\Mailer;
use App\Entity\Disposition;
use App\Repository\DispositionRepository;
use Psr\Log\LoggerInterface;
class DispositionReminderService
{
public function __construct(
private readonly DispositionRepository $dispositionRepository,
private readonly Mailer $mailer,
private readonly LoggerInterface $logger
) {
}
public function sendDispositionReminders(): string
{
// find dispositions starting in five days from now
$dateFrom = (new \DateTimeImmutable())->modify('+5 days');
$qb = $this->dispositionRepository->createQueryBuilder('disposition');
$dispositions = $qb
->select('disposition', 'assignment', 'destination')
->innerJoin('disposition.assignment', 'assignment')
->innerJoin('assignment.destination', 'destination')
->where($qb->expr()->eq('destination.dateFrom', ':dateFrom'))
->setParameter('dateFrom', $dateFrom->format('Y-m-d'))
->getQuery()
->getResult()
;
if (0 === $count = count($dispositions)) {
$message = 'No disposition reminders to be sent to teamers';
$this->logger->info($message);
return $message;
}
foreach ($dispositions as $disposition) {
/** @var Disposition $disposition */
$teamer = $disposition->getTeamer();
$assignment = $disposition->getAssignment();
$destination = $assignment->getDestination();
$this->mailer->createAndSendEmail([
'disposition' => $disposition,
], [
'to' => $teamer->getCommunication()->getEmail(),
'subject' => 'Reminder: Dein Einsatz '.$destination,
'template' => 'email/reminder_pre_disposition.html.twig',
]);
}
$message = 'Sent '.$count.' disposition reminders to teamers';
$this->logger->info($message);
return $message;
}
}