refactor: split the questionnaire into teamer and bus feedback
This commit is contained in:
1 parent
2f4f9800dd
commit
a0170f5952
35 files changed
+1114
-554
No files matched your search
@@ -77,30 +77,38 @@ class DispositionRepository extends ServiceEntityRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* The teamer's placements whose questionnaire (config/questionnaires/teamer_assignment.yaml) is
|
||||
* still to be submitted: not started, or saved as a draft. The rules are those of
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
* 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
|
||||
* would stand in for the other's.
|
||||
*
|
||||
* Rows are [0 => Disposition, 'responseStatus' => ?QuestionnaireResponseStatus].
|
||||
* Rows are [0 => Disposition, 'teamerStatus' => ?QuestionnaireResponseStatus,
|
||||
* 'busStatus' => ?QuestionnaireResponseStatus].
|
||||
*/
|
||||
public function getPendingQuestionnaireQuery(Teamer $teamer, \DateTimeImmutable $goLive): Query
|
||||
{
|
||||
$qb = $this->createQueryBuilder('disposition');
|
||||
|
||||
return $qb
|
||||
->select('disposition', 'assignment', 'destination', 'response.status AS responseStatus')
|
||||
->select('disposition', 'assignment', 'destination', 'teamer_response.status AS teamerStatus', 'bus_response.status AS busStatus')
|
||||
->innerJoin('disposition.assignment', 'assignment')
|
||||
->innerJoin('assignment.destination', 'destination')
|
||||
->leftJoin(
|
||||
QuestionnaireResponse::class,
|
||||
'response',
|
||||
'teamer_response',
|
||||
Join::ON,
|
||||
'response.disposition = disposition AND response.questionnaire = :questionnaire'
|
||||
'teamer_response.disposition = disposition AND teamer_response.questionnaire = :teamerQuestionnaire'
|
||||
)
|
||||
->leftJoin(
|
||||
QuestionnaireResponse::class,
|
||||
'bus_response',
|
||||
Join::ON,
|
||||
'bus_response.disposition = disposition AND bus_response.questionnaire = :busQuestionnaire'
|
||||
)
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->eq('disposition.teamer', ':teamer'),
|
||||
@@ -110,13 +118,23 @@ class DispositionRepository extends ServiceEntityRepository
|
||||
$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')
|
||||
$qb->expr()->isNull('teamer_response.id'),
|
||||
$qb->expr()->eq('teamer_response.status', ':draft'),
|
||||
// a bus escort, i.e. Assignment::hasBusEscort(), owing the bus feedback
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->isNotNull('assignment.pickup'),
|
||||
$qb->expr()->neq('assignment.pickup', 0),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull('bus_response.id'),
|
||||
$qb->expr()->eq('bus_response.status', ':draft')
|
||||
)
|
||||
)
|
||||
)
|
||||
))
|
||||
->orderBy('destination.dateTo', \SortDirection::Descending)
|
||||
->setParameter('teamer', $teamer)
|
||||
->setParameter('questionnaire', QuestionnaireCatalog::TEAMER_ASSIGNMENT)
|
||||
->setParameter('teamerQuestionnaire', QuestionnaireCatalog::TEAMER_FEEDBACK)
|
||||
->setParameter('busQuestionnaire', QuestionnaireCatalog::BUS_FEEDBACK)
|
||||
->setParameter('dispositionCalledOff', Disposition::STATUS_CALLED_OFF)
|
||||
->setParameter('assignmentStatuses', [Assignment::STATUS_CALLED_OFF, Assignment::STATUS_DELETED])
|
||||
->setParameter('skipFormalities', false)
|
||||
@@ -135,7 +153,8 @@ class DispositionRepository extends ServiceEntityRepository
|
||||
return array_map(
|
||||
static fn (array $row): array => [
|
||||
'disposition' => $row[0],
|
||||
'draft' => QuestionnaireResponseStatus::DRAFT === $row['responseStatus'],
|
||||
'draft' => QuestionnaireResponseStatus::DRAFT === $row['teamerStatus']
|
||||
|| QuestionnaireResponseStatus::DRAFT === $row['busStatus'],
|
||||
],
|
||||
$this->getPendingQuestionnaireQuery($teamer, $goLive)->getResult(),
|
||||
);
|
||||
|
||||
@@ -80,8 +80,17 @@ class QuestionnaireResponseRepository extends ServiceEntityRepository
|
||||
return $qb->getQuery();
|
||||
}
|
||||
|
||||
public function findOneByDisposition(string $questionnaire, Disposition $disposition): ?QuestionnaireResponse
|
||||
/**
|
||||
* @return array<string, QuestionnaireResponse> keyed by questionnaire key
|
||||
*/
|
||||
public function findByDisposition(Disposition $disposition): array
|
||||
{
|
||||
return $this->findOneBy(['questionnaire' => $questionnaire, 'disposition' => $disposition]);
|
||||
$responses = [];
|
||||
|
||||
foreach ($this->findBy(['disposition' => $disposition]) as $response) {
|
||||
$responses[$response->getQuestionnaire()] = $response;
|
||||
}
|
||||
|
||||
return $responses;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user