Parcourir la source

ajout des relations pour discussions

Clément K il y a 4 ans
Parent
commit
105b2e7ee3
1 fichiers modifiés avec 40 ajouts et 0 suppressions
  1. 40 0
      src/Entity/Message.php

+ 40 - 0
src/Entity/Message.php

@@ -40,9 +40,15 @@ class Message
      */
     private $date;
 
+    /**
+     * @ORM\ManyToOne(targetEntity=Message::class, inversedBy="replies")
+     */
+    private $replies;
+
     public function __construct()
     {
         $this->mentions = new ArrayCollection();
+        $this->replies = new ArrayCollection();
     }
 
     public function getId(): ?int
@@ -109,4 +115,38 @@ class Message
 
         return $this;
     }
+
+    public function getReplies(): ?self
+    {
+        return $this->replies;
+    }
+
+    public function setReplies(?self $replies): self
+    {
+        $this->replies = $replies;
+
+        return $this;
+    }
+
+    public function addReply(self $reply): self
+    {
+        if (!$this->replies->contains($reply)) {
+            $this->replies[] = $reply;
+            $reply->setReplies($this);
+        }
+
+        return $this;
+    }
+
+    public function removeReply(self $reply): self
+    {
+        if ($this->replies->removeElement($reply)) {
+            // set the owning side to null (unless already changed)
+            if ($reply->getReplies() === $this) {
+                $reply->setReplies(null);
+            }
+        }
+
+        return $this;
+    }
 }