feat: admin list filtering and search
This commit is contained in:
@@ -6,9 +6,13 @@ namespace App\Repository;
|
||||
|
||||
use App\Entity\BookingEditDraft;
|
||||
use App\Entity\User;
|
||||
use App\Form\Model\Filter\BookingEditDraftFilterDto;
|
||||
use App\Repository\Filter\AppliesListFiltersTrait;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\ORM\Query\Parameter;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
@@ -16,11 +20,59 @@ use Doctrine\Persistence\ManagerRegistry;
|
||||
*/
|
||||
class BookingEditDraftRepository extends ServiceEntityRepository
|
||||
{
|
||||
use AppliesListFiltersTrait;
|
||||
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, BookingEditDraft::class);
|
||||
}
|
||||
|
||||
public function createFilteredQueryBuilder(BookingEditDraftFilterDto $filter): QueryBuilder
|
||||
{
|
||||
$qb = $this
|
||||
->createQueryBuilder('booking_edit_draft')
|
||||
->leftJoin('booking_edit_draft.user', 'user')
|
||||
;
|
||||
|
||||
$this->applySearchTerm($qb, $filter->searchTerm(), [
|
||||
'user.email',
|
||||
'booking_edit_draft.bookingNumber',
|
||||
'booking_edit_draft.bookingId',
|
||||
]);
|
||||
|
||||
$this->applyDateWithin($qb, 'booking_edit_draft.createdAt', $filter->dateFrom, $filter->dateTo);
|
||||
|
||||
if (null !== $filter->user) {
|
||||
$qb->andWhere('booking_edit_draft.user = :user')->setParameter('user', $filter->user);
|
||||
}
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
/**
|
||||
* The accounts that actually have a draft — the full user table would be an unusable
|
||||
* choice list and most of it could never match.
|
||||
*
|
||||
* @return User[]
|
||||
*/
|
||||
public function findDraftOwners(): array
|
||||
{
|
||||
// Rooted at the user rather than the draft: DQL cannot select a joined entity on its own.
|
||||
/** @var User[] $users */
|
||||
$users = $this->getEntityManager()
|
||||
->createQueryBuilder()
|
||||
->select('user')
|
||||
->distinct()
|
||||
->from(User::class, 'user')
|
||||
->innerJoin(BookingEditDraft::class, 'draft', Join::ON, 'draft.user = user')
|
||||
->orderBy('user.email', 'ASC')
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a draft for a specific user and booking combination.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user