comments = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getAuthor(): ?string { return $this->author; } public function setAuthor(string $author): self { $this->author = $author; return $this; } public function getWebsite(): ?string { return $this->website; } public function setWebsite(?string $website): self { $this->website = $website; return $this; } public function getEmail(): ?string { return $this->email; } public function setEmail(?string $email): self { $this->email = $email; return $this; } public function getContent(): ?string { return $this->content; } public function setContent(?string $content): self { $this->content = $content; return $this; } public function getIsActive(): ?bool { return $this->isActive; } public function setIsActive(bool $isActive): self { $this->isActive = $isActive; return $this; } public function getPost(): ?Post { return $this->post; } public function setPost(?Post $post): self { $this->post = $post; return $this; } public function getParentComment(): ?self { return $this->parentComment; } public function setParentComment(?self $parentComment): self { $this->parentComment = $parentComment; return $this; } /** * @return Collection|Comment[] */ public function getComments(array $criteria = []): Collection { $collection = new ArrayCollection(); foreach ($this->comments as $comment) { if (isset($criteria['isActive']) && $comment->getIsActive() !== $criteria['isActive']) { continue; } $collection->add($comment); } return $collection; } public function addComment(self $comment): self { if (!$this->comments->contains($comment)) { $this->comments[] = $comment; $comment->setParentComment($this); } return $this; } public function removeComment(self $comment): self { if ($this->comments->removeElement($comment)) { // set the owning side to null (unless already changed) if ($comment->getParentComment() === $this) { $comment->setParentComment(null); } } return $this; } /** * Get the avatar URL using gravatar. */ public function getAvatar(): string { return 'https://secure.gravatar.com/avatar/'.md5($this->getEmail() ?? 'undefined@undefined').'.jpg?s=90&d=retro'; } /** * {@inheritdoc} */ public function __toString() { return sprintf( '[%s] (%s) %s', $this->getAuthor(), $this->getCreatedAt()->format('d/m/Y'), substr($this->getContent(), 0, 20).'…' ); } }