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 %}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 - - -