Sfoglia il codice sorgente

Tous les filtres fonctionnels

Sangfroid 9 mesi fa
parent
commit
9507ffed63

+ 1 - 1
assets/app.js

@@ -21,5 +21,5 @@ const sv = switchView("#switchview");
 const se = switchEtat ('[data-fonction="switch"]');
 
 jQuery(function() {
-    $('[data-toggle="star-filter"]').filtreParNote();
+    //$('[data-toggle="star-filter"]').filtreParNote();
 })

+ 1 - 0
src/Controller/FilmAbstractController.php

@@ -14,6 +14,7 @@ abstract class FilmAbstractController extends AbstractController
     {
         $session = $request->getSession();
 
+        
         $filterDto = $session->get('filters', new FiltersDTO());
         $filtersForm = $this->createForm(FiltersType::class, $filterDto);
 

+ 1 - 2
src/Controller/SearchController.php

@@ -18,8 +18,7 @@ class SearchController extends AbstractController
         $query = $request->query->get('q', "");
         return $this->render('videotheque/liste_'.$options->vue().'.html.twig', array(
             'listeFilms'    =>  $filmSearch->search($query),
-            'titre'         =>  'Recherche '. $query,
-            'query'         =>  $query
+            'titre'         =>  'Recherche '. $query
         ));
     }
 }

+ 1 - 0
src/Controller/VideothequeListController.php

@@ -25,6 +25,7 @@ class VideothequeListController extends FilmAbstractController
 	{
         $filtersForm = $this->formPagination($request);
         $listeFilms = $filmRepository->findTous($filtersForm->getData()->toArray());
+        dump($filtersForm->getData());
 
 		return $this->render('videotheque/liste_'.$options->vue().'.html.twig', array(
             'listeFilms'	=>	$listeFilms,

+ 7 - 3
src/Dto/FiltersDTO.php

@@ -2,6 +2,7 @@
 
 namespace App\Dto;
 
+use App\Entity\User;
 use Symfony\Component\Validator\Constraints as Assert;
 
 class FiltersDTO
@@ -12,7 +13,9 @@ class FiltersDTO
         #[Assert\LessThanOrEqual(100)]
         public int $nbResults = 25,
 
-        public ?string $userName = null,
+        public ?User $userName = null,
+        
+        public ?int $note = null,
         
         #[Assert\NotBlank()]
         public string $sortBy = 'dateSubmited',
@@ -21,7 +24,7 @@ class FiltersDTO
         public string $sortOrder = 'DESC'
     )
     {
-        
+
     }
 
     public function toArray(): array
@@ -30,7 +33,8 @@ class FiltersDTO
             'limit'     => $this->nbResults,
             'username'  => $this->userName,
             'sortBy'    => $this->sortBy,
-            'sortOrder' => $this->sortOrder
+            'sortOrder' => $this->sortOrder,
+            'note'      => $this->note
         ];
     }
 }

+ 30 - 2
src/Form/FiltersType.php

@@ -3,8 +3,13 @@
 namespace App\Form;
 
 use App\Dto\FiltersDTO;
+use App\Entity\User;
+use App\Repository\UserRepository;
+use Doctrine\ORM\QueryBuilder;
+use Symfony\Bridge\Doctrine\Form\Type\EntityType;
 use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
+use Symfony\Component\Form\Extension\Core\Type\NumberType;
 use Symfony\Component\Form\FormBuilderInterface;
 use Symfony\Component\OptionsResolver\OptionsResolver;
 
@@ -13,6 +18,20 @@ class FiltersType extends AbstractType
     public function buildForm(FormBuilderInterface $builder, array $options): void
     {
         $builder
+            ->add('note', NumberType::class, [
+                'required'  => false,
+                'label'       => "Note au dessus de",
+                'attr'      => [
+                    'min'   => 0,
+                    'max'   => 5,
+                    'class' => "rating",
+                    'data-step' => 1,
+                    'data-show-clear'   => "true",
+                    'data-show-caption' => "false",
+                    'data-size'         => "sm",
+                    'data-theme'          => "krajee-fa"
+                ],
+            ])
             ->add('nbResults', ChoiceType::class, [
                 'choices' => [
                     '10' => 10,
@@ -21,8 +40,17 @@ class FiltersType extends AbstractType
                     '100' => 100
                 ]
             ])
-            ->add('userName', null, [
-                'required' => false
+            ->add('userName', EntityType::class, [
+                'required' => false,
+                'class' => User::class,
+                'choice_label' => 'username',
+                'choice_value' => function(?User $user): string {
+                    return $user ? $user->getUserIdentifier() : '';
+                },
+                'query_builder' => function (UserRepository $er): QueryBuilder {
+                    return $er->createQueryBuilder('u')
+                        ->orderBy('u.username', 'ASC');
+                }
             ])
             ->add('sortBy', ChoiceType::class, [
                 'choices' => [

+ 11 - 1
src/Repository/FilmRepository.php

@@ -87,10 +87,20 @@ class FilmRepository extends ServiceEntityRepository
 
     public function queryFilter(array $filters = []): QueryBuilder
     {
-        return $this->createQueryBuilder('f')
+        $qb =  $this->createQueryBuilder('f')
             ->orderBy('f.'.($filters['sortBy'] ?? 'dateSubmited'), $filters['sortOrder'] ?? 'DESC')
             ->setMaxResults((int)($filters['limit'] ?? 100))
+            ->andWhere('f.note >= :note')
+            ->setParameter('note', $filters['note'] ?? 0)
         ;
+        if ($filters['username']) {
+            $qb
+                ->andWhere('f.authered = :authered')
+                ->setParameter('authered', $filters['username'])
+            ;
+        }
+        return $qb;
+        
     }
 
     public function findTous (array $filters = []): Paginator

+ 20 - 5
templates/videotheque/_filters_form.html.twig

@@ -1,8 +1,23 @@
 {% if filtersForm is defined %}
-    {{ form_start(filtersForm) }}
+<div data-controller="collapser mb-3">
+    <button class="btn text-primary" data-bs-toggle="collapse" data-bs-target="#collapse-filters">Filtres <i data-collapser-target="button" class="fa fa-chevron-circle-right fa-lg"></i></button>
+    <div id="collapse-filters" class="collapse" data-collapser-target="collapse">
+        {% form_theme filtersForm 'bootstrap_5_horizontal_layout.html.twig' %}
+            {{ form_start(filtersForm) }}
+        
+            {{ form_row(filtersForm.note) }}
+            {{ form_row(filtersForm.nbResults) }}
+            {{ form_row(filtersForm.userName) }}
 
-    {{ form_rest(filtersForm)}}
-    <button class="btn btn-primary mb-3" type="submit">Filtrer</button>
-
-    {{ form_end(filtersForm) }}
+            {{ form_row(filtersForm.sortBy) }}
+            {{ form_row(filtersForm.sortOrder) }}
+            {{ form_rest(filtersForm)}}
+            <div class="d-flex">
+                <div class="me-auto"></div>
+                <button class="btn btn-primary mb-3" type="submit">Filtrer</button>
+            </div>
+                
+            {{ form_end(filtersForm) }}
+    </div>
+</div>
 {% endif %}

+ 3 - 19
templates/videotheque/_liste_header.html.twig

@@ -2,24 +2,8 @@
     {% if is_granted('IS_AUTHENTICATED_REMEMBERED') %}
         <p class="me-2"><a class="btn btn-primary" role="button" href="{{ path('videotheque_ajouter') }}"><i class="fa fa-plus-square fa-lg"></i> Ajouter un film</a></p>
         <p class="me-2"><a class="btn btn-primary" role="button" href="{{ path('videotheque_ajouter_tmdb') }}"><i class="fa fa-plus-square fa-lg"></i> Ajouter par TMDB</a></p>
-        <p class="me-auto"><a href="#" role="button" class="btn btn-secondary" id="switchview">Changer de vue</a></p>
+        <p class="me-2"><a href="#" role="button" class="btn btn-secondary" id="switchview">Changer de vue</a></p>
           
-        {% endif %}
-    <p class="">Filtrer par film au dessus de
-    <input class="rating"
-        data-disabled="false"
-        data-show-clear="true"
-        data-show-caption="false"
-        data-theme="krajee-fa"
-        data-toggle="star-filter"
-        data-path="#tableFilms"
-        style="display:none;"
-        min=0
-        max=5
-        data-step=1
-        data-size="sm"
-        value="0">
-    </p>
+    {% endif %}
 </div>
-
-{{ include ('videotheque/_filters_form.html.twig') }}
+{{ include ('videotheque/_filters_form.html.twig') }}

+ 11 - 1
translations/messages.fr.yaml

@@ -41,4 +41,14 @@ Super Admin: Super Admin
 Compte activé: Compte activé
 Activated: Compte activé
 Oui: Oui
-Non: Non
+Non: Non
+
+Note au dessus de: Note au dessus de 
+Nb results: Résultats par page
+User name: Films ajoutés par
+Sort by: Tri par
+Sort order: Ordre
+ASC: Croissant
+DESC: Décroissant
+Date de soumission: Date de soumission
+Note: Note