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