src/Entity/AlerteUtilisateur.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AlerteUtilisateurRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. #[ORM\Entity(repositoryClassAlerteUtilisateurRepository::class)]
  6. #[ORM\Table(name'alerte_utilisateur')]
  7. #[ORM\Index(name'idx_alerte_user'columns: ['alerte_id''user_id'])]
  8. #[ORM\Index(name'idx_user_statut'columns: ['user_id''statut'])]
  9. class AlerteUtilisateur
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\ManyToOne(targetEntityAlert::class)]
  16.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  17.     private ?Alert $alerte null;
  18.     #[ORM\ManyToOne(targetEntityUser::class)]
  19.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  20.     private ?User $user null;
  21.     #[ORM\Column(length20)]
  22.     private ?string $statut 'nouvelle'// nouvelle, vue, traitee, ignoree
  23.     #[ORM\Column]
  24.     private ?\DateTimeImmutable $createdAt null;
  25.     #[ORM\Column(nullabletrue)]
  26.     private ?\DateTimeImmutable $viewedAt null;
  27.     #[ORM\Column(nullabletrue)]
  28.     private ?\DateTimeImmutable $treatedAt null;
  29.     public function __construct()
  30.     {
  31.         $this->createdAt = new \DateTimeImmutable();
  32.         $this->statut 'nouvelle';
  33.     }
  34.     public function getId(): ?int
  35.     {
  36.         return $this->id;
  37.     }
  38.     public function getAlerte(): ?Alert
  39.     {
  40.         return $this->alerte;
  41.     }
  42.     public function setAlerte(?Alert $alerte): static
  43.     {
  44.         $this->alerte $alerte;
  45.         return $this;
  46.     }
  47.     public function getUser(): ?User
  48.     {
  49.         return $this->user;
  50.     }
  51.     public function setUser(?User $user): static
  52.     {
  53.         $this->user $user;
  54.         return $this;
  55.     }
  56.     public function getStatut(): ?string
  57.     {
  58.         return $this->statut;
  59.     }
  60.     public function setStatut(string $statut): static
  61.     {
  62.         $this->statut $statut;
  63.         return $this;
  64.     }
  65.     public function getCreatedAt(): ?\DateTimeImmutable
  66.     {
  67.         return $this->createdAt;
  68.     }
  69.     public function setCreatedAt(\DateTimeImmutable $createdAt): static
  70.     {
  71.         $this->createdAt $createdAt;
  72.         return $this;
  73.     }
  74.     public function getViewedAt(): ?\DateTimeImmutable
  75.     {
  76.         return $this->viewedAt;
  77.     }
  78.     public function setViewedAt(?\DateTimeImmutable $viewedAt): static
  79.     {
  80.         $this->viewedAt $viewedAt;
  81.         return $this;
  82.     }
  83.     public function getTreatedAt(): ?\DateTimeImmutable
  84.     {
  85.         return $this->treatedAt;
  86.     }
  87.     public function setTreatedAt(?\DateTimeImmutable $treatedAt): static
  88.     {
  89.         $this->treatedAt $treatedAt;
  90.         return $this;
  91.     }
  92.     // Méthodes utilitaires
  93.     public function isNouvelle(): bool
  94.     {
  95.         return $this->statut === 'nouvelle';
  96.     }
  97.     public function marquerCommeVue(): void
  98.     {
  99.         if ($this->statut === 'nouvelle') {
  100.             $this->statut 'vue';
  101.             $this->viewedAt = new \DateTimeImmutable();
  102.         }
  103.     }
  104.     public function marquerCommeTraitee(): void
  105.     {
  106.         $this->statut 'traitee';
  107.         $this->treatedAt = new \DateTimeImmutable();
  108.     }
  109.     public function marquerCommeIgnoree(): void
  110.     {
  111.         $this->statut 'ignoree';
  112.     }
  113. }