From 19c4dd08e17f266a0bab4f0abc9cff17833172c6 Mon Sep 17 00:00:00 2001 From: barillote Date: Thu, 3 Apr 2025 16:00:26 +0200 Subject: [PATCH] Search internship + Merci Mr Boussarie --- src/Controller/AnnouncementController.php | 20 +++++++++++++------- src/Repository/AnnouncementRepository.php | 22 ++++++++++++++++++++++ templates/announcement/index.html.twig | 15 +++++++++++++++ templates/index/index.html.twig | 15 --------------- 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/src/Controller/AnnouncementController.php b/src/Controller/AnnouncementController.php index a1da498..699d90b 100644 --- a/src/Controller/AnnouncementController.php +++ b/src/Controller/AnnouncementController.php @@ -20,32 +20,38 @@ final class AnnouncementController extends AbstractController $user = $this->getUser(); $announcements = []; + // Récupérer les paramètres de recherche + $companyName = $request->query->get('company_name'); + $location = $request->query->get('location'); + $category = $request->query->get('category'); + if (in_array('ROLE_ADMIN', $user->getRoles())) { $showNonValidated = $request->query->get('show_non_validated'); if ($showNonValidated) { $announcements = $announcementRepository->findBy(['status' => 'notVerified']); - } - if (!$showNonValidated){ + } else { $announcements = $announcementRepository->findAll(); } - } if (in_array('ROLE_EMPLOYEE', $user->getRoles())) { $company = $user->getCompany(); - if ($company) - { + if ($company) { $announcements = $announcementRepository->findBy(['company' => $company]); } } - if (in_array('ROLE_INTERN', $user->getRoles())) - { + if (in_array('ROLE_INTERN', $user->getRoles())) { $announcements = $announcementRepository->findBy(['status' => 'Verified']); } + // Filtrer les annonces en fonction des critères de recherche + if ($companyName || $location || $category) { + $announcements = $announcementRepository->searchAnnouncements($companyName, $location, $category); + } + return $this->render('announcement/index.html.twig', [ 'announcements' => $announcements, 'showNonValidated' => $request->query->get('show_non_validated', false), diff --git a/src/Repository/AnnouncementRepository.php b/src/Repository/AnnouncementRepository.php index 36813af..0e0094b 100644 --- a/src/Repository/AnnouncementRepository.php +++ b/src/Repository/AnnouncementRepository.php @@ -16,6 +16,28 @@ class AnnouncementRepository extends ServiceEntityRepository parent::__construct($registry, Announcement::class); } + public function searchAnnouncements(?string $companyName, ?string $location, ?string $category): array + { + $queryBuilder = $this->createQueryBuilder('a')->InnerJoin('a.company', 'c'); + + if ($companyName) { + $queryBuilder->andWhere('c.name LIKE :companyName') + ->setParameter('companyName', '%' . $companyName . '%'); + } + + if ($location) { + $queryBuilder->andWhere('c.address LIKE :location') + ->setParameter('location', '%' . $location . '%'); + } + + if ($category) { + $queryBuilder->andWhere('a.title LIKE :category OR a.description LIKE :category') + ->setParameter('category', '%' . $category . '%'); + } + + return $queryBuilder->getQuery()->getResult(); + } + // /** // * @return Announcement[] Returns an array of Announcement objects // */ diff --git a/templates/announcement/index.html.twig b/templates/announcement/index.html.twig index 39ecc15..0920dd6 100644 --- a/templates/announcement/index.html.twig +++ b/templates/announcement/index.html.twig @@ -36,6 +36,21 @@
+
+
+ + + + +
+
+ {% for announcement in announcements %}
diff --git a/templates/index/index.html.twig b/templates/index/index.html.twig index a35c679..3af426a 100644 --- a/templates/index/index.html.twig +++ b/templates/index/index.html.twig @@ -11,21 +11,6 @@

Trouvez votre stage de rêve !

Connectez les talents aux opportunités : votre clé vers le succès professionnel

-
-
- - - - -
-

la recherche n'est pas encore implémenté

-