<?phpnamespace App\Entity;use App\Repository\ForumCommentRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;/** * @ORM\Entity(repositoryClass=ForumCommentRepository::class) */class ForumComment{ /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="text") */ private ?string $content; /** * @ORM\ManyToOne(targetEntity=ForumPost::class, inversedBy="comments") */ private ?ForumPost $post; /** * @ORM\Column(type="datetime") */ private ?\DateTimeInterface $createdAt; /** * @ORM\OneToMany(targetEntity=ForumCommentReply::class, mappedBy="comment") */ private Collection $commentReplies; /** * @ORM\ManyToOne(targetEntity=ForumUser::class, inversedBy="forumComments") */ private ?ForumUser $forumUser; /** * @ORM\OneToMany(targetEntity=ForumNotificationSubscriber::class, mappedBy="comment") */ private Collection $notificationSubscribers; //---------------------------------------------------------------- public function getTimeCreateString(): string { $date = $this->createdAt; $today = new \DateTime(); $interval = $today->diff($date); if ($interval->days == 0) { return 'Comment today'; } elseif ($interval->days == 1) { return 'Comment 1 day ago'; } elseif ($interval->days >= 2 && $interval->days <= 6) { return 'Comment ' . $interval->days . ' days ago'; } else { return 'Comment on ' . $date->format('j M Y'); } } //---------------------------------------------------------------- public function __construct() { $this->commentReplies = new ArrayCollection(); $this->createdAt = new \DateTime(); $this->notificationSubscribers = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getContent(): ?string { return $this->content; } public function setContent(string $content): self { $this->content = $content; return $this; } public function getPost(): ?ForumPost { return $this->post; } public function setPost(?ForumPost $post): self { $this->post = $post; return $this; } /** * @return Collection<int, ForumCommentReply> */ public function getCommentReplies(): Collection { return $this->commentReplies; } public function addCommentReply(ForumCommentReply $commentReply): self { if (!$this->commentReplies->contains($commentReply)) { $this->commentReplies[] = $commentReply; $commentReply->setComment($this); } return $this; } public function removeCommentReply(ForumCommentReply $commentReply): self { if ($this->commentReplies->removeElement($commentReply)) { // set the owning side to null (unless already changed) if ($commentReply->getComment() === $this) { $commentReply->setComment(null); } } return $this; } public function getCreatedAt(): ?\DateTimeInterface { return $this->createdAt; } public function setCreatedAt(\DateTimeInterface $createdAt): self { $this->createdAt = $createdAt; return $this; } public function getForumUser(): ?ForumUser { return $this->forumUser; } public function setForumUser(?ForumUser $forumUser): self { $this->forumUser = $forumUser; return $this; } /** * @return Collection<int, ForumNotificationSubscriber> */ public function getNotificationSubscribers(): Collection { return $this->notificationSubscribers; } public function addNotificationSubscriber(ForumNotificationSubscriber $notificationSubscriber): self { if (!$this->notificationSubscribers->contains($notificationSubscriber)) { $this->notificationSubscribers[] = $notificationSubscriber; $notificationSubscriber->setComment($this); } return $this; } public function removeNotificationSubscriber(ForumNotificationSubscriber $notificationSubscriber): self { if ($this->notificationSubscribers->removeElement($notificationSubscriber)) { // set the owning side to null (unless already changed) if ($notificationSubscriber->getComment() === $this) { $notificationSubscriber->setComment(null); } } return $this; }}