src/Entity/Comment.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CommentRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JMS\Serializer\Annotation as Serializer;
  8. /**
  9. * @ORM\Entity(repositoryClass=CommentRepository::class)
  10. * @Serializer\ExclusionPolicy("ALL")
  11. */
  12. class Comment extends BaseEntity
  13. {
  14. /**
  15. * @ORM\Id
  16. * @ORM\GeneratedValue
  17. * @ORM\Column(type="integer")
  18. * @Serializer\Expose
  19. */
  20. private $id;
  21. /**
  22. * @ORM\Column(type="text")
  23. * @Serializer\Expose
  24. */
  25. private $message;
  26. /**
  27. * @ORM\ManyToOne(targetEntity=Comment::class, inversedBy="comments")
  28. */
  29. private $parent;
  30. /**
  31. * @ORM\OneToMany(targetEntity=Comment::class, mappedBy="parent", cascade={"persist", "remove"})
  32. * @Serializer\Expose
  33. */
  34. private $comments;
  35. /**
  36. * @ORM\ManyToOne(targetEntity=Subject::class, inversedBy="comments")
  37. * @ORM\JoinColumn(onDelete="CASCADE")
  38. */
  39. private $subject;
  40. /**
  41. * @ORM\OneToMany(targetEntity=CommentLike::class, mappedBy="comment", cascade={"persist", "remove"})
  42. * @Serializer\Expose
  43. */
  44. private $commentLikes;
  45. /**
  46. * @ORM\OneToMany(targetEntity=Notification::class, mappedBy="comment", cascade={"remove"})
  47. */
  48. private $notifications;
  49. public function __construct()
  50. {
  51. $this->comments = new ArrayCollection();
  52. $this->commentLikes = new ArrayCollection();
  53. $this->notifications = new ArrayCollection();
  54. }
  55. public function getId(): ?int
  56. {
  57. return $this->id;
  58. }
  59. public function getMessage(): ?string
  60. {
  61. return $this->message;
  62. }
  63. public function setMessage(string $message): self
  64. {
  65. $this->message = $message;
  66. return $this;
  67. }
  68. public function getParent(): ?self
  69. {
  70. return $this->parent;
  71. }
  72. public function setParent(?self $parent): self
  73. {
  74. $this->parent = $parent;
  75. return $this;
  76. }
  77. /**
  78. * @return Collection<int, self>
  79. */
  80. public function getComments(): Collection
  81. {
  82. return $this->comments;
  83. }
  84. public function addComment(self $comment): self
  85. {
  86. if (!$this->comments->contains($comment)) {
  87. $this->comments[] = $comment;
  88. $comment->setParent($this);
  89. }
  90. return $this;
  91. }
  92. public function removeComment(self $comment): self
  93. {
  94. if ($this->comments->removeElement($comment)) {
  95. // set the owning side to null (unless already changed)
  96. if ($comment->getParent() === $this) {
  97. $comment->setParent(null);
  98. }
  99. }
  100. return $this;
  101. }
  102. public function getSubject(): ?Subject
  103. {
  104. return $this->subject;
  105. }
  106. public function setSubject(?Subject $subject): self
  107. {
  108. $this->subject = $subject;
  109. return $this;
  110. }
  111. /**
  112. * @return Collection<int, CommentLike>
  113. */
  114. public function getCommentLikes(): Collection
  115. {
  116. return $this->commentLikes;
  117. }
  118. public function addCommentLike(CommentLike $commentLike): self
  119. {
  120. if (!$this->commentLikes->contains($commentLike)) {
  121. $this->commentLikes[] = $commentLike;
  122. $commentLike->setComment($this);
  123. }
  124. return $this;
  125. }
  126. public function removeCommentLike(CommentLike $commentLike): self
  127. {
  128. if ($this->commentLikes->removeElement($commentLike)) {
  129. // set the owning side to null (unless already changed)
  130. if ($commentLike->getComment() === $this) {
  131. $commentLike->setComment(null);
  132. }
  133. }
  134. return $this;
  135. }
  136. /**
  137. * @return Collection<int, Notification>
  138. */
  139. public function getNotifications(): Collection
  140. {
  141. return $this->notifications;
  142. }
  143. public function addNotification(Notification $notification): self
  144. {
  145. if (!$this->notifications->contains($notification)) {
  146. $this->notifications[] = $notification;
  147. $notification->setComment($this);
  148. }
  149. return $this;
  150. }
  151. public function removeNotification(Notification $notification): self
  152. {
  153. if ($this->notifications->removeElement($notification)) {
  154. // set the owning side to null (unless already changed)
  155. if ($notification->getComment() === $this) {
  156. $notification->setComment(null);
  157. }
  158. }
  159. return $this;
  160. }
  161. }