Skip to content

Commit

Permalink
Admin search
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Keyp committed Jan 26, 2022
1 parent 4a98b33 commit 45fb5f9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 37 deletions.
18 changes: 12 additions & 6 deletions src/Controller/AdminInterfaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
namespace App\Controller;

use App\Entity\User;
use App\Form\SearchType;
use App\Form\SearchNameType;
use App\Repository\UserRepository;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -18,11 +17,18 @@ class AdminInterfaceController extends AbstractController
#[Route('/admin/interface', name: 'admin_interface')]
public function index(UserRepository $userRepository, Request $request): Response
{
$form = $this -> createForm(SearchType::class);
$form = $this->createForm(SearchNameType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$f = $form->getData();
$users = $userRepository->findBy(['firstname' => $f]);


if($form->handleRequest($request)->isSubmitted() && $form->isValid() ){
$criteria = $form->getData();
$recherche = $userRepository->search($criteria);
return $this->render('admin_interface/index.html.twig', [
'controller_name' => 'AdminInterfaceController',
'users' => $users,
'form' => $form->createView(),
]);
}

$users = $userRepository->findAll();
Expand Down
19 changes: 0 additions & 19 deletions src/Controller/SearchController.php

This file was deleted.

13 changes: 6 additions & 7 deletions src/Form/SearchType.php → src/Form/SearchNameType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,29 @@

namespace App\Form;

use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class SearchType extends AbstractType
class SearchNameType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('username', TextType::class, [
'label' => 'Nom utilisateur'
])-> add('save', SubmitType::class,[
'label' => 'Rechercher'
->add('firstname', TextType::class, [
'label' => 'Prénom',
])->add('save', SubmitType::class, [
'label' => 'Enregistrer'
])
;
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
// Configure your form options here
]);
}
}
2 changes: 1 addition & 1 deletion src/Form/UserFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'label' => 'Code postal'
])->add('save', SubmitType::class, [
'label' => 'Enregistrer'
]);;
]);
}

public function configureOptions(OptionsResolver $resolver): void
Expand Down
11 changes: 7 additions & 4 deletions templates/admin_interface/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
</style>

<div class="container-fluid">
<h1>Modération des comptes utilisateurs ✅</h1>
<div class="search">
{{form(form)}}
<div class="container-fluid text-center">
<h1 class="mt-4">Modération des comptes utilisateurs ✅</h1>
<div class="search w-60 d-flex justify-content-start align-items-center text-start mb-4">
<form method="POST">
{{form_row(form.firstname)}}
{{form_row(form.save)}}
</form>
</div>
<table class="container text-center">
<thead>
Expand Down

0 comments on commit 45fb5f9

Please sign in to comment.