src/Entity/Comment.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimeStampableTrait;
  4. use App\Repository\CommentRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. #[ORM\Entity(repositoryClass: CommentRepository::class)]
  11. class Comment
  12. {
  13.     use TimeStampableTrait;
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     #[Groups(['activity:read','task:read'])]
  18.     private ?int $id = null;
  19.     #[ORM\ManyToOne(inversedBy: 'comments')]
  20.     #[Groups(['activity:read', 'task:read'])]
  21.     private ?User $author = null;
  22.     #[ORM\Column(type: Types::TEXT)]
  23.     #[Groups(['activity:read', 'task:read'])]
  24.     private ?string $comment = null;
  25.     #[ORM\ManyToOne(inversedBy: 'comments')]
  26.     private ?Task $task = null;
  27.     #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'parent')]
  28.     private ?self $comments = null;
  29.     #[ORM\OneToMany(mappedBy: 'comments', targetEntity: self::class)]
  30.     private Collection $parent;
  31.     #[ORM\ManyToOne(inversedBy: 'comment')]
  32.     private ?RateOfProgress $rateOfProgress = null;
  33.     #[ORM\ManyToOne(inversedBy: 'comments')]
  34.     private ?Activity $activity = null;
  35.     public function __construct()
  36.     {
  37.         $this->createdAt = new \DateTimeImmutable();
  38.         $this->parent = new ArrayCollection();
  39.     }
  40.     public function getId(): ?int
  41.     {
  42.         return $this->id;
  43.     }
  44.     public function getAuthor(): ?User
  45.     {
  46.         return $this->author;
  47.     }
  48.     public function setAuthor(?User $author): static
  49.     {
  50.         $this->author = $author;
  51.         return $this;
  52.     }
  53.     public function getComment(): ?string
  54.     {
  55.         return $this->comment;
  56.     }
  57.     public function setComment(string $comment): static
  58.     {
  59.         $this->comment = $comment;
  60.         return $this;
  61.     }
  62.     
  63.     public function getTask(): ?Task
  64.     {
  65.         return $this->task;
  66.     }
  67.     public function setTask(?Task $task): static
  68.     {
  69.         $this->task = $task;
  70.         return $this;
  71.     }
  72.     public function getComments(): ?self
  73.     {
  74.         return $this->comments;
  75.     }
  76.     public function setComments(?self $comments): static
  77.     {
  78.         $this->comments = $comments;
  79.         return $this;
  80.     }
  81.     /**
  82.      * @return Collection<int, self>
  83.      */
  84.     public function getParent(): Collection
  85.     {
  86.         return $this->parent;
  87.     }
  88.     public function addParent(self $parent): static
  89.     {
  90.         if (!$this->parent->contains($parent)) {
  91.             $this->parent->add($parent);
  92.             $parent->setComments($this);
  93.         }
  94.         return $this;
  95.     }
  96.     public function removeParent(self $parent): static
  97.     {
  98.         if ($this->parent->removeElement($parent)) {
  99.             // set the owning side to null (unless already changed)
  100.             if ($parent->getComments() === $this) {
  101.                 $parent->setComments(null);
  102.             }
  103.         }
  104.         return $this;
  105.     }
  106.     public function getRateOfProgress(): ?RateOfProgress
  107.     {
  108.         return $this->rateOfProgress;
  109.     }
  110.     public function setRateOfProgress(?RateOfProgress $rateOfProgress): static
  111.     {
  112.         $this->rateOfProgress = $rateOfProgress;
  113.         return $this;
  114.     }
  115.     public function getActivity(): ?Activity
  116.     {
  117.         return $this->activity;
  118.     }
  119.     public function setActivity(?Activity $activity): static
  120.     {
  121.         $this->activity = $activity;
  122.         return $this;
  123.     }
  124.     #[Groups(['activity:read'])]
  125.     public function getUser() {
  126.         return $this->author? $this->author->getFirstname()." ".$this->author->getLastname() : '';
  127.     }
  128. }