<?phpnamespace App\Entity;use App\Entity\Traits\TimeStampableTrait;use App\Repository\CommentRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Serializer\Annotation\Groups;#[ORM\Entity(repositoryClass: CommentRepository::class)]class Comment{ use TimeStampableTrait; #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] #[Groups(['activity:read','task:read'])] private ?int $id = null; #[ORM\ManyToOne(inversedBy: 'comments')] #[Groups(['activity:read', 'task:read'])] private ?User $author = null; #[ORM\Column(type: Types::TEXT)] #[Groups(['activity:read', 'task:read'])] private ?string $comment = null; #[ORM\ManyToOne(inversedBy: 'comments')] private ?Task $task = null; #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'parent')] private ?self $comments = null; #[ORM\OneToMany(mappedBy: 'comments', targetEntity: self::class)] private Collection $parent; #[ORM\ManyToOne(inversedBy: 'comment')] private ?RateOfProgress $rateOfProgress = null; #[ORM\ManyToOne(inversedBy: 'comments')] private ?Activity $activity = null; public function __construct() { $this->createdAt = new \DateTimeImmutable(); $this->parent = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getAuthor(): ?User { return $this->author; } public function setAuthor(?User $author): static { $this->author = $author; return $this; } public function getComment(): ?string { return $this->comment; } public function setComment(string $comment): static { $this->comment = $comment; return $this; } public function getTask(): ?Task { return $this->task; } public function setTask(?Task $task): static { $this->task = $task; return $this; } public function getComments(): ?self { return $this->comments; } public function setComments(?self $comments): static { $this->comments = $comments; return $this; } /** * @return Collection<int, self> */ public function getParent(): Collection { return $this->parent; } public function addParent(self $parent): static { if (!$this->parent->contains($parent)) { $this->parent->add($parent); $parent->setComments($this); } return $this; } public function removeParent(self $parent): static { if ($this->parent->removeElement($parent)) { // set the owning side to null (unless already changed) if ($parent->getComments() === $this) { $parent->setComments(null); } } return $this; } public function getRateOfProgress(): ?RateOfProgress { return $this->rateOfProgress; } public function setRateOfProgress(?RateOfProgress $rateOfProgress): static { $this->rateOfProgress = $rateOfProgress; return $this; } public function getActivity(): ?Activity { return $this->activity; } public function setActivity(?Activity $activity): static { $this->activity = $activity; return $this; } #[Groups(['activity:read'])] public function getUser() { return $this->author? $this->author->getFirstname()." ".$this->author->getLastname() : ''; }}