From e0960c340483552d64c002a6d774f81436d03b18 Mon Sep 17 00:00:00 2001 From: Romain Date: Wed, 7 May 2025 18:34:49 +0200 Subject: [PATCH] =?UTF-8?q?r=C3=A9paration=20du=20projet=20et=20ajout=20de?= =?UTF-8?q?=20l=20affichage=20des=20favoris?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/AnnouncementController.php | 19 ++++++++++--- src/Repository/AnnouncementRepository.php | 34 +++++++---------------- templates/announcement/index.html.twig | 13 +++++++++ templates/announcement/show.html.twig | 3 ++ templates/faq/index.html.twig | 4 ++- templates/profile/employee.html.twig | 2 +- templates/profile/intern.html.twig | 7 ----- 7 files changed, 45 insertions(+), 37 deletions(-) diff --git a/src/Controller/AnnouncementController.php b/src/Controller/AnnouncementController.php index 31c6513..19899a7 100644 --- a/src/Controller/AnnouncementController.php +++ b/src/Controller/AnnouncementController.php @@ -3,6 +3,7 @@ namespace App\Controller; use App\Entity\Announcement; +use App\Entity\Intern; use App\Form\AnnouncementType; use App\Repository\AnnouncementRepository; use App\Repository\InternApplicationRepository; @@ -40,6 +41,19 @@ final class AnnouncementController extends AbstractController } } + if (in_array('ROLE_INTERN', $user->getRoles())) { + $showFavorites = $request->query->get('show_favorites'); + + /** @var Intern $intern */ + $intern = $user; + + if ($showFavorites) { + $announcements = $this->announcementRepository->findFavoritesByIntern($intern); + } else { + $announcements = $this->announcementRepository->findBy(['status' => 'Verified']); + } + } + if (in_array('ROLE_EMPLOYEE', $user->getRoles())) { $company = $user->getCompany(); @@ -48,10 +62,6 @@ final class AnnouncementController extends AbstractController } } - if (in_array('ROLE_INTERN', $user->getRoles())) { - $announcements = $this->announcementRepository->findBy(['status' => 'Verified']); - } - if ($companyName || $location || $category) { $announcements = $this->announcementRepository->searchAnnouncements($companyName, $location, $category); } @@ -68,6 +78,7 @@ final class AnnouncementController extends AbstractController 'announcements' => $announcements, 'favorites' => $favorites, 'showNonValidated' => $request->query->get('show_non_validated', false), + 'showFavorites' => $request->query->get('show_favorites', false) ]); } diff --git a/src/Repository/AnnouncementRepository.php b/src/Repository/AnnouncementRepository.php index 0e0094b..064af71 100644 --- a/src/Repository/AnnouncementRepository.php +++ b/src/Repository/AnnouncementRepository.php @@ -3,6 +3,7 @@ namespace App\Repository; use App\Entity\Announcement; +use App\Entity\Intern; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; @@ -38,28 +39,13 @@ class AnnouncementRepository extends ServiceEntityRepository return $queryBuilder->getQuery()->getResult(); } - // /** - // * @return Announcement[] Returns an array of Announcement objects - // */ - // public function findByExampleField($value): array - // { - // return $this->createQueryBuilder('a') - // ->andWhere('a.exampleField = :val') - // ->setParameter('val', $value) - // ->orderBy('a.id', 'ASC') - // ->setMaxResults(10) - // ->getQuery() - // ->getResult() - // ; - // } - - // public function findOneBySomeField($value): ?Announcement - // { - // return $this->createQueryBuilder('a') - // ->andWhere('a.exampleField = :val') - // ->setParameter('val', $value) - // ->getQuery() - // ->getOneOrNullResult() - // ; - // } + public function findFavoritesByIntern(Intern $intern): array + { + return $this->createQueryBuilder('a') + ->innerJoin('a.favoritesInterns', 'fav') + ->andWhere('fav.intern = :intern') + ->setParameter('intern', $intern) + ->getQuery() + ->getResult(); + } } diff --git a/templates/announcement/index.html.twig b/templates/announcement/index.html.twig index debc235..f601196 100644 --- a/templates/announcement/index.html.twig +++ b/templates/announcement/index.html.twig @@ -16,6 +16,17 @@ {% endif %} + {% if 'ROLE_INTERN' in app.user.roles %} +
+ + +
+ {% endif %} + + {% if 'ROLE_EMPLOYEE' in app.user.roles %}
@@ -43,6 +54,7 @@ Validée {% endif %} + {% if 'ROLE_INTERN' in app.user.roles %}
+ {% endif %}

{{ announcement.title }}

diff --git a/templates/announcement/show.html.twig b/templates/announcement/show.html.twig index b4dff6a..4395871 100644 --- a/templates/announcement/show.html.twig +++ b/templates/announcement/show.html.twig @@ -80,6 +80,8 @@ {% endif %} + + {% if 'ROLE_INTERN' in app.user.roles %}
+ {% endif %} diff --git a/templates/faq/index.html.twig b/templates/faq/index.html.twig index 3f3ee79..2a0429c 100644 --- a/templates/faq/index.html.twig +++ b/templates/faq/index.html.twig @@ -16,10 +16,12 @@
{% endfor %} + {% if 'ROLE_ADMIN' in app.user.roles %}
- Ajouter une FAQ / Poser une question + Ajouter une Question / Reponse
+ {% endif %} {% endblock %} diff --git a/templates/profile/employee.html.twig b/templates/profile/employee.html.twig index d83f460..55c871a 100644 --- a/templates/profile/employee.html.twig +++ b/templates/profile/employee.html.twig @@ -6,7 +6,7 @@

Prénom : {{ app.user.lastName }}

Adresse : {{ app.user.address }}

Téléphone : {{ app.user.tel }}

-

Email : {{ app.user.mail }}

+

Email : {{ app.user.mail }}

Sélectionner vos compétences - -
- Accéder aux favoris - -
-

Vos candidatures :

{% if applications|length > 0 %}