src/Entity/Conversation.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ConversationRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. /**
  9.  * @ORM\Entity(repositoryClass=ConversationRepository::class)
  10.  */
  11. class Conversation
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      * @Groups("conversation")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\OneToMany(targetEntity=ParticipantConversation::class, mappedBy="conversation", cascade={"persist"}, orphanRemoval=true)
  22.      */
  23.     private $participants;
  24.     /**
  25.      * @ORM\OneToMany(targetEntity=Message::class, mappedBy="conversation")
  26.      * @Groups("conversation")
  27.      */
  28.     private $messages;
  29.     /**
  30.      * @ORM\Column(type="string", length=255, nullable=true)
  31.      * @Groups({"message","conversation"})
  32.      */
  33.     private $title;
  34.     /**
  35.      * @ORM\Column(type="datetime", nullable=true)
  36.      * @Groups({"message","conversation"})
  37.      */
  38.     private $createdAt;
  39.     /**
  40.      * @ORM\OneToMany(targetEntity=Notification::class, mappedBy="conversation")
  41.      */
  42.     private $notifications;
  43.     public function __construct()
  44.     {
  45.         $this->participants = new ArrayCollection();
  46.         $this->messages = new ArrayCollection();
  47.         $this->createdAt = new \DateTime();
  48.         $this->notifications = new ArrayCollection();
  49.     }
  50.     public function getId(): ?int
  51.     {
  52.         return $this->id;
  53.     }
  54.     public function getTitle(): ?string
  55.     {
  56.         return $this->title;
  57.     }
  58.     public function setTitle(?string $title): self
  59.     {
  60.         $this->title $title;
  61.         return $this;
  62.     }
  63.     /**
  64.      * @return Collection<int, ParticipantConversation>
  65.      */
  66.     public function getParticipants(): Collection
  67.     {
  68.         return $this->participants;
  69.     }
  70.     public function addParticipant(ParticipantConversation $participant): self
  71.     {
  72.         if (!$this->participants->contains($participant)) {
  73.             $this->participants[] = $participant;
  74.             $participant->setConversation($this);
  75.         }
  76.         return $this;
  77.     }
  78.     public function removeParticipant(ParticipantConversation $participant): self
  79.     {
  80.         if ($this->participants->removeElement($participant)) {
  81.             // set the owning side to null (unless already changed)
  82.             if ($participant->getConversation() === $this) {
  83.                 $participant->setConversation(null);
  84.             }
  85.         }
  86.         return $this;
  87.     }
  88.     /**
  89.      * @return Collection<int, Message>
  90.      */
  91.     public function getMessages(): Collection
  92.     {
  93.         return $this->messages;
  94.     }
  95.     public function addMessage(Message $message): self
  96.     {
  97.         if (!$this->messages->contains($message)) {
  98.             $this->messages[] = $message;
  99.             $message->setConversation($this);
  100.         }
  101.         return $this;
  102.     }
  103.     public function removeMessage(Message $message): self
  104.     {
  105.         if ($this->messages->removeElement($message)) {
  106.             // set the owning side to null (unless already changed)
  107.             if ($message->getConversation() === $this) {
  108.                 $message->setConversation(null);
  109.             }
  110.         }
  111.         return $this;
  112.     }
  113.     public function getCreatedAt(): ?\DateTimeInterface
  114.     {
  115.         return $this->createdAt;
  116.     }
  117.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  118.     {
  119.         $this->createdAt $createdAt;
  120.         return $this;
  121.     }
  122.     /**
  123.      * @return Collection<int, Notification>
  124.      */
  125.     public function getNotifications(): Collection
  126.     {
  127.         return $this->notifications;
  128.     }
  129.     public function addNotification(Notification $notification): self
  130.     {
  131.         if (!$this->notifications->contains($notification)) {
  132.             $this->notifications[] = $notification;
  133.             $notification->setConversation($this);
  134.         }
  135.         return $this;
  136.     }
  137.     public function removeNotification(Notification $notification): self
  138.     {
  139.         if ($this->notifications->removeElement($notification)) {
  140.             // set the owning side to null (unless already changed)
  141.             if ($notification->getConversation() === $this) {
  142.                 $notification->setConversation(null);
  143.             }
  144.         }
  145.         return $this;
  146.     }
  147. }