<?php
namespace App\Entity;
use App\Repository\CommentRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
/**
* @ORM\Entity(repositoryClass=CommentRepository::class)
* @Serializer\ExclusionPolicy("ALL")
*/
class Comment extends BaseEntity
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Expose
*/
private $id;
/**
* @ORM\Column(type="text")
* @Serializer\Expose
*/
private $message;
/**
* @ORM\ManyToOne(targetEntity=Comment::class, inversedBy="comments")
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="parent", cascade={"persist", "remove"})
* @Serializer\Expose
*/
private $comments;
/**
* @ORM\ManyToOne(targetEntity=Subject::class, inversedBy="comments")
* @ORM\JoinColumn(onDelete="CASCADE")
*/
private $subject;
/**
* @ORM\OneToMany(targetEntity=CommentLike::class, mappedBy="comment", cascade={"persist", "remove"})
* @Serializer\Expose
*/
private $commentLikes;
/**
* @ORM\OneToMany(targetEntity=Notification::class, mappedBy="comment", cascade={"remove"})
*/
private $notifications;
public function __construct()
{
$this->comments = new ArrayCollection();
$this->commentLikes = new ArrayCollection();
$this->notifications = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getMessage(): ?string
{
return $this->message;
}
public function setMessage(string $message): self
{
$this->message = $message;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getComments(): Collection
{
return $this->comments;
}
public function addComment(self $comment): self
{
if (!$this->comments->contains($comment)) {
$this->comments[] = $comment;
$comment->setParent($this);
}
return $this;
}
public function removeComment(self $comment): self
{
if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed)
if ($comment->getParent() === $this) {
$comment->setParent(null);
}
}
return $this;
}
public function getSubject(): ?Subject
{
return $this->subject;
}
public function setSubject(?Subject $subject): self
{
$this->subject = $subject;
return $this;
}
/**
* @return Collection<int, CommentLike>
*/
public function getCommentLikes(): Collection
{
return $this->commentLikes;
}
public function addCommentLike(CommentLike $commentLike): self
{
if (!$this->commentLikes->contains($commentLike)) {
$this->commentLikes[] = $commentLike;
$commentLike->setComment($this);
}
return $this;
}
public function removeCommentLike(CommentLike $commentLike): self
{
if ($this->commentLikes->removeElement($commentLike)) {
// set the owning side to null (unless already changed)
if ($commentLike->getComment() === $this) {
$commentLike->setComment(null);
}
}
return $this;
}
/**
* @return Collection<int, Notification>
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notification $notification): self
{
if (!$this->notifications->contains($notification)) {
$this->notifications[] = $notification;
$notification->setComment($this);
}
return $this;
}
public function removeNotification(Notification $notification): self
{
if ($this->notifications->removeElement($notification)) {
// set the owning side to null (unless already changed)
if ($notification->getComment() === $this) {
$notification->setComment(null);
}
}
return $this;
}
}