feat: exclude unavailable assignments from list for teamer
This commit is contained in:
@@ -50,6 +50,33 @@ class AssignmentRepository extends ServiceEntityRepository
|
||||
|
||||
public function getListQueryForTeamer(Teamer $teamer, AssignmentFilterDto $filterDto): Query
|
||||
{
|
||||
// Find ids of assignments with available slots first
|
||||
$qb = $this->createQueryBuilder('assignment');
|
||||
|
||||
$availableAssignments = $qb
|
||||
->select('assignment.id')
|
||||
->leftJoin('assignment.dispositions', 'disposition')
|
||||
->innerJoin('assignment.destination', 'destination')
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->gt('destination.dateFrom', ':now'),
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->isNotNull('assignment.dateFrom'),
|
||||
$qb->expr()->gt('assignment.dateFrom', ':now')
|
||||
)
|
||||
),
|
||||
$qb->expr()->isNull('assignment.deletedAt')
|
||||
))
|
||||
->groupBy('assignment')
|
||||
->having($qb->expr()->gt('assignment.availableDispositions', $qb->expr()->count('disposition.id')))
|
||||
->setParameter('now', new \DateTimeImmutable())
|
||||
->getQuery()
|
||||
->getArrayResult()
|
||||
;
|
||||
|
||||
// Extract ids of available assignments for the following query
|
||||
$availableAssignmentsIds = array_column($availableAssignments, 'id');
|
||||
|
||||
$qb = $this->createQueryBuilder('assignment');
|
||||
|
||||
$qb
|
||||
@@ -64,7 +91,8 @@ class AssignmentRepository extends ServiceEntityRepository
|
||||
$qb->expr()->gt('assignment.dateFrom', ':now')
|
||||
)
|
||||
),
|
||||
$qb->expr()->isNull('assignment.deletedAt')
|
||||
$qb->expr()->isNull('assignment.deletedAt'),
|
||||
$qb->expr()->in('assignment.id', $availableAssignmentsIds)
|
||||
))
|
||||
->leftJoin('assignment.applications', 'application', Join::WITH, $qb->expr()->eq('application.teamer', ':teamer'))
|
||||
->leftJoin('assignment.dispositions', 'disposition', Join::WITH, $qb->expr()->eq('disposition.teamer', ':teamer'))
|
||||
|
||||
Reference in New Issue
Block a user