feat: keep questionnaires until submitted, remind teamers daily and take bus feedback per leg
This commit is contained in:
1 parent
abf9c1be0b
commit
e72616fdbf
37 files changed
+1119
-238
No files matched your search
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Cron;
|
||||
|
||||
use App\Config\EmailTextKey;
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Email\Mailer;
|
||||
use App\Entity\Disposition;
|
||||
use App\Repository\DispositionRepository;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Reminds teamers of their unsubmitted questionnaires, every day from the day after the trip ended
|
||||
* until they are submitted - a saved draft does not count. One mail per teamer, listing every such
|
||||
* placement.
|
||||
*
|
||||
* Like the other reminders it records nothing: the cron runs once a day, and that is what makes it
|
||||
* daily.
|
||||
*/
|
||||
class QuestionnaireReminderService
|
||||
{
|
||||
private readonly \DateTimeImmutable $questionnaireGoLive;
|
||||
|
||||
/**
|
||||
* @param string $questionnaireGoLive Y-m-d, the services.yaml parameter questionnaire_go_live
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly DispositionRepository $dispositionRepository,
|
||||
private readonly Mailer $mailer,
|
||||
private readonly LoggerInterface $logger,
|
||||
string $questionnaireGoLive,
|
||||
) {
|
||||
$this->questionnaireGoLive = QuestionnaireCatalog::parseGoLive($questionnaireGoLive);
|
||||
}
|
||||
|
||||
public function sendReminders(?\DateTimeImmutable $today = null): string
|
||||
{
|
||||
$today = ($today ?? new \DateTimeImmutable('today'))->setTime(0, 0);
|
||||
|
||||
/** @var array<int, list<Disposition>> $perTeamer keyed by object id: Doctrine hands out one Teamer instance per row */
|
||||
$perTeamer = [];
|
||||
|
||||
foreach ($this->dispositionRepository->findQuestionnaireReminders($this->questionnaireGoLive, $today) as $disposition) {
|
||||
$perTeamer[spl_object_id($disposition->getTeamer())][] = $disposition;
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
|
||||
foreach ($perTeamer as $dispositions) {
|
||||
$email = $dispositions[0]->getTeamer()->getCommunication()?->getEmail();
|
||||
|
||||
if (null === $email) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->mailer->createAndSendText(EmailTextKey::REMINDER_QUESTIONNAIRE, [
|
||||
'destinations' => implode(', ', array_map(
|
||||
static fn (Disposition $disposition): string => (string) $disposition->getAssignment()->getDestination(),
|
||||
$dispositions,
|
||||
)),
|
||||
], [
|
||||
'to' => $email,
|
||||
]);
|
||||
|
||||
++$count;
|
||||
}
|
||||
|
||||
$message = 'Sent '.$count.' questionnaire reminders to teamers';
|
||||
$this->logger->info($message);
|
||||
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user