src/Entity/Post.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Translation\AutoTranslatableTrait;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  8. #[ORM\Table(name'post')]
  9. #[ORM\Index(name'ix_image_url'columns: ['image_url'])]
  10. #[ORM\Index(name'ix_category'columns: ['category'])]
  11. #[ORM\Entity(repositoryClass'App\Entity\Repository\PostRepository')]
  12. class Post implements TranslatableInterface
  13. {
  14.     use AutoTranslatableTrait;
  15.     #[ORM\Id]
  16.     #[ORM\Column(type'integer')]
  17.     #[ORM\GeneratedValue(strategy'AUTO')]
  18.     private $id;
  19.     #[ORM\Column(type'text'length0nullablefalse)]
  20.     private $text;
  21.     #[ORM\Column(type'string'nullabletrue)]
  22.     private $image_url;
  23.     #[ORM\Column(type'json'nullabletrue)]
  24.     private $tags;
  25.     #[ORM\Column(type'datetime'nullablefalse)]
  26.     private $date_created;
  27.     #[ORM\OneToMany(targetEntity'App\Entity\PostComment'mappedBy'post')]
  28.     private $postComment;
  29.     #[ORM\OneToMany(targetEntity'App\Entity\PostBookmark'mappedBy'post')]
  30.     private $postBookmark;
  31.     #[ORM\ManyToOne(targetEntity'App\Entity\User'inversedBy'post')]
  32.     #[ORM\JoinColumn(name'user_id'referencedColumnName'id'nullablefalse)]
  33.     private $user;
  34.     #[ORM\OneToMany(targetEntityPostLike::class, mappedBy'post'orphanRemovaltrue)]
  35.     private $postLikes;
  36.     #[ORM\Column(type'json'nullabletrue)]
  37.     private $richtext = [];
  38.     #[ORM\Column(type'string'length255)]
  39.     private $category;
  40.     #[ORM\Column(type'array'nullabletrue)]
  41.     private $imageUrls = [];
  42.     #[ORM\Column(type'string'length50nullabletrue)]
  43.     private $type;
  44.     #[ORM\OneToOne(targetEntityContent::class, mappedBy'post'cascade: ['persist''remove'])]
  45.     private $content;
  46.     #[ORM\Column(type'string'length255nullabletrue)]
  47.     private $dynamic_link;
  48.     #[ORM\OneToMany(targetEntityPostTag::class, mappedBy'post'orphanRemovaltrue)]
  49.     private $postTags;
  50.     #[ORM\Column(length3nullabletrue)]
  51.     private ?string $language null;
  52.     #[ORM\Column(nullabletrue)]
  53.     private ?array $metadata = [];
  54.     #[ORM\OneToMany(mappedBy'post'targetEntityPostReport::class, orphanRemovaltrue)]
  55.     private Collection $postReports;
  56.     #[ORM\Column(nullabletrue)]
  57.     private ?bool $hidden null;
  58.     #[ORM\Column(type'string'length255nullabletrue)]
  59.     private $location;
  60.     #[ORM\Column(nullabletrue)]
  61.     private ?array $ai_moderation_result null;
  62.     public function __construct()
  63.     {
  64.         $this->postComment = new ArrayCollection();
  65.         $this->postBookmark = new ArrayCollection();
  66.         $this->postLikes = new ArrayCollection();
  67.         $this->date_created = new \DateTime();
  68.         $this->category 'default';
  69.         $this->postTags = new ArrayCollection();
  70.         $this->postReports = new ArrayCollection();
  71.     }
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     public function getText(): ?string
  77.     {
  78.         if ($this->shouldNotBeTranslated()) {
  79.             return $this->text;
  80.         }
  81.         $translated $this->translate()->getText();
  82.         return !empty($translated) ? $translated $this->text;
  83.     }
  84.     public function setText(string $text): self
  85.     {
  86.         $this->text $text;
  87.         return $this;
  88.     }
  89.     public function getImageUrl(): ?string
  90.     {
  91.         return $this->image_url;
  92.     }
  93.     public function setImageUrl(?string $image_url): self
  94.     {
  95.         $this->image_url $image_url;
  96.         return $this;
  97.     }
  98.     public function getDateCreated(): ?\DateTimeInterface
  99.     {
  100.         return $this->date_created;
  101.     }
  102.     public function setDateCreated(\DateTimeInterface $date_created): self
  103.     {
  104.         $this->date_created $date_created;
  105.         return $this;
  106.     }
  107.     /**
  108.      * @return Collection|PostComment[]
  109.      */
  110.     public function getPostComment(): Collection
  111.     {
  112.         return $this->postComment;
  113.     }
  114.     public function addPostComment(PostComment $postComment): self
  115.     {
  116.         if (!$this->postComment->contains($postComment)) {
  117.             $this->postComment[] = $postComment;
  118.             $postComment->setPost($this);
  119.         }
  120.         return $this;
  121.     }
  122.     public function removePostComment(PostComment $postComment): self
  123.     {
  124.         if ($this->postComment->contains($postComment)) {
  125.             $this->postComment->removeElement($postComment);
  126.             // set the owning side to null (unless already changed)
  127.             if ($postComment->getPost() === $this) {
  128.                 $postComment->setPost(null);
  129.             }
  130.         }
  131.         return $this;
  132.     }
  133.     public function getUser(): ?User
  134.     {
  135.         return $this->user;
  136.     }
  137.     public function setUser(?User $user): self
  138.     {
  139.         $this->user $user;
  140.         return $this;
  141.     }
  142.     /**
  143.      * @return Collection|PostBookmark[]
  144.      */
  145.     public function getPostBookmark(): Collection
  146.     {
  147.         return $this->postBookmark;
  148.     }
  149.     public function addPostBookmark(PostBookmark $postBookmark): self
  150.     {
  151.         if (!$this->postBookmark->contains($postBookmark)) {
  152.             $this->postBookmark[] = $postBookmark;
  153.             $postBookmark->setPost($this);
  154.         }
  155.         return $this;
  156.     }
  157.     public function removePostBookmark(PostBookmark $postBookmark): self
  158.     {
  159.         if ($this->postBookmark->contains($postBookmark)) {
  160.             $this->postBookmark->removeElement($postBookmark);
  161.             // set the owning side to null (unless already changed)
  162.             if ($postBookmark->getPost() === $this) {
  163.                 $postBookmark->setPost(null);
  164.             }
  165.         }
  166.         return $this;
  167.     }
  168.     public function getTags(): ?array
  169.     {
  170.         return $this->tags;
  171.     }
  172.     public function setTags(?array $tags): self
  173.     {
  174.         $this->tags $tags;
  175.         return $this;
  176.     }
  177.     /**
  178.      * @return Collection|PostLike[]
  179.      */
  180.     public function getPostLikes(): Collection
  181.     {
  182.         return $this->postLikes;
  183.     }
  184.     public function addPostLike(PostLike $postLike): self
  185.     {
  186.         if (!$this->postLikes->contains($postLike)) {
  187.             $this->postLikes[] = $postLike;
  188.             $postLike->setPost($this);
  189.         }
  190.         return $this;
  191.     }
  192.     public function removePostLike(PostLike $postLike): self
  193.     {
  194.         if ($this->postLikes->removeElement($postLike)) {
  195.             // set the owning side to null (unless already changed)
  196.             if ($postLike->getPost() === $this) {
  197.                 $postLike->setPost(null);
  198.             }
  199.         }
  200.         return $this;
  201.     }
  202.     public function getRichtext(bool $skipTranslation false): ?array
  203.     {
  204.         if ($skipTranslation || $this->shouldNotBeTranslated()) {
  205.             return $this->richtext;
  206.         }
  207.         $translated $this->translate()->getRichtext();
  208.         return !empty($translated) ? $translated $this->richtext;
  209.     }
  210.     public function setRichtext(?array $richtext): self
  211.     {
  212.         $this->richtext $richtext;
  213.         return $this;
  214.     }
  215.     public function getCategory(): ?string
  216.     {
  217.         return $this->category;
  218.     }
  219.     public function setCategory(string $category): self
  220.     {
  221.         $this->category $category;
  222.         return $this;
  223.     }
  224.     public function getImageUrls(): ?array
  225.     {
  226.         return $this->imageUrls;
  227.     }
  228.     public function setImageUrls(?array $imageUrls): self
  229.     {
  230.         $this->imageUrls $imageUrls;
  231.         return $this;
  232.     }
  233.     public function getType(): ?string
  234.     {
  235.         return $this->type;
  236.     }
  237.     public function setType(?string $type): self
  238.     {
  239.         $this->type $type;
  240.         return $this;
  241.     }
  242.     public function getContent(): ?Content
  243.     {
  244.         return $this->content;
  245.     }
  246.     public function setContent(?Content $content): self
  247.     {
  248.         // unset the owning side of the relation if necessary
  249.         if ($content === null && $this->content !== null) {
  250.             $this->content->setPost(null);
  251.         }
  252.         // set the owning side of the relation if necessary
  253.         if ($content !== null && $content->getPost() !== $this) {
  254.             $content->setPost($this);
  255.         }
  256.         $this->content $content;
  257.         return $this;
  258.     }
  259.     /**
  260.      * Gets the engagement as single number: comments + likes + comment likes
  261.      *
  262.      * @return int
  263.      */
  264.     public function getEngagement(): int
  265.     {
  266.         $score $this->getPostComment()->count() + $this->getPostLikes()->count();
  267.         foreach ($this->getPostComment() as $comment) {
  268.             $score += $comment->getCommentLikes()->count();
  269.         }
  270.         return $score;
  271.     }
  272.     public function getDynamicLink(): ?string
  273.     {
  274.         return $this->dynamic_link;
  275.     }
  276.     public function setDynamicLink(?string $dynamic_link): self
  277.     {
  278.         $this->dynamic_link $dynamic_link;
  279.         return $this;
  280.     }
  281.     /**
  282.      * @return Collection<int, PostTag>
  283.      */
  284.     public function getPostTags(): Collection
  285.     {
  286.         return $this->postTags;
  287.     }
  288.     public function addPostTag(PostTag $postTag): self
  289.     {
  290.         if (!$this->postTags->contains($postTag)) {
  291.             $this->postTags[] = $postTag;
  292.             $postTag->setPost($this);
  293.         }
  294.         return $this;
  295.     }
  296.     public function removePostTag(PostTag $postTag): self
  297.     {
  298.         if ($this->postTags->removeElement($postTag)) {
  299.             // set the owning side to null (unless already changed)
  300.             if ($postTag->getPost() === $this) {
  301.                 $postTag->setPost(null);
  302.             }
  303.         }
  304.         return $this;
  305.     }
  306.     public function getLanguage(): ?string
  307.     {
  308.         return $this->language;
  309.     }
  310.     public function setLanguage(?string $language): static
  311.     {
  312.         $this->language $language;
  313.         return $this;
  314.     }
  315.     public function getMetadata(): ?array
  316.     {
  317.         return $this->metadata;
  318.     }
  319.     public function setMetadata(?array $metadata): static
  320.     {
  321.         $this->metadata $metadata;
  322.         return $this;
  323.     }
  324.     /**
  325.      * @return Collection<int, PostReport>
  326.      */
  327.     public function getPostReports(): Collection
  328.     {
  329.         return $this->postReports;
  330.     }
  331.     public function addPostReport(PostReport $postReport): static
  332.     {
  333.         if (!$this->postReports->contains($postReport)) {
  334.             $this->postReports->add($postReport);
  335.             $postReport->setPost($this);
  336.         }
  337.         return $this;
  338.     }
  339.     public function removePostReport(PostReport $postReport): static
  340.     {
  341.         if ($this->postReports->removeElement($postReport)) {
  342.             // set the owning side to null (unless already changed)
  343.             if ($postReport->getPost() === $this) {
  344.                 $postReport->setPost(null);
  345.             }
  346.         }
  347.         return $this;
  348.     }
  349.     public function isHidden(): ?bool
  350.     {
  351.         return $this->hidden;
  352.     }
  353.     public function setHidden(?bool $hidden): static
  354.     {
  355.         $this->hidden $hidden;
  356.         return $this;
  357.     }
  358.     public function getLocation(): ?string
  359.     {
  360.         return $this->location;
  361.     }
  362.     public function setLocation(?string $location): static
  363.     {
  364.         $this->location $location;
  365.         return $this;
  366.     }
  367.     public function getAiModerationResult(): ?array
  368.     {
  369.         return $this->ai_moderation_result;
  370.     }
  371.     public function setAiModerationResult(?array $ai_moderation_result): static
  372.     {
  373.         $this->ai_moderation_result $ai_moderation_result;
  374.         return $this;
  375.     }
  376. }