src/Entity/Chat.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ChatRepository;
  4. use App\Entity\Traits\Timestampable;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use JMS\Serializer\Annotation\Groups;
  10. #[ORM\HasLifecycleCallbacks]
  11. #[ORM\Entity(repositoryClassChatRepository::class)]
  12. class Chat
  13. {
  14.     use Timestampable;
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     #[Groups(['getChats''chatView''chatAllList'])]
  19.     private ?int $id null;
  20.     #[ORM\OneToMany(mappedBy'chat'targetEntityMessage::class)]
  21.     #[Groups(['getChats''chatView''chatAllList'])]
  22.     private Collection $messages;
  23.     #[ORM\ManyToOne(inversedBy'chats')]
  24.     #[ORM\JoinColumn(nullablefalse)]
  25.     #[Groups(['chatView''chatAllList'])]
  26.     private ?User $initiator null;
  27.     #[ORM\ManyToOne(inversedBy'chats')]
  28.     #[ORM\JoinColumn(nullablefalse)]
  29.     #[Groups(['chatView''chatAllList'])]
  30.     private ?User $recipient null;
  31.     #[ORM\ManyToOne(inversedBy'chats')]
  32.     #[ORM\JoinColumn(nullablefalse)]
  33.     private ?SchoolYear $year null;
  34.     #[ORM\OneToMany(mappedBy'chat'targetEntityClassYear::class)]
  35.     private Collection $classes;
  36.     public function __construct()
  37.     {
  38.         $this->messages = new ArrayCollection();
  39.         $this->classes = new ArrayCollection();
  40.     }
  41.     public function getId(): ?int
  42.     {
  43.         return $this->id;
  44.     }
  45.     /**
  46.      * @return Collection<int, Message>
  47.      */
  48.     public function getMessages(): Collection
  49.     {
  50.         return $this->messages;
  51.     }
  52.     public function addMessage(Message $message): static
  53.     {
  54.         if (!$this->messages->contains($message)) {
  55.             $this->messages->add($message);
  56.             $message->setChat($this);
  57.         }
  58.         return $this;
  59.     }
  60.     public function removeMessage(Message $message): static
  61.     {
  62.         if ($this->messages->removeElement($message)) {
  63.             // set the owning side to null (unless already changed)
  64.             if ($message->getChat() === $this) {
  65.                 $message->setChat(null);
  66.             }
  67.         }
  68.         return $this;
  69.     }
  70.     public function getInitiator(): ?User
  71.     {
  72.         return $this->initiator;
  73.     }
  74.     public function setInitiator(?User $initiator): static
  75.     {
  76.         $this->initiator $initiator;
  77.         return $this;
  78.     }
  79.     public function getRecipient(): ?User
  80.     {
  81.         return $this->recipient;
  82.     }
  83.     public function setRecipient(?User $recipient): static
  84.     {
  85.         $this->recipient $recipient;
  86.         return $this;
  87.     }
  88.     public function getYear(): ?SchoolYear
  89.     {
  90.         return $this->year;
  91.     }
  92.     public function setYear(?SchoolYear $year): static
  93.     {
  94.         $this->year $year;
  95.         return $this;
  96.     }
  97.     /**
  98.      * @return Collection<int, ClassYear>
  99.      */
  100.     public function getClasses(): Collection
  101.     {
  102.         return $this->classes;
  103.     }
  104.     public function addClass(ClassYear $class): static
  105.     {
  106.         if (!$this->classes->contains($class)) {
  107.             $this->classes->add($class);
  108.             $class->setChat($this);
  109.         }
  110.         return $this;
  111.     }
  112.     public function removeClass(ClassYear $class): static
  113.     {
  114.         if ($this->classes->removeElement($class)) {
  115.             // set the owning side to null (unless already changed)
  116.             if ($class->getChat() === $this) {
  117.                 $class->setChat(null);
  118.             }
  119.         }
  120.         return $this;
  121.     }
  122. }