feat: remind teamers of open questionnaires on the dashboard
This commit is contained in:
1 parent
5e4e574076
commit
890e04f8a6
7 files changed
+313
-4
No files matched your search
@@ -2,12 +2,16 @@
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\QuestionnaireResponse;
|
||||
use App\Entity\Teamer;
|
||||
use App\Entity\Upload;
|
||||
use App\Enum\QuestionnaireResponseStatus;
|
||||
use App\Repository\Filter\SeasonPeriodFilter;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\Query\Expr\Comparison;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
@@ -72,6 +76,73 @@ class DispositionRepository extends ServiceEntityRepository
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* The teamer's placements whose questionnaire (config/questionnaires/teamer_escort.yaml) is
|
||||
* still to be submitted: not started, or saved as a draft. The rules are those of
|
||||
* DispositionVoter::QUESTIONNAIRE - bus escort, over (today included), on or after go-live,
|
||||
* neither called off nor skip-formalities - so every row shown on the dashboard can be opened.
|
||||
*
|
||||
* The response is joined as an arbitrary entity because the association is one-way; the
|
||||
* questionnaire key has to be part of the JOIN condition, or a response to another
|
||||
* questionnaire would hide this one.
|
||||
*
|
||||
* Rows are [0 => Disposition, 'responseStatus' => ?QuestionnaireResponseStatus].
|
||||
*/
|
||||
public function getPendingQuestionnaireQuery(Teamer $teamer, \DateTimeImmutable $goLive): Query
|
||||
{
|
||||
$qb = $this->createQueryBuilder('disposition');
|
||||
|
||||
return $qb
|
||||
->select('disposition', 'assignment', 'destination', 'response.status AS responseStatus')
|
||||
->innerJoin('disposition.assignment', 'assignment')
|
||||
->innerJoin('assignment.destination', 'destination')
|
||||
->leftJoin(
|
||||
QuestionnaireResponse::class,
|
||||
'response',
|
||||
Join::ON,
|
||||
'response.disposition = disposition AND response.questionnaire = :questionnaire'
|
||||
)
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->eq('disposition.teamer', ':teamer'),
|
||||
$qb->expr()->neq('disposition.status', ':dispositionCalledOff'),
|
||||
$qb->expr()->notIn('assignment.status', ':assignmentStatuses'),
|
||||
$qb->expr()->eq('assignment.skipFormalities', ':skipFormalities'),
|
||||
$qb->expr()->isNotNull('assignment.pickup'),
|
||||
$qb->expr()->neq('assignment.pickup', 0),
|
||||
$qb->expr()->gte('destination.dateTo', ':goLive'),
|
||||
$qb->expr()->lte('destination.dateTo', ':today'),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull('response.id'),
|
||||
$qb->expr()->eq('response.status', ':draft')
|
||||
)
|
||||
))
|
||||
->orderBy('destination.dateTo', \SortDirection::Descending)
|
||||
->setParameter('teamer', $teamer)
|
||||
->setParameter('questionnaire', QuestionnaireCatalog::TEAMER_ESCORT)
|
||||
->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('today', new \DateTimeImmutable('today'), Types::DATE_IMMUTABLE)
|
||||
->setParameter('draft', QuestionnaireResponseStatus::DRAFT)
|
||||
->getQuery()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{disposition: Disposition, draft: bool}>
|
||||
*/
|
||||
public function findPendingQuestionnaireByTeamer(Teamer $teamer, \DateTimeImmutable $goLive): array
|
||||
{
|
||||
return array_map(
|
||||
static fn (array $row): array => [
|
||||
'disposition' => $row[0],
|
||||
'draft' => QuestionnaireResponseStatus::DRAFT === $row['responseStatus'],
|
||||
],
|
||||
$this->getPendingQuestionnaireQuery($teamer, $goLive)->getResult(),
|
||||
);
|
||||
}
|
||||
|
||||
public function getRecentDispositionsByTeamerQuery(Teamer $teamer): Query
|
||||
{
|
||||
$qb = $this->createQueryBuilder('disposition');
|
||||
|
||||
Reference in new issue
Block a user