feat: manual sorting of additional services
This commit is contained in:
@@ -6,6 +6,7 @@ namespace App\Repository\Groups;
|
||||
|
||||
use App\Entity\Groups\AdditionalService;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
@@ -20,4 +21,16 @@ class AdditionalServiceRepository extends ServiceEntityRepository
|
||||
{
|
||||
parent::__construct($registry, AdditionalService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional services are ordered manually in the admin; dateFrom and id only break ties
|
||||
* between records that share a position (newly created or duplicated ones).
|
||||
*/
|
||||
protected function applyOrdering(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder
|
||||
->orderBy('s.position', 'ASC')
|
||||
->addOrderBy('s.dateFrom', 'ASC')
|
||||
->addOrderBy('s.id', 'ASC');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace App\Repository\Groups;
|
||||
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
||||
/**
|
||||
* @template T of object
|
||||
@@ -26,16 +27,26 @@ trait FindsByAccommodationAndDateRangeTrait
|
||||
\DateTimeImmutable $dateFrom,
|
||||
\DateTimeImmutable $dateTo,
|
||||
): array {
|
||||
return $this->createQueryBuilder('s')
|
||||
$queryBuilder = $this->createQueryBuilder('s')
|
||||
->where('s.accommodation = :accommodation')
|
||||
->andWhere('s.dateFrom <= :dateTo')
|
||||
->andWhere('s.dateTo >= :dateFrom')
|
||||
->setParameter('accommodation', $accommodation)
|
||||
->setParameter('dateFrom', $dateFrom)
|
||||
->setParameter('dateTo', $dateTo)
|
||||
->setParameter('dateTo', $dateTo);
|
||||
|
||||
$this->applyOrdering($queryBuilder);
|
||||
|
||||
return $queryBuilder->getQuery()->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ordering applied to the query above; override to sort by something else.
|
||||
*/
|
||||
protected function applyOrdering(QueryBuilder $queryBuilder): void
|
||||
{
|
||||
$queryBuilder
|
||||
->orderBy('s.dateFrom', 'ASC')
|
||||
->addOrderBy('s.label', 'ASC')
|
||||
->getQuery()
|
||||
->getResult();
|
||||
->addOrderBy('s.label', 'ASC');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user