src/Entity/Comment.php line 14

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\DBAL\Types\Types;
  7. use App\Entity\Traits\Timestampable;
  8. use Doctrine\ORM\Mapping as ORM;
  9. #[ORM\HasLifecycleCallbacks]
  10. #[ORM\Entity(repositoryClassCommentRepository::class)]
  11. class Comment
  12. {
  13.     use Timestampable;
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\Column(length255)]
  19.     private ?string $name null;
  20.     #[ORM\Column(length255nullabletrue)]
  21.     private ?string $email null;
  22.     #[ORM\Column(typeTypes::TEXT)]
  23.     private ?string $content null;
  24.     #[ORM\ManyToOne(inversedBy'comments')]
  25.     #[ORM\JoinColumn(nullablefalse)]
  26.     private ?Blog $blog null;
  27.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'replies')]
  28.     private ?self $parent null;
  29.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class, orphanRemovaltrue)]
  30.     private Collection $replies;
  31.     public function __construct()
  32.     {
  33.         $this->replies = new ArrayCollection();
  34.     }
  35.     public function getId(): ?int
  36.     {
  37.         return $this->id;
  38.     }
  39.     public function getName(): ?string
  40.     {
  41.         return $this->name;
  42.     }
  43.     public function setName(string $name): static
  44.     {
  45.         $this->name $name;
  46.         return $this;
  47.     }
  48.     public function getEmail(): ?string
  49.     {
  50.         return $this->email;
  51.     }
  52.     public function setEmail(?string $email): static
  53.     {
  54.         $this->email $email;
  55.         return $this;
  56.     }
  57.     public function getContent(): ?string
  58.     {
  59.         return $this->content;
  60.     }
  61.     public function setContent(string $content): static
  62.     {
  63.         $this->content $content;
  64.         return $this;
  65.     }
  66.     public function getBlog(): ?Blog
  67.     {
  68.         return $this->blog;
  69.     }
  70.     public function setBlog(?Blog $blog): static
  71.     {
  72.         $this->blog $blog;
  73.         return $this;
  74.     }
  75.     public function getParent(): ?self
  76.     {
  77.         return $this->parent;
  78.     }
  79.     public function setParent(?self $parent): static
  80.     {
  81.         $this->parent $parent;
  82.         return $this;
  83.     }
  84.     /**
  85.      * @return Collection<int, self>
  86.      */
  87.     public function getReplies(): Collection
  88.     {
  89.         return $this->replies;
  90.     }
  91.     public function addReply(self $reply): static
  92.     {
  93.         if (!$this->replies->contains($reply)) {
  94.             $this->replies->add($reply);
  95.             $reply->setParent($this);
  96.         }
  97.         return $this;
  98.     }
  99.     public function removeReply(self $reply): static
  100.     {
  101.         if ($this->replies->removeElement($reply)) {
  102.             // set the owning side to null (unless already changed)
  103.             if ($reply->getParent() === $this) {
  104.                 $reply->setParent(null);
  105.             }
  106.         }
  107.         return $this;
  108.     }
  109. }