From 18de1024dc2d214615ac6b52456680d3d1fe8981 Mon Sep 17 00:00:00 2001 From: emilschn Date: Tue, 10 Dec 2024 17:15:45 +0100 Subject: [PATCH] wip sort user table #2942 --- src/Form/SearchUserType.php | 15 +++++++++++++++ src/Repository/UserRepository.php | 11 +++++++++-- src/Service/SearchUser.php | 11 +++++++++++ templates/back/user/index.html.twig | 16 +++++++++++----- 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/Form/SearchUserType.php b/src/Form/SearchUserType.php index 591a466e5..4f6762590 100755 --- a/src/Form/SearchUserType.php +++ b/src/Form/SearchUserType.php @@ -108,6 +108,21 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'label' => false, ]); } + + $builder->add('orderType', ChoiceType::class, [ + 'choices' => [ + 'Ordre alphabétique (A -> Z)' => 'u.nom-ASC', + 'Ordre alphabétique inversé (Z -> A)' => 'u.nom-DESC', + 'Partenaire (A -> Z)' => 'p.nom-ASC', + 'Partenaire inversé (Z -> A)' => 'p.nom-DESC', + 'Connexion la plus récente' => 'u.lastLoginAt-ASC', + 'Connexion la plus ancienne' => 'u.lastLoginAt-DESC', + ], + 'required' => false, + 'label' => 'Trier par', + 'data' => 'u.nom-ASC', + ]); + $builder->add('page', HiddenType::class); } diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index eacdb929a..a8d667a71 100755 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -376,8 +376,15 @@ public function findFiltered(SearchUser $searchUser, $execute = true): QueryBuil $qb->select('u', 'up', 'p', 't') ->leftJoin('u.userPartners', 'up') ->leftJoin('up.partner', 'p') - ->leftJoin('p.territory', 't') - ->orderBy('u.nom', 'ASC'); + ->leftJoin('p.territory', 't'); + + if (!empty($searchUser->getOrderType())) { + [$orderField, $orderDirection] = explode('-', $searchUser->getOrderType()); + $qb->orderBy($orderField, $orderDirection); + } else { + $qb->orderBy('u.nom', 'ASC'); + } + $qb->andWhere('u.statut != :statutArchive')->setParameter('statutArchive', User::STATUS_ARCHIVE); $qb->andWhere('JSON_CONTAINS(u.roles, :roleUsager) = 0')->setParameter('roleUsager', '"ROLE_USAGER"'); diff --git a/src/Service/SearchUser.php b/src/Service/SearchUser.php index d85ed84aa..6b97eead7 100644 --- a/src/Service/SearchUser.php +++ b/src/Service/SearchUser.php @@ -26,6 +26,7 @@ class SearchUser private ?int $statut = null; private ?string $role = null; private ?string $permissionAffectation = null; + private ?string $orderType = null; public function __construct(User $user) { @@ -125,6 +126,16 @@ public function setPermissionAffectation(?string $permissionAffectation): void $this->permissionAffectation = $permissionAffectation; } + public function getOrderType(): ?string + { + return $this->orderType; + } + + public function setOrderType(?string $orderType): void + { + $this->orderType = $orderType; + } + public function getUrlParams(): array { $params = $this->getUrlParamsBase(); diff --git a/templates/back/user/index.html.twig b/templates/back/user/index.html.twig index 0ee66e749..184c8e5c6 100755 --- a/templates/back/user/index.html.twig +++ b/templates/back/user/index.html.twig @@ -24,9 +24,11 @@ + + {% form_theme form 'form/dsfr_theme.html.twig' %} + {{ form_start(form) }} +
- {% form_theme form 'form/dsfr_theme.html.twig' %} - {{ form_start(form) }} {{ form_errors(form) }}
@@ -58,10 +60,9 @@ Réinitialiser les résultats
- {{ form_end(form) }}
-
+

{{users|length}} utilisateur{% if users|length > 1%}s{% endif %}

@@ -70,6 +71,11 @@
+
+ {{ form_row(form.orderType) }} +
+ {{ form_end(form) }} +
{% set tableHead %} {% if is_granted('ROLE_ADMIN') %} @@ -157,7 +163,7 @@ {% endfor %} {% endset %} - {% include '_partials/back/table.html.twig' with { 'tableLabel': 'Liste des utilisateurs', 'tableHead': tableHead, 'tableBody': tableBody } %} + {% include '_partials/back/table.html.twig' with { 'tableLabel': 'Liste des utilisateurs', 'tableHead': tableHead, 'tableBody': tableBody, 'cancelSortable': true } %}
{% import '_partials/macros.html.twig' as macros %}