src/Entity/ForumComment.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ForumCommentRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=ForumCommentRepository::class)
  10.  */
  11. class ForumComment
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="text")
  21.      */
  22.     private ?string $content;
  23.     /**
  24.      * @ORM\ManyToOne(targetEntity=ForumPost::class, inversedBy="comments")
  25.      */
  26.     private ?ForumPost $post;
  27.     /**
  28.      * @ORM\Column(type="datetime")
  29.      */
  30.     private ?\DateTimeInterface $createdAt;
  31.     /**
  32.      * @ORM\OneToMany(targetEntity=ForumCommentReply::class, mappedBy="comment")
  33.      */
  34.     private Collection $commentReplies;
  35.     /**
  36.      * @ORM\ManyToOne(targetEntity=ForumUser::class, inversedBy="forumComments")
  37.      */
  38.     private ?ForumUser $forumUser;
  39.     /**
  40.      * @ORM\OneToMany(targetEntity=ForumNotificationSubscriber::class, mappedBy="comment")
  41.      */
  42.     private Collection $notificationSubscribers;
  43.     //----------------------------------------------------------------
  44.     public function getTimeCreateString(): string
  45.     {
  46.         $date $this->createdAt;
  47.         $today = new \DateTime();
  48.         $interval $today->diff($date);
  49.         if ($interval->days == 0) {
  50.             return 'Comment today';
  51.         } elseif ($interval->days == 1) {
  52.             return 'Comment 1 day ago';
  53.         } elseif ($interval->days >= && $interval->days <= 6) {
  54.             return 'Comment ' $interval->days ' days ago';
  55.         } else {
  56.             return 'Comment on ' $date->format('j M Y');
  57.         }
  58.     }
  59.     //----------------------------------------------------------------
  60.     public function __construct()
  61.     {
  62.         $this->commentReplies = new ArrayCollection();
  63.         $this->createdAt = new \DateTime();
  64.         $this->notificationSubscribers = new ArrayCollection();
  65.     }
  66.     public function getId(): ?int
  67.     {
  68.         return $this->id;
  69.     }
  70.     public function getContent(): ?string
  71.     {
  72.         return $this->content;
  73.     }
  74.     public function setContent(string $content): self
  75.     {
  76.         $this->content $content;
  77.         return $this;
  78.     }
  79.     public function getPost(): ?ForumPost
  80.     {
  81.         return $this->post;
  82.     }
  83.     public function setPost(?ForumPost $post): self
  84.     {
  85.         $this->post $post;
  86.         return $this;
  87.     }
  88.     /**
  89.      * @return Collection<int, ForumCommentReply>
  90.      */
  91.     public function getCommentReplies(): Collection
  92.     {
  93.         return $this->commentReplies;
  94.     }
  95.     public function addCommentReply(ForumCommentReply $commentReply): self
  96.     {
  97.         if (!$this->commentReplies->contains($commentReply)) {
  98.             $this->commentReplies[] = $commentReply;
  99.             $commentReply->setComment($this);
  100.         }
  101.         return $this;
  102.     }
  103.     public function removeCommentReply(ForumCommentReply $commentReply): self
  104.     {
  105.         if ($this->commentReplies->removeElement($commentReply)) {
  106.             // set the owning side to null (unless already changed)
  107.             if ($commentReply->getComment() === $this) {
  108.                 $commentReply->setComment(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.     public function getForumUser(): ?ForumUser
  123.     {
  124.         return $this->forumUser;
  125.     }
  126.     public function setForumUser(?ForumUser $forumUser): self
  127.     {
  128.         $this->forumUser $forumUser;
  129.         return $this;
  130.     }
  131.     /**
  132.      * @return Collection<int, ForumNotificationSubscriber>
  133.      */
  134.     public function getNotificationSubscribers(): Collection
  135.     {
  136.         return $this->notificationSubscribers;
  137.     }
  138.     public function addNotificationSubscriber(ForumNotificationSubscriber $notificationSubscriber): self
  139.     {
  140.         if (!$this->notificationSubscribers->contains($notificationSubscriber)) {
  141.             $this->notificationSubscribers[] = $notificationSubscriber;
  142.             $notificationSubscriber->setComment($this);
  143.         }
  144.         return $this;
  145.     }
  146.     public function removeNotificationSubscriber(ForumNotificationSubscriber $notificationSubscriber): self
  147.     {
  148.         if ($this->notificationSubscribers->removeElement($notificationSubscriber)) {
  149.             // set the owning side to null (unless already changed)
  150.             if ($notificationSubscriber->getComment() === $this) {
  151.                 $notificationSubscriber->setComment(null);
  152.             }
  153.         }
  154.         return $this;
  155.     }
  156. }