diff --git a/src/Controller/AnnouncementController.php b/src/Controller/AnnouncementController.php index 699d90b..707e1fc 100644 --- a/src/Controller/AnnouncementController.php +++ b/src/Controller/AnnouncementController.php @@ -20,7 +20,6 @@ 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'); @@ -47,18 +46,27 @@ final class AnnouncementController extends AbstractController $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); } + $favorites = []; + if (in_array('ROLE_INTERN', $user->getRoles())) { + $favorites = array_map( + fn($f) => $f->getAnnouncement()->getId(), + $user->getFavorites()->toArray() + ); + } + return $this->render('announcement/index.html.twig', [ 'announcements' => $announcements, + 'favorites' => $favorites, 'showNonValidated' => $request->query->get('show_non_validated', false), ]); } + #[Route('/new', name: 'app_announcement_new', methods: ['GET', 'POST'])] public function new(Request $request, EntityManagerInterface $entityManager): Response { diff --git a/src/Entity/Favoris.php b/src/Entity/Favoris.php index 26f1023..be05f56 100644 --- a/src/Entity/Favoris.php +++ b/src/Entity/Favoris.php @@ -2,6 +2,8 @@ namespace App\Entity; +use App\Entity\UserApp; +use App\Entity\Announcement; use App\Repository\FavorisRepository; use Doctrine\ORM\Mapping as ORM; @@ -13,15 +15,38 @@ class Favoris #[ORM\Column] private ?int $id = null; + #[ORM\ManyToOne(inversedBy: 'favoris')] + #[ORM\JoinColumn(nullable: false)] + private ?UserApp $user = null; + + #[ORM\ManyToOne(inversedBy: 'favoris')] + #[ORM\JoinColumn(nullable: false)] + private ?Announcement $announcement = null; + public function getId(): ?int { return $this->id; } - public function setId(int $id): static + public function getUser(): ?UserApp { - $this->id = $id; + return $this->user; + } + public function setUser(?UserApp $user): static + { + $this->user = $user; + return $this; + } + + public function getAnnouncement(): ?Announcement + { + return $this->announcement; + } + + public function setAnnouncement(?Announcement $announcement): static + { + $this->announcement = $announcement; return $this; } } diff --git a/templates/announcement/index.html.twig b/templates/announcement/index.html.twig index 0920dd6..debc235 100644 --- a/templates/announcement/index.html.twig +++ b/templates/announcement/index.html.twig @@ -7,84 +7,66 @@
{{ announcement.company.name }}