feat: offer the questionnaire for placements ended within a rolling window

This commit is contained in:
fromme committed 2026-11-10 09:23:23 +01:00
1 parent 9d0cdd7f52
commit 3c34cfa76a
8 files changed
+65 -55

No files matched your search

+7 -7
View File
@@ -57,17 +57,17 @@ class QuestionnaireCatalog
}
/**
* The services.yaml parameter questionnaire_go_live as a date: the teamer questionnaire is
* offered for placements ending on or after it, and to nobody while it is null.
* The first end date the teamer questionnaire is still offered for: the services.yaml
* parameter questionnaire_window_days, in days before today. Placements that ended earlier are neither
* pending nor open, so a deploy does not offer it for every past placement at once.
*/
public static function parseGoLive(?string $goLive): ?\DateTimeImmutable
public static function windowStart(int $windowDays): \DateTimeImmutable
{
if (null === $goLive) {
return null;
if ($windowDays < 0) {
throw new \InvalidArgumentException(sprintf('questionnaire_window_days must not be negative, got %d', $windowDays));
}
return \DateTimeImmutable::createFromFormat('!Y-m-d', $goLive)
?: throw new \InvalidArgumentException(sprintf('questionnaire_go_live "%s" is not a Y-m-d date', $goLive));
return new \DateTimeImmutable(sprintf('today -%d days', $windowDays));
}
/**
+5 -4
View File
@@ -72,12 +72,13 @@ class IndexController extends AbstractController
$dispositionDocuments = $this->processDocuments($upcomingDispositions);
// offered to nobody until the go-live date is configured, as in DispositionVoter
$questionnaireGoLive = QuestionnaireCatalog::parseGoLive($this->getParameter('questionnaire_go_live'));
$pendingQuestionnaires = null === $questionnaireGoLive ? [] : $this
$pendingQuestionnaires = $this
->entityManager
->getRepository(Disposition::class)
->findPendingQuestionnaireByTeamer($teamer, $questionnaireGoLive)
->findPendingQuestionnaireByTeamer(
$teamer,
QuestionnaireCatalog::windowStart((int) $this->getParameter('questionnaire_window_days')),
)
;
// the list merges in season assignments; the document notices above stay on dispositions
+7 -7
View File
@@ -80,8 +80,8 @@ class DispositionRepository extends ServiceEntityRepository
* The teamer's placements with a questionnaire still to be submitted - not started, or saved as
* a draft: the teamer feedback, and after a bus escort the bus feedback too
* (DispositionContext::questionnaires(), spelled out here in DQL). The rules are those of
* DispositionVoter::QUESTIONNAIRE - over (today included), on or after go-live, neither called
* off nor skip-formalities - so every row shown on the dashboard can be opened.
* DispositionVoter::QUESTIONNAIRE - over (today included), on or after $windowStart, neither
* called off nor skip-formalities - so every row shown on the dashboard can be opened.
*
* The responses are joined as arbitrary entities because the association is one-way; the
* questionnaire key has to be part of each JOIN condition, or one questionnaire's response
@@ -90,7 +90,7 @@ class DispositionRepository extends ServiceEntityRepository
* Rows are [0 => Disposition, 'teamerStatus' => ?QuestionnaireResponseStatus,
* 'busStatus' => ?QuestionnaireResponseStatus].
*/
public function getPendingQuestionnaireQuery(Teamer $teamer, \DateTimeImmutable $goLive): Query
public function getPendingQuestionnaireQuery(Teamer $teamer, \DateTimeImmutable $windowStart): Query
{
$qb = $this->createQueryBuilder('disposition');
@@ -115,7 +115,7 @@ class DispositionRepository extends ServiceEntityRepository
$qb->expr()->neq('disposition.status', ':dispositionCalledOff'),
$qb->expr()->notIn('assignment.status', ':assignmentStatuses'),
$qb->expr()->eq('assignment.skipFormalities', ':skipFormalities'),
$qb->expr()->gte('destination.dateTo', ':goLive'),
$qb->expr()->gte('destination.dateTo', ':windowStart'),
$qb->expr()->lte('destination.dateTo', ':today'),
$qb->expr()->orX(
$qb->expr()->isNull('teamer_response.id'),
@@ -138,7 +138,7 @@ class DispositionRepository extends ServiceEntityRepository
->setParameter('dispositionCalledOff', Disposition::STATUS_CALLED_OFF)
->setParameter('assignmentStatuses', [Assignment::STATUS_CALLED_OFF, Assignment::STATUS_DELETED])
->setParameter('skipFormalities', false)
->setParameter('goLive', $goLive, Types::DATE_IMMUTABLE)
->setParameter('windowStart', $windowStart, Types::DATE_IMMUTABLE)
->setParameter('today', new \DateTimeImmutable('today'), Types::DATE_IMMUTABLE)
->setParameter('draft', QuestionnaireResponseStatus::DRAFT)
->getQuery()
@@ -148,7 +148,7 @@ class DispositionRepository extends ServiceEntityRepository
/**
* @return list<array{disposition: Disposition, draft: bool}>
*/
public function findPendingQuestionnaireByTeamer(Teamer $teamer, \DateTimeImmutable $goLive): array
public function findPendingQuestionnaireByTeamer(Teamer $teamer, \DateTimeImmutable $windowStart): array
{
return array_map(
static fn (array $row): array => [
@@ -156,7 +156,7 @@ class DispositionRepository extends ServiceEntityRepository
'draft' => QuestionnaireResponseStatus::DRAFT === $row['teamerStatus']
|| QuestionnaireResponseStatus::DRAFT === $row['busStatus'],
],
$this->getPendingQuestionnaireQuery($teamer, $goLive)->getResult(),
$this->getPendingQuestionnaireQuery($teamer, $windowStart)->getResult(),
);
}
+4 -7
View File
@@ -25,16 +25,13 @@ class DispositionVoter extends Voter
public const MANAGE_RECEIPTS = 'MANAGE_RECEIPTS';
public const QUESTIONNAIRE = 'QUESTIONNAIRE';
private readonly ?\DateTimeImmutable $questionnaireGoLive;
/**
* @param string|null $questionnaireGoLive Y-m-d, the services.yaml parameter questionnaire_go_live
* @param int $questionnaireWindowDays the services.yaml parameter questionnaire_window_days
*/
public function __construct(
private readonly Security $security,
?string $questionnaireGoLive,
private readonly int $questionnaireWindowDays,
) {
$this->questionnaireGoLive = QuestionnaireCatalog::parseGoLive($questionnaireGoLive);
}
protected function supports(string $attribute, mixed $subject): bool
@@ -134,7 +131,7 @@ class DispositionVoter extends Voter
*/
private function assertQuestionnaireAllowed(TokenInterface $token, Disposition $disposition): bool
{
if (null === $this->questionnaireGoLive || false === $this->assertTeamerAccess($token, $disposition)) {
if (false === $this->assertTeamerAccess($token, $disposition)) {
return false;
}
@@ -146,7 +143,7 @@ class DispositionVoter extends Voter
$dateTo = $disposition->getAssignment()?->getDestination()?->getDateTo();
return null !== $dateTo
&& $dateTo >= $this->questionnaireGoLive
&& $dateTo >= QuestionnaireCatalog::windowStart($this->questionnaireWindowDays)
&& $dateTo <= new \DateTimeImmutable('today');
}