feat: remind of open questionnaires nightly for a week, then weekly
This commit is contained in:
1 parent
e72616fdbf
commit
8b5b7584b1
4 files changed
+60
-11
No files matched your search
@@ -111,8 +111,8 @@ class DispositionRepository extends ServiceEntityRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* Every teamer's placements with a questionnaire still to be submitted, for the daily reminder
|
||||
* (QuestionnaireReminderService): the dashboard's rules, but only from the day after the trip
|
||||
* Every teamer's placements with a questionnaire still to be submitted, for the reminder
|
||||
* (QuestionnaireReminderService, which picks the nights each is due on): the dashboard's rules, but only from the day after the trip
|
||||
* ended, and only teamers who can still log in to submit - not deleted, with a user account that
|
||||
* is not blocked. Otherwise they would be reminded every day, forever.
|
||||
*
|
||||
|
||||
@@ -10,15 +10,19 @@ 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.
|
||||
* Reminds teamers of their unsubmitted questionnaires until they are submitted - a saved draft does
|
||||
* not count: every night for the first week after the trip, then once a week, so a teamer who never
|
||||
* submits is not mailed every night for the rest of the season. One mail per teamer on a night when
|
||||
* any of their placements is due, listing every placement they still owe.
|
||||
*
|
||||
* Like the other reminders it records nothing: the cron runs once a day, and that is what makes it
|
||||
* daily.
|
||||
* Like the other reminders it records nothing: whether a placement is due is a function of the day,
|
||||
* and the cron runs once a day.
|
||||
*/
|
||||
class QuestionnaireReminderService
|
||||
{
|
||||
/** nights after the trip with a reminder each, before it turns weekly */
|
||||
private const int DAILY_NIGHTS = 7;
|
||||
|
||||
private readonly \DateTimeImmutable $questionnaireGoLive;
|
||||
|
||||
/**
|
||||
@@ -47,9 +51,10 @@ class QuestionnaireReminderService
|
||||
$count = 0;
|
||||
|
||||
foreach ($perTeamer as $dispositions) {
|
||||
$due = array_filter($dispositions, fn (Disposition $disposition): bool => $this->isDue($disposition, $today));
|
||||
$email = $dispositions[0]->getTeamer()->getCommunication()?->getEmail();
|
||||
|
||||
if (null === $email) {
|
||||
if ([] === $due || null === $email) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -70,4 +75,15 @@ class QuestionnaireReminderService
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nights 1 to 7 after the trip, then nights 14, 21, ... The repository only returns
|
||||
* placements that ended yesterday or earlier.
|
||||
*/
|
||||
private function isDue(Disposition $disposition, \DateTimeImmutable $today): bool
|
||||
{
|
||||
$nights = (int) $disposition->getAssignment()->getDestination()->getDateTo()->setTime(0, 0)->diff($today)->days;
|
||||
|
||||
return $nights <= self::DAILY_NIGHTS || 0 === $nights % 7;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user