feat: add the house manager questionnaire per travel and compact the questionnaire layout
This commit is contained in:
1 parent
d760ed3cdf
commit
bfef08b519
50 files changed
+2763
-180
No files matched your search
@@ -2,10 +2,17 @@
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\QuestionnaireResponse;
|
||||
use App\Entity\Teamer;
|
||||
use App\Enum\QuestionnaireResponseStatus;
|
||||
use App\Model\DestinationFilterDto;
|
||||
use App\Repository\Traits\QueryHelperTrait;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
@@ -161,4 +168,117 @@ class DestinationRepository extends ServiceEntityRepository
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* The ended travels a house manager still owes something for, one row per travel: the
|
||||
* questionnaire is not submitted (only for travels ended on or after $goLive), or a placement
|
||||
* still has no rating and is not waived. The two are independent - the questionnaire can be
|
||||
* submitted while ratings are missing.
|
||||
*
|
||||
* A travel counts only with at least one placement a house manager rates
|
||||
* (DispositionRepository::findForHouseManagerQuestionnaire() spells the same rule): a travel
|
||||
* nobody worked on has nothing to report.
|
||||
*
|
||||
* Rows are [0 => Destination, 'questionnaireStatus' => ?string (QuestionnaireResponseStatus
|
||||
* value, null without a response), 'placements' => int, 'openFeedbacks' => int].
|
||||
*
|
||||
* @param list<string>|null $hotelCodes the house manager's (User::$hotelCodes), matched on
|
||||
* either end of the travel's code as everywhere else;
|
||||
* null for every house
|
||||
* @param Teamer|null $houseManager the house manager's own teamer, whose placement they
|
||||
* do not rate
|
||||
*/
|
||||
public function getPendingForHouseManagerQuery(?array $hotelCodes, \DateTimeImmutable $goLive, \DateTimeImmutable $endedBy, ?Teamer $houseManager = null): Query
|
||||
{
|
||||
$qb = $this->createQueryBuilder('destination');
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
// a placement of this travel that a house manager rates; $alias keeps the subqueries apart
|
||||
$placements = static function (string $alias, string $select, bool $unrated = false) use ($em, $houseManager): string {
|
||||
$sub = $em->createQueryBuilder()
|
||||
->select(sprintf($select, $alias))
|
||||
->from(Disposition::class, $alias)
|
||||
->innerJoin($alias.'.assignment', $alias.'_assignment')
|
||||
->where($alias.'_assignment.destination = destination')
|
||||
->andWhere($alias.'.status <> :dispositionCalledOff')
|
||||
->andWhere($alias.'_assignment.status NOT IN (:assignmentStatuses)')
|
||||
->andWhere($alias.'_assignment.skipFormalities = :skipFormalities')
|
||||
;
|
||||
|
||||
if (null !== $houseManager) {
|
||||
$sub->andWhere($alias.'.teamer <> :houseManager');
|
||||
}
|
||||
|
||||
if ($unrated) {
|
||||
$sub
|
||||
->andWhere($alias.'.feedback IS NULL')
|
||||
->andWhere($alias.'.feedbackWaived = :feedbackWaived')
|
||||
;
|
||||
}
|
||||
|
||||
return $sub->getDQL();
|
||||
};
|
||||
|
||||
// this travel's house manager questionnaire
|
||||
$response = static function (string $alias, string $select, bool $submitted = false) use ($em): string {
|
||||
$sub = $em->createQueryBuilder()
|
||||
->select(sprintf($select, $alias))
|
||||
->from(QuestionnaireResponse::class, $alias)
|
||||
->where($alias.'.destination = destination')
|
||||
->andWhere($alias.'.questionnaire = :questionnaire')
|
||||
;
|
||||
|
||||
if ($submitted) {
|
||||
$sub->andWhere($alias.'.status = :submitted');
|
||||
}
|
||||
|
||||
return $sub->getDQL();
|
||||
};
|
||||
|
||||
$qb
|
||||
->select(
|
||||
'destination',
|
||||
'('.$response('status_response', '%s.status').') AS questionnaireStatus',
|
||||
'('.$placements('counted', 'COUNT(%s.id)').') AS placements',
|
||||
'('.$placements('unrated_count', 'COUNT(%s.id)', true).') AS openFeedbacks',
|
||||
)
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->isNull('destination.deletedAt'),
|
||||
$qb->expr()->lte('destination.dateTo', ':endedBy'),
|
||||
$qb->expr()->exists($placements('staffed', '%s.id')),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->gte('destination.dateTo', ':goLive'),
|
||||
$qb->expr()->not($qb->expr()->exists($response('submitted_response', '%s.id', true)))
|
||||
),
|
||||
$qb->expr()->exists($placements('unrated', '%s.id', true))
|
||||
)
|
||||
))
|
||||
->orderBy('destination.dateTo', \SortDirection::Ascending)
|
||||
->setParameter('endedBy', $endedBy, Types::DATE_IMMUTABLE)
|
||||
->setParameter('goLive', $goLive, Types::DATE_IMMUTABLE)
|
||||
->setParameter('questionnaire', QuestionnaireCatalog::HOUSE_MANAGER_FEEDBACK)
|
||||
->setParameter('submitted', QuestionnaireResponseStatus::SUBMITTED)
|
||||
->setParameter('dispositionCalledOff', Disposition::STATUS_CALLED_OFF)
|
||||
->setParameter('assignmentStatuses', [Assignment::STATUS_CALLED_OFF, Assignment::STATUS_DELETED])
|
||||
->setParameter('skipFormalities', false)
|
||||
->setParameter('feedbackWaived', false)
|
||||
;
|
||||
|
||||
if (null !== $houseManager) {
|
||||
$qb->setParameter('houseManager', $houseManager);
|
||||
}
|
||||
|
||||
if (null !== $hotelCodes) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->orX(
|
||||
$qb->expr()->in($qb->expr()->substring('destination.hotelCode', 1, 3), ':hotelCodes'),
|
||||
$qb->expr()->in($qb->expr()->substring('destination.hotelCode', -3, 3), ':hotelCodes'),
|
||||
))
|
||||
->setParameter('hotelCodes', $hotelCodes)
|
||||
;
|
||||
}
|
||||
|
||||
return $qb->getQuery();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Repository;
|
||||
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\QuestionnaireResponse;
|
||||
use App\Entity\Teamer;
|
||||
@@ -393,6 +394,80 @@ class DispositionRepository extends ServiceEntityRepository
|
||||
return $qb->getQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* The travel's teamers as the house manager's questionnaire lists them: every placement on it
|
||||
* that is not called off, on an assignment that is neither called off nor deleted nor
|
||||
* skip-formalities - the placements a house manager rates. The house manager's own placement,
|
||||
* if they hold one, is left out: nobody rates themselves.
|
||||
*
|
||||
* DestinationRepository::getPendingForHouseManagerQuery() spells the same rule in DQL.
|
||||
*
|
||||
* @return list<Disposition> by job profile, then teamer; teamer, job profile and feedback loaded
|
||||
*/
|
||||
public function findForHouseManagerQuestionnaire(Destination $destination, ?Teamer $houseManager = null): array
|
||||
{
|
||||
$qb = $this->createHouseManagerPlacementsQueryBuilder([$destination]);
|
||||
|
||||
if (null !== $houseManager) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->neq('disposition.teamer', ':houseManager'))
|
||||
->setParameter('houseManager', $houseManager)
|
||||
;
|
||||
}
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* The same placements for several travels at once, for the house manager's pending list.
|
||||
*
|
||||
* @param list<Destination> $destinations
|
||||
*
|
||||
* @return array<int, list<Disposition>> keyed by destination id
|
||||
*/
|
||||
public function findForHouseManagerByDestinations(array $destinations): array
|
||||
{
|
||||
if ([] === $destinations) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$placements = [];
|
||||
|
||||
foreach ($this->createHouseManagerPlacementsQueryBuilder($destinations)->getQuery()->getResult() as $disposition) {
|
||||
$placements[$disposition->getAssignment()->getDestination()->getId()][] = $disposition;
|
||||
}
|
||||
|
||||
return $placements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<Destination> $destinations
|
||||
*/
|
||||
private function createHouseManagerPlacementsQueryBuilder(array $destinations): QueryBuilder
|
||||
{
|
||||
$qb = $this->createQueryBuilder('disposition');
|
||||
|
||||
return $qb
|
||||
->select('disposition', 'assignment', 'job_profile', 'teamer', 'feedback')
|
||||
->innerJoin('disposition.assignment', 'assignment')
|
||||
->innerJoin('assignment.jobProfile', 'job_profile')
|
||||
->innerJoin('disposition.teamer', 'teamer')
|
||||
->leftJoin('disposition.feedback', 'feedback')
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->in('assignment.destination', ':destinations'),
|
||||
$qb->expr()->neq('disposition.status', ':dispositionCalledOff'),
|
||||
$qb->expr()->notIn('assignment.status', ':assignmentStatuses'),
|
||||
$this->excludesSkipFormalities($qb)
|
||||
))
|
||||
->orderBy('job_profile.name')
|
||||
->addOrderBy('teamer.lastName')
|
||||
->addOrderBy('teamer.firstName')
|
||||
->setParameter('destinations', $destinations)
|
||||
->setParameter('dispositionCalledOff', Disposition::STATUS_CALLED_OFF)
|
||||
->setParameter('assignmentStatuses', [Assignment::STATUS_CALLED_OFF, Assignment::STATUS_DELETED])
|
||||
;
|
||||
}
|
||||
|
||||
public function findDispositionsWithOverdueFeedback(?int $offsetDays = null): array
|
||||
{
|
||||
return $this
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\QuestionnaireResponse;
|
||||
use App\Enum\QuestionnaireResponseStatus;
|
||||
@@ -28,19 +30,16 @@ class QuestionnaireResponseRepository extends ServiceEntityRepository
|
||||
|
||||
/**
|
||||
* Submitted responses to one questionnaire for the office's list. Drafts stay out: until the
|
||||
* teamer submits, a response is theirs. Filtered and sorted on the live disposition rather
|
||||
* than the snapshot in `context`, which JSON would make neither sortable nor indexable.
|
||||
* respondent submits, a response is theirs. Filtered and sorted on the live disposition or
|
||||
* travel rather than the snapshot in `context`, which JSON would make neither sortable nor
|
||||
* indexable. The house manager's questionnaire is about a travel, so it has no teamer to
|
||||
* filter by.
|
||||
*/
|
||||
public function getListQuery(string $questionnaire, QuestionnaireResponseFilterDto $filterDto): Query
|
||||
{
|
||||
$qb = $this->createQueryBuilder('response');
|
||||
|
||||
$qb
|
||||
->select('response', 'disposition', 'teamer', 'assignment', 'destination')
|
||||
->innerJoin('response.disposition', 'disposition')
|
||||
->innerJoin('disposition.teamer', 'teamer')
|
||||
->innerJoin('disposition.assignment', 'assignment')
|
||||
->innerJoin('assignment.destination', 'destination')
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->eq('response.questionnaire', ':questionnaire'),
|
||||
$qb->expr()->eq('response.status', ':submitted')
|
||||
@@ -49,11 +48,26 @@ class QuestionnaireResponseRepository extends ServiceEntityRepository
|
||||
->setParameter('submitted', QuestionnaireResponseStatus::SUBMITTED)
|
||||
;
|
||||
|
||||
if (null !== $teamer = $filterDto->getTeamer()) {
|
||||
if (QuestionnaireCatalog::HOUSE_MANAGER_FEEDBACK === $questionnaire) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->eq('disposition.teamer', ':teamer'))
|
||||
->setParameter('teamer', $teamer)
|
||||
->select('response', 'destination')
|
||||
->innerJoin('response.destination', 'destination')
|
||||
;
|
||||
} else {
|
||||
$qb
|
||||
->select('response', 'disposition', 'teamer', 'assignment', 'destination')
|
||||
->innerJoin('response.disposition', 'disposition')
|
||||
->innerJoin('disposition.teamer', 'teamer')
|
||||
->innerJoin('disposition.assignment', 'assignment')
|
||||
->innerJoin('assignment.destination', 'destination')
|
||||
;
|
||||
|
||||
if (null !== $teamer = $filterDto->getTeamer()) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->eq('disposition.teamer', ':teamer'))
|
||||
->setParameter('teamer', $teamer)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $hotel = $filterDto->getHotel()) {
|
||||
@@ -95,4 +109,15 @@ class QuestionnaireResponseRepository extends ServiceEntityRepository
|
||||
|
||||
return $responses;
|
||||
}
|
||||
|
||||
/**
|
||||
* The house manager's questionnaire about this travel, draft or submitted.
|
||||
*/
|
||||
public function findForDestination(Destination $destination): ?QuestionnaireResponse
|
||||
{
|
||||
return $this->findOneBy([
|
||||
'destination' => $destination,
|
||||
'questionnaire' => QuestionnaireCatalog::HOUSE_MANAGER_FEEDBACK,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user