src/Entity/ChatMessage.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ChatMessageRepository;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Serializer\Annotation\Groups// Add this use statement
  7. #[ORM\Entity(repositoryClassChatMessageRepository::class)]
  8. class ChatMessage
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     #[Groups(["chat_message"])]
  14.     private ?int $id null;
  15.     #[ORM\ManyToOne(inversedBy'chatMessages')]
  16.     #[ORM\JoinColumn(nullablefalse)]
  17.     #[Groups(["chat_message"])] // User needs to be serializable with 'chat_message' group too
  18.     private ?User $user null;
  19.     #[ORM\ManyToOne(inversedBy'chatMessages')]
  20.     #[ORM\JoinColumn(nullabletrue)]
  21.     #[Groups(["chat_message"])] // Team needs to be serializable with 'chat_message' group too
  22.     private ?Team $team null;
  23.     #[ORM\ManyToOne]
  24.     #[ORM\JoinColumn(nullabletrue)]
  25.     #[Groups(["chat_message"])] // Season needs to be serializable with 'chat_message' group too
  26.     private ?Season $season null;
  27.     #[ORM\ManyToOne]
  28.     #[ORM\JoinColumn(nullabletrue)]
  29.     #[Groups(["chat_message"])] // Recipient (User) needs to be serializable
  30.     private ?User $recipient null;
  31.     #[ORM\Column(length20)]
  32.     #[Groups(["chat_message"])]
  33.     private string $type 'team'// Options: 'team', 'season', 'direct'
  34.     #[ORM\Column(typeTypes::TEXT)]
  35.     #[Groups(["chat_message"])]
  36.     private ?string $content null;
  37.     #[ORM\Column(length255nullabletrue)]
  38.     #[Groups(["chat_message"])]
  39.     private ?string $attachmentUrl null;
  40.     #[ORM\Column]
  41.     #[Groups(["chat_message"])]
  42.     private ?\DateTimeImmutable $createdAt null;
  43.     #[ORM\Column]
  44.     #[Groups(["chat_message"])]
  45.     private ?bool $isRead null;
  46.     public function __construct()
  47.     {
  48.         $this->createdAt = new \DateTimeImmutable();
  49.         $this->isRead false;
  50.     }
  51.     public function getId(): ?int
  52.     {
  53.         return $this->id;
  54.     }
  55.     public function getUser(): ?User
  56.     {
  57.         return $this->user;
  58.     }
  59.     public function setUser(?User $user): static
  60.     {
  61.         $this->user $user;
  62.         return $this;
  63.     }
  64.     public function getTeam(): ?Team
  65.     {
  66.         return $this->team;
  67.     }
  68.     public function setTeam(?Team $team): static
  69.     {
  70.         $this->team $team;
  71.         return $this;
  72.     }
  73.     public function getSeason(): ?Season
  74.     {
  75.         return $this->season;
  76.     }
  77.     public function setSeason(?Season $season): static
  78.     {
  79.         $this->season $season;
  80.         return $this;
  81.     }
  82.     public function getRecipient(): ?User
  83.     {
  84.         return $this->recipient;
  85.     }
  86.     public function setRecipient(?User $recipient): static
  87.     {
  88.         $this->recipient $recipient;
  89.         return $this;
  90.     }
  91.     public function getType(): ?string
  92.     {
  93.         return $this->type;
  94.     }
  95.     public function setType(string $type): static
  96.     {
  97.         $this->type $type;
  98.         return $this;
  99.     }
  100.     public function getContent(): ?string
  101.     {
  102.         return $this->content;
  103.     }
  104.     public function setContent(string $content): static
  105.     {
  106.         $this->content $content;
  107.         return $this;
  108.     }
  109.     public function getAttachmentUrl(): ?string
  110.     {
  111.         return $this->attachmentUrl;
  112.     }
  113.     public function setAttachmentUrl(?string $attachmentUrl): static
  114.     {
  115.         $this->attachmentUrl $attachmentUrl;
  116.         return $this;
  117.     }
  118.     public function getCreatedAt(): ?\DateTimeImmutable
  119.     {
  120.         return $this->createdAt;
  121.     }
  122.     public function setCreatedAt(\DateTimeImmutable $createdAt): static
  123.     {
  124.         $this->createdAt $createdAt;
  125.         return $this;
  126.     }
  127.     public function isIsRead(): ?bool
  128.     {
  129.         return $this->isRead;
  130.     }
  131.     public function setIsRead(bool $isRead): static
  132.     {
  133.         $this->isRead $isRead;
  134.         return $this;
  135.     }
  136.     /**
  137.      * Mark the message as read
  138.      */
  139.     public function markAsRead(): static
  140.     {
  141.         $this->isRead true;
  142.         return $this;
  143.     }
  144.     /**
  145.      * Check if the message has an attachment
  146.      */
  147.     public function hasAttachment(): bool
  148.     {
  149.         return $this->attachmentUrl !== null;
  150.     }
  151. }