feat: admin list filtering and search
This commit is contained in:
@@ -5,7 +5,10 @@ declare(strict_types=1);
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Form\Model\Filter\UserFilterDto;
|
||||
use App\Repository\Filter\AppliesListFiltersTrait;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
@@ -13,11 +16,38 @@ use Doctrine\Persistence\ManagerRegistry;
|
||||
*/
|
||||
class UserRepository extends ServiceEntityRepository
|
||||
{
|
||||
use AppliesListFiltersTrait;
|
||||
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, User::class);
|
||||
}
|
||||
|
||||
public function createFilteredQueryBuilder(UserFilterDto $filter): QueryBuilder
|
||||
{
|
||||
$qb = $this->createQueryBuilder('user');
|
||||
|
||||
$this->applySearchTerm($qb, $filter->searchTerm(), [
|
||||
'user.email',
|
||||
'user.addressId',
|
||||
'user.personId',
|
||||
]);
|
||||
|
||||
$this->applyDateWithin($qb, 'user.lastLoginAt', $filter->dateFrom, $filter->dateTo);
|
||||
|
||||
if (null !== $filter->role && '' !== $filter->role) {
|
||||
// Same reasoning as findGroupsStaff(): the roles are a JSON array column and no
|
||||
// JSON_CONTAINS is registered, so the needle carries its quotes to stay anchored
|
||||
// to a whole array entry.
|
||||
$qb
|
||||
->andWhere('user.roles LIKE :role')
|
||||
->setParameter('role', '%"'.$filter->role.'"%')
|
||||
;
|
||||
}
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Users who can look after a group booking. The roles are a JSON array column and no
|
||||
* JSON_CONTAINS is registered, so the needles carry their quotes to stay anchored to
|
||||
|
||||
Reference in New Issue
Block a user