src/Entity/Notification.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\NotificationRepository;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. #[ORM\Entity(repositoryClassNotificationRepository::class)]
  7. class Notification
  8. {
  9.     #[ORM\Id]
  10.     #[ORM\GeneratedValue]
  11.     #[ORM\Column]
  12.     private ?int $id null;
  13.     #[ORM\ManyToOne(inversedBy'notifications')]
  14.     #[ORM\JoinColumn(nullablefalse)]
  15.     private ?User $user null;
  16.     #[ORM\Column(length50)]
  17.     private ?string $type null;
  18.     #[ORM\Column(typeTypes::TEXT)]
  19.     private ?string $content null;
  20.     #[ORM\Column]
  21.     private ?bool $isRead null;
  22.     #[ORM\Column]
  23.     private ?\DateTimeImmutable $createdAt null;
  24.     #[ORM\Column(type'json'nullabletrue)]
  25.     private ?array $data null;
  26.     public function __construct()
  27.     {
  28.         $this->isRead false;
  29.         $this->createdAt = new \DateTimeImmutable();
  30.     }
  31.     public function getId(): ?int
  32.     {
  33.         return $this->id;
  34.     }
  35.     public function getUser(): ?User
  36.     {
  37.         return $this->user;
  38.     }
  39.     public function setUser(?User $user): static
  40.     {
  41.         $this->user $user;
  42.         return $this;
  43.     }
  44.     public function getType(): ?string
  45.     {
  46.         return $this->type;
  47.     }
  48.     public function setType(string $type): static
  49.     {
  50.         $this->type $type;
  51.         return $this;
  52.     }
  53.     public function getContent(): ?string
  54.     {
  55.         return $this->content;
  56.     }
  57.     public function setContent(string $content): static
  58.     {
  59.         $this->content $content;
  60.         return $this;
  61.     }
  62.     public function isIsRead(): ?bool
  63.     {
  64.         return $this->isRead;
  65.     }
  66.     public function setIsRead(bool $isRead): static
  67.     {
  68.         $this->isRead $isRead;
  69.         return $this;
  70.     }
  71.     public function getCreatedAt(): ?\DateTimeImmutable
  72.     {
  73.         return $this->createdAt;
  74.     }
  75.     public function setCreatedAt(\DateTimeImmutable $createdAt): static
  76.     {
  77.         $this->createdAt $createdAt;
  78.         return $this;
  79.     }
  80.     public function getData(): ?array
  81.     {
  82.         return $this->data;
  83.     }
  84.     public function setData(?array $data): static
  85.     {
  86.         $this->data $data;
  87.         return $this;
  88.     }
  89.     /**
  90.      * Mark the notification as read
  91.      */
  92.     public function markAsRead(): static
  93.     {
  94.         $this->isRead true;
  95.         return $this;
  96.     }
  97.     /**
  98.      * Check if the notification is for a submission
  99.      */
  100.     public function isSubmissionNotification(): bool
  101.     {
  102.         return in_array($this->type, ['submission_approved''submission_rejected']);
  103.     }
  104.     /**
  105.      * Check if the notification is for a team
  106.      */
  107.     public function isTeamNotification(): bool
  108.     {
  109.         return in_array($this->type, ['team_joined''team_left''team_role_changed']);
  110.     }
  111.     /**
  112.      * Check if the notification is for a season
  113.      */
  114.     public function isSeasonNotification(): bool
  115.     {
  116.         return in_array($this->type, ['season_started''season_ended']);
  117.     }
  118. }