src/Entity/Notification.php line 12

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\NotificationRepository;
  4. use DateTime;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. #[ORM\Entity(repositoryClassNotificationRepository::class)]
  9. class Notification
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length255)]
  16.     #[Groups('read:notification')]
  17.     private ?string $title null;
  18.     #[ORM\Column(length255)]
  19.     #[Groups('read:notification')]
  20.     private ?string $message null;
  21.     #[ORM\Column(length255)]
  22.     #[Groups('read:notification')]
  23.     private ?string $url null;
  24.     #[ORM\Column(length255nullabletrue)]
  25.     #[Groups('create:notification')]
  26.     private ?string $channel 'target';
  27.     #[ORM\Column(length255nullabletrue)]
  28.     private ?string $target null;
  29.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  30.     #[Groups('read:notification')]
  31.     private ?\DateTimeInterface $createdAt;
  32.     #[ORM\ManyToOne]
  33.     private ?User $user null;
  34.     public function __construct()
  35.     {
  36.         $this->createdAt = new DateTime();
  37.     }
  38.     public function getId(): ?int
  39.     {
  40.         return $this->id;
  41.     }
  42.     public function getTitle(): ?string
  43.     {
  44.         return $this->title;
  45.     }
  46.     public function setTitle(string $title): self
  47.     {
  48.         $this->title $title;
  49.         return $this;
  50.     }
  51.     public function getMessage(): ?string
  52.     {
  53.         return $this->message;
  54.     }
  55.     public function setMessage(string $message): self
  56.     {
  57.         $this->message $message;
  58.         return $this;
  59.     }
  60.     public function getUrl(): ?string
  61.     {
  62.         return $this->url;
  63.     }
  64.     public function setUrl(string $url): self
  65.     {
  66.         $this->url $url;
  67.         return $this;
  68.     }
  69.     public function getChannel(): ?string
  70.     {
  71.         return $this->channel;
  72.     }
  73.     public function setChannel(?string $channel): self
  74.     {
  75.         $this->channel $channel;
  76.         return $this;
  77.     }
  78.     public function getTarget(): ?string
  79.     {
  80.         return $this->target;
  81.     }
  82.     public function setTarget(?string $target): self
  83.     {
  84.         $this->target $target;
  85.         return $this;
  86.     }
  87.     public function getCreatedAt(): ?\DateTimeInterface
  88.     {
  89.         return $this->createdAt;
  90.     }
  91.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  92.     {
  93.         $this->createdAt $createdAt;
  94.         return $this;
  95.     }
  96.     public function getUser(): ?User
  97.     {
  98.         return $this->user;
  99.     }
  100.     public function setUser(?User $user): self
  101.     {
  102.         $this->user $user;
  103.         return $this;
  104.     }
  105.     public function isRead(): bool
  106.     {
  107.         if (null === $this->user) return false;
  108.         $notificationsReadAt $this->user->getNotificationsReadAt();
  109.         return $notificationsReadAt && $this->createdAt $notificationsReadAt;
  110.     }
  111. }