Feat: Add assignment filter for admins

This commit is contained in:
Björn Fromme
2023-10-23 15:03:17 +02:00
parent d688a05203
commit 6f7db829b5
9 changed files with 424 additions and 32 deletions
+83 -27
View File
@@ -4,7 +4,9 @@ namespace App\Repository;
use App\Entity\Application;
use App\Entity\Assignment;
use App\Entity\Destination;
use App\Entity\Teamer;
use App\Model\AssignmentFilterDto;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Expr\Join;
@@ -25,7 +27,7 @@ class AssignmentRepository extends ServiceEntityRepository
parent::__construct($registry, Assignment::class);
}
public function getListQuery(Teamer $teamer = null): Query
public function getListQuery(AssignmentFilterDto $filterDto): Query
{
$qb = $this->createQueryBuilder('assignment');
@@ -34,25 +36,81 @@ class AssignmentRepository extends ServiceEntityRepository
->innerJoin('assignment.destination', 'destination')
->innerJoin('assignment.jobProfile', 'job_profile')
->where($qb->expr()->isNull('assignment.deletedAt'))
;
if (null !== $teamer) {
$qb
->leftJoin('assignment.applications', 'application', Join::WITH, $qb->expr()->eq('application.teamer', ':teamer'))
->leftJoin('assignment.dispositions', 'disposition', Join::WITH, $qb->expr()->eq('disposition.teamer', ':teamer'))
->setParameter('teamer', $teamer)
->leftJoin('assignment.applications', 'application', Join::WITH, $qb->expr()->neq('application.status', ':status'))
->leftJoin('assignment.dispositions', 'disposition')
->setParameter('status', Application::STATUS_REJECTED)
;
} else {
if (null !== $dateFrom = $filterDto->getDateFrom()) {
$qb
->leftJoin('assignment.applications', 'application', Join::WITH, $qb->expr()->neq('application.status', ':status'))
->leftJoin('assignment.dispositions', 'disposition')
->setParameter('status', Application::STATUS_REJECTED)
->andWhere($qb->expr()->gte('destination.dateFrom', ':dateFrom'))
->setParameter('dateFrom', $dateFrom)
;
}
if (null !== $dateTo = $filterDto->getDateTo()) {
$qb
->andWhere($qb->expr()->lte('destination.dateTo', ':dateTo'))
->setParameter('dateTo', $dateTo)
;
}
if (null !== $jobProfile = $filterDto->getJobProfile()) {
$qb
->andWhere($qb->expr()->eq('assignment.jobProfile', ':jobProfile'))
->setParameter('jobProfile', $jobProfile)
;
}
if (null !== $destination = $filterDto->getDestination()) {
$qb
->andWhere($qb->expr()->eq('assignment.destination', ':destination'))
->setParameter('destination', $destination)
;
}
if (null !== $duration = $filterDto->getDuration()) {
$days = match ($duration) {
AssignmentFilterDto::DURATION_WEEKEND => [2, 4],
AssignmentFilterDto::DURATION_MID_WEEK => [5, 6],
AssignmentFilterDto::DURATION_FULL_WEEK => [7, 7],
default => [8, 0],
};
[$minDays, $maxDays] = $days;
$qb
->andWhere($qb->expr()->gte('DATEDIFF(destination.dateTo, destination.dateFrom)', ':minDays'))
->setParameter('minDays', $minDays)
;
if (0 < $maxDays) {
$qb
->andWhere($qb->expr()->lte('DATEDIFF(destination.dateTo, destination.dateFrom)', ':maxDays'))
->setParameter('maxDays', $maxDays)
;
}
}
return $qb->getQuery();
}
public function getListQueryForTeamer(Teamer $teamer = null): Query
{
$qb = $this->createQueryBuilder('assignment');
return $qb
->select('assignment', 'destination', 'job_profile', 'application', 'disposition')
->innerJoin('assignment.destination', 'destination')
->innerJoin('assignment.jobProfile', 'job_profile')
->where($qb->expr()->isNull('assignment.deletedAt'))
->leftJoin('assignment.applications', 'application', Join::WITH, $qb->expr()->eq('application.teamer', ':teamer'))
->leftJoin('assignment.dispositions', 'disposition', Join::WITH, $qb->expr()->eq('disposition.teamer', ':teamer'))
->setParameter('teamer', $teamer)
->getQuery()
;
}
public function getBookmarkQueryForTeamer(Teamer $teamer): Query
{
$qb = $this->createQueryBuilder('assignment');
@@ -85,39 +143,37 @@ class AssignmentRepository extends ServiceEntityRepository
->getSingleResult()
;
$options['minDate'] = $result['minDate'];
$options['maxDate'] = $result['maxDate'];
$options['minDate'] = new \DateTimeImmutable($result['minDate']);
$options['maxDate'] = new \DateTimeImmutable($result['maxDate']);
// Job-profiles
$qb = $this->createQueryBuilder('assignment');
$result = $qb
->select('job_profile.id', 'job_profile.name')
->select('assignment', 'job_profile')
->innerJoin('assignment.jobProfile', 'job_profile')
->orderBy('job_profile.name', 'ASC')
->where($qb->expr()->isNull('assignment.deletedAt'))
->getQuery()
->getArrayResult()
->getResult()
;
$options['jobProfiles'] = array_map(function (Assignment $assignment) {
return $assignment->getJobProfile();
}, $result);
foreach ($result as $row) {
$options['jobProfiles'][$row['id']] = $row['name'];
}
// Products
// Destinations
$qb = $this->createQueryBuilder('assignment');
$result = $qb
->select('destination.id id', 'destination.product product', 'destination.hotel hotel')
->select('assignment', 'destination')
->innerJoin('assignment.destination', 'destination')
->where($qb->expr()->isNull('assignment.deletedAt'))
->orderBy('destination.product', 'ASC')
->groupBy('destination.id')
->getQuery()
->getArrayResult()
->getResult()
;
foreach ($result as $row) {
$options['products'][$row['id']] = $row['product'];
}
$options['destinations'] = array_map(function (Assignment $assignment) {
return $assignment->getDestination();
}, $result);
return $options;
}