<?php
namespace App\Entity;
use App\Translation\AutoTranslatableTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
#[ORM\Table(name: 'post_comment')]
#[ORM\Entity(repositoryClass: 'App\Entity\Repository\PostCommentRepository')]
class PostComment implements TranslatableInterface
{
use AutoTranslatableTrait;
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;
#[ORM\Column(type: 'text', length: 0, nullable: false)]
private $text;
#[ORM\Column(type: 'json', nullable: true)]
private $tags;
#[ORM\Column(type: 'datetime', nullable: false)]
private $date_created;
#[ORM\OneToMany(targetEntity: 'App\Entity\PostComment', mappedBy: 'parentPostComment')]
private $childPostComment;
#[ORM\ManyToOne(targetEntity: 'App\Entity\Post', inversedBy: 'postComment')]
#[ORM\JoinColumn(name: 'post_id', referencedColumnName: 'id', nullable: false)]
private $post;
#[ORM\ManyToOne(targetEntity: 'App\Entity\PostComment', inversedBy: 'childPostComment')]
#[ORM\JoinColumn(name: 'post_comment_id', referencedColumnName: 'id')]
private $parentPostComment;
#[ORM\ManyToOne(targetEntity: 'App\Entity\User', inversedBy: 'postComment')]
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: false)]
private $user;
#[ORM\OneToMany(targetEntity: CommentLike::class, mappedBy: 'comment', orphanRemoval: true)]
private $commentLikes;
#[ORM\Column(type: 'json', nullable: true)]
private $richtext = [];
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $imageUrl;
#[ORM\OneToMany(targetEntity: CommentTag::class, mappedBy: 'comment', orphanRemoval: true)]
private $commentTags;
#[ORM\Column(length: 3, nullable: true)]
private ?string $language = null;
#[ORM\Column(nullable: true)]
private ?array $ai_moderation_result = null;
#[ORM\Column(nullable: true)]
private ?bool $hidden = null;
#[ORM\OneToMany(mappedBy: 'post_comment', targetEntity: PostCommentReport::class, orphanRemoval: true)]
private Collection $postCommentReports;
public function __toString(): string
{
return 'comment_' . $this->getText();
}
public function __construct()
{
$this->childPostComment = new ArrayCollection();
$this->commentLikes = new ArrayCollection();
$this->date_created = new \DateTime();
$this->commentTags = new ArrayCollection();
$this->postCommentReports = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getText(): ?string
{
return $this->text;
}
public function setText(string $text): self
{
$this->text = $text;
return $this;
}
public function getDateCreated(): ?\DateTimeInterface
{
return $this->date_created;
}
public function setDateCreated(\DateTimeInterface $date_created): self
{
$this->date_created = $date_created;
return $this;
}
/**
* @return Collection|PostComment[]
*/
public function getChildPostComment(): Collection
{
return $this->childPostComment;
}
public function addChildPostComment(PostComment $childPostComment): self
{
if (!$this->childPostComment->contains($childPostComment)) {
$this->childPostComment[] = $childPostComment;
$childPostComment->setParentPostComment($this);
}
return $this;
}
public function removeChildPostComment(PostComment $childPostComment): self
{
if ($this->childPostComment->contains($childPostComment)) {
$this->childPostComment->removeElement($childPostComment);
// set the owning side to null (unless already changed)
if ($childPostComment->getParentPostComment() === $this) {
$childPostComment->setParentPostComment(null);
}
}
return $this;
}
public function getPost(): ?Post
{
return $this->post;
}
public function setPost(?Post $post): self
{
$this->post = $post;
return $this;
}
public function getParentPostComment(): ?self
{
return $this->parentPostComment;
}
public function setParentPostComment(?self $parentPostComment): self
{
$this->parentPostComment = $parentPostComment;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getTags(): ?array
{
return $this->tags;
}
public function setTags(?array $tags): self
{
$this->tags = $tags;
return $this;
}
/**
* @return Collection|CommentLike[]
*/
public function getCommentLikes(): Collection
{
return $this->commentLikes;
}
public function addCommentLike(CommentLike $commentLike): self
{
if (!$this->commentLikes->contains($commentLike)) {
$this->commentLikes[] = $commentLike;
$commentLike->setComment($this);
}
return $this;
}
public function removeCommentLike(CommentLike $commentLike): self
{
if ($this->commentLikes->removeElement($commentLike)) {
// set the owning side to null (unless already changed)
if ($commentLike->getComment() === $this) {
$commentLike->setComment(null);
}
}
return $this;
}
public function getRichtext(bool $skipTranslation = false): ?array
{
if ($skipTranslation || $this->shouldNotBeTranslated()) {
return $this->richtext;
}
$translated = $this->translate()->getRichtext();
return !empty($translated) ? $translated : $this->richtext;
}
public function setRichtext(?array $richtext): self
{
$this->richtext = $richtext;
return $this;
}
public function getImageUrl(): ?string
{
return $this->imageUrl;
}
public function setImageUrl(?string $imageUrl): self
{
$this->imageUrl = $imageUrl;
return $this;
}
/**
* @return Collection<int, CommentTag>
*/
public function getCommentTags(): Collection
{
return $this->commentTags;
}
public function addCommentTag(CommentTag $commentTag): self
{
if (!$this->commentTags->contains($commentTag)) {
$this->commentTags[] = $commentTag;
$commentTag->setComment($this);
}
return $this;
}
public function removeCommentTag(CommentTag $commentTag): self
{
if ($this->commentTags->removeElement($commentTag)) {
// set the owning side to null (unless already changed)
if ($commentTag->getComment() === $this) {
$commentTag->setComment(null);
}
}
return $this;
}
public function getLanguage(): ?string
{
return $this->language;
}
public function setLanguage(?string $language): static
{
$this->language = $language;
return $this;
}
public function getAiModerationResult(): ?array
{
return $this->ai_moderation_result;
}
public function setAiModerationResult(?array $ai_moderation_result): static
{
$this->ai_moderation_result = $ai_moderation_result;
return $this;
}
public function isHidden(): ?bool
{
return $this->hidden;
}
public function setHidden(?bool $hidden): static
{
$this->hidden = $hidden;
return $this;
}
/**
* @return Collection<int, PostCommentReport>
*/
public function getPostCommentReports(): Collection
{
return $this->postCommentReports;
}
public function addPostCommentReport(PostCommentReport $postCommentReport): static
{
if (!$this->postCommentReports->contains($postCommentReport)) {
$this->postCommentReports->add($postCommentReport);
$postCommentReport->setPostComment($this);
}
return $this;
}
public function removePostCommentReport(PostCommentReport $postCommentReport): static
{
if ($this->postCommentReports->removeElement($postCommentReport)) {
// set the owning side to null (unless already changed)
if ($postCommentReport->getPostComment() === $this) {
$postCommentReport->setPostComment(null);
}
}
return $this;
}
}