mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
admin users: filter by name or email
This commit is contained in:
@@ -19,6 +19,7 @@ use Chill\MainBundle\Form\UserCurrentLocationType;
|
||||
use Chill\MainBundle\Form\UserPasswordType;
|
||||
use Chill\MainBundle\Form\UserType;
|
||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||
use Chill\MainBundle\Repository\UserRepository;
|
||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
|
||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactoryInterface;
|
||||
use LogicException;
|
||||
@@ -38,24 +39,62 @@ class UserController extends CRUDController
|
||||
{
|
||||
public const FORM_GROUP_CENTER_COMPOSED = 'composed_groupcenter';
|
||||
|
||||
private FilterOrderHelperFactoryInterface $filterOrderHelperFactory;
|
||||
|
||||
private LoggerInterface $logger;
|
||||
|
||||
private UserPasswordEncoderInterface $passwordEncoder;
|
||||
|
||||
private UserRepository $userRepository;
|
||||
|
||||
private ValidatorInterface $validator;
|
||||
|
||||
|
||||
public function __construct(
|
||||
LoggerInterface $chillLogger,
|
||||
ValidatorInterface $validator,
|
||||
UserPasswordEncoderInterface $passwordEncoder,
|
||||
FilterOrderHelperFactoryInterface $filterOrderHelperFactory
|
||||
UserRepository $userRepository
|
||||
) {
|
||||
$this->logger = $chillLogger;
|
||||
$this->userRepository = $userRepository;
|
||||
$this->validator = $validator;
|
||||
$this->passwordEncoder = $passwordEncoder;
|
||||
$this->filterOrderHelperFactory = $filterOrderHelperFactory;
|
||||
}
|
||||
|
||||
protected function countEntities(string $action, Request $request, ?FilterOrderHelper $filterOrder = null): int
|
||||
{
|
||||
if (!$filterOrder instanceof FilterOrderHelper) {
|
||||
return parent::countEntities($action, $request, $filterOrder);
|
||||
}
|
||||
|
||||
if (null === $filterOrder->getQueryString()) {
|
||||
return parent::countEntities($action, $request, $filterOrder);
|
||||
}
|
||||
|
||||
return $this->userRepository->countByUsernameOrEmail($filterOrder->getQueryString());
|
||||
}
|
||||
|
||||
protected function getQueryResult(
|
||||
string $action,
|
||||
Request $request,
|
||||
int $totalItems,
|
||||
PaginatorInterface $paginator,
|
||||
?FilterOrderHelper $filterOrder = null
|
||||
) {
|
||||
if (0 === $totalItems) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!$filterOrder instanceof FilterOrderHelper) {
|
||||
return parent::getQueryResult($action, $request, $totalItems, $paginator, $filterOrder);
|
||||
}
|
||||
|
||||
if (null === $filterOrder->getQueryString()) {
|
||||
return parent::getQueryResult($action, $request, $totalItems, $paginator, $filterOrder);
|
||||
}
|
||||
|
||||
return $this->userRepository->findByUsernameOrEmail($filterOrder->getQueryString(), ['usernameCanonical' => 'ASC'],
|
||||
$paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,15 +269,6 @@ class UserController extends CRUDController
|
||||
->build();
|
||||
}
|
||||
|
||||
protected function countEntities(string $action, Request $request, ?FilterOrderHelper $filterOrder = null): int
|
||||
{
|
||||
if (null === $filterOrder) {
|
||||
throw new LogicException('filterOrder should not be null');
|
||||
}
|
||||
|
||||
return parent::countEntities($action, $request, $filterOrder);
|
||||
}
|
||||
|
||||
protected function createFormFor(string $action, $entity, ?string $formClass = null, array $formOptions = []): FormInterface
|
||||
{
|
||||
// for "new", add special config
|
||||
@@ -288,7 +318,8 @@ class UserController extends CRUDController
|
||||
|
||||
protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator)
|
||||
{
|
||||
$query->addOrderBy('e.usernameCanonical', 'ASC');
|
||||
$query
|
||||
->addOrderBy('e.usernameCanonical', 'ASC');
|
||||
|
||||
return parent::orderQuery($action, $query, $request, $paginator);
|
||||
}
|
||||
|
Reference in New Issue
Block a user