diff --git a/public/img/notifs_non_lues.png b/public/img/notifs_non_lues.png new file mode 100644 index 0000000000000000000000000000000000000000..a7633409c9b8cce47157da3819b627eef1df2e72 Binary files /dev/null and b/public/img/notifs_non_lues.png differ diff --git a/src/Controller/NotificationsController.php b/src/Controller/NotificationsController.php index bc8e7a4104fb7fd580d475587e1ce4577be361dd..b35715b5eac5b390b94fca0596901e05c75920fe 100644 --- a/src/Controller/NotificationsController.php +++ b/src/Controller/NotificationsController.php @@ -21,7 +21,7 @@ class NotificationsController extends AbstractController public function index(): Response { $entityManager = $this->doctrine->getManager(); - $notifs = $entityManager->getRepository(Notification::class)->findBy(['user_id' => $this->getUser()]);; + $notifs = $entityManager->getRepository(Notification::class)->findBy(['user_id' => $this->getUser()]); return $this->render('notifications/index.html.twig', [ 'notifs' => $notifs ]); diff --git a/src/Entity/Utilisateur.php b/src/Entity/Utilisateur.php index 0823522b864223770ee0426ff6f5fff8145952e2..527bd27b14020149ea61b2ee908bbae5149be50f 100644 --- a/src/Entity/Utilisateur.php +++ b/src/Entity/Utilisateur.php @@ -3,6 +3,7 @@ namespace App\Entity; use App\Repository\UtilisateurRepository; +use Doctrine\Persistence\ManagerRegistry; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; @@ -75,6 +76,9 @@ class Utilisateur extends Personne #[ORM\ManyToMany(targetEntity: Prestations::class, inversedBy: 'utilisateurs_aimant')] private Collection $prestations_aimees; + #[ORM\OneToMany(mappedBy: 'user_id', targetEntity: Notification::class, orphanRemoval: true)] + private Collection $notifs; + public function __construct() { $this->inscriptions = new ArrayCollection(); @@ -84,6 +88,7 @@ class Utilisateur extends Personne $this->prestations_proprietaire = new ArrayCollection(); $this->litiges = new ArrayCollection(); $this->prestations_aimees = new ArrayCollection(); + $this->notifs = new ArrayCollection(); } public function getNbFlorains(): ?int @@ -500,4 +505,15 @@ class Utilisateur extends Personne if (!$this->prestations_aimees) return false; return $this->prestations_aimees->contains($prestation); } + + /** + * @return Collection<int, Notification> + */ + public function getNotifs(): Collection { + return $this->notifs; + } + + public function hasNotifs() : bool { + return count($this->notifs) > 0; + } } diff --git a/templates/header.html.twig b/templates/header.html.twig index e4ea51503637c809ea90da6a929ab17ee1d767cf..c93c00c8329eeffbacee584a760ef2490d3a3374 100644 --- a/templates/header.html.twig +++ b/templates/header.html.twig @@ -9,7 +9,12 @@ {% endif %} </div> <p>{{ app.user.login }}</p> - <a href="{{ path("app_notifications")}}"><img src={{asset('/img/notifs.png')}} alt="logo profil" width="35px"/></a> + + {% if app.user.notifs|length > 0 %} + <a href="{{ path("app_notifications")}}"><img src={{asset('/img/notifs_non_lues.png')}} alt="logo profil" width="35px"/></a> + {% else %} + <a href="{{ path("app_notifications")}}"><img src={{asset('/img/notifs.png')}} alt="logo profil" width="35px"/></a> + {% endif %} <a href="{{ path("app_modif_user")}}" ><img src={{asset('/img/bonhomme.png')}} alt="logo profil" width="50px"/></a> {% if not is_granted('ROLE_ADMIN') %} <p>Solde: {{ app.user.getNbFlorains() }}</p>