src/Entity/Article.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ArticleRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. /**
  9.  * @ORM\Entity(repositoryClass=ArticleRepository::class)
  10.  * @ORM\HasLifecycleCallbacks()
  11.  */
  12. class Article
  13. {
  14.     const STATUS_DRAFT 'draft';
  15.     const STATUS_PENDING 'pending';
  16.     const STATUS_PUBLISHED 'published';
  17.     const STATUS_REJECTED 'rejected';
  18.     const STATUS_ARCHIVED 'archived';
  19.     /**
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="string", length=500)
  27.      */
  28.     private $title;
  29.     /**
  30.      * @ORM\Column(type="string", length=191, unique=true)
  31.      * @Gedmo\Slug(fields={"title"})
  32.      */
  33.     private $slug;
  34.     /**
  35.      * @ORM\Column(type="string", length=1000, nullable=true)
  36.      */
  37.     private $subtitle;
  38.     /**
  39.      * @ORM\Column(type="text")
  40.      */
  41.     private $excerpt;
  42.     /**
  43.      * @ORM\Column(type="text")
  44.      */
  45.     private $body;
  46.     /**
  47.      * @ORM\ManyToOne(targetEntity=Category::class, inversedBy="articles")
  48.      * @ORM\JoinColumn(nullable=false)
  49.      */
  50.     private $category;
  51.     /**
  52.      * @ORM\Column(type="string", length=50)
  53.      */
  54.     private $status self::STATUS_DRAFT;
  55.     /**
  56.      * @ORM\Column(type="string", length=500, nullable=true)
  57.      */
  58.     private $sourceTopic;
  59.     /**
  60.      * @ORM\Column(type="float", nullable=true)
  61.      */
  62.     private $satireScore;
  63.     /**
  64.      * @ORM\Column(type="float", nullable=true)
  65.      */
  66.     private $riskScore;
  67.     /**
  68.      * @ORM\ManyToOne(targetEntity=MediaAsset::class)
  69.      * @ORM\JoinColumn(nullable=true)
  70.      */
  71.     private $featuredImage;
  72.     /**
  73.      * @ORM\Column(type="boolean")
  74.      */
  75.     private $isAiGenerated false;
  76.     /**
  77.      * @ORM\Column(type="boolean")
  78.      */
  79.     private $isFeatured false;
  80.     /**
  81.      * @ORM\Column(type="integer")
  82.      */
  83.     private $viewCount 0;
  84.     /**
  85.      * @ORM\Column(type="string", length=255, nullable=true)
  86.      */
  87.     private $author;
  88.     /**
  89.      * @ORM\Column(type="datetime", nullable=true)
  90.      */
  91.     private $publishedAt;
  92.     /**
  93.      * @ORM\Column(type="datetime")
  94.      * @Gedmo\Timestampable(on="create")
  95.      */
  96.     private $createdAt;
  97.     /**
  98.      * @ORM\Column(type="datetime")
  99.      * @Gedmo\Timestampable(on="update")
  100.      */
  101.     private $updatedAt;
  102.     /**
  103.      * @ORM\ManyToMany(targetEntity=Tag::class, inversedBy="articles")
  104.      */
  105.     private $tags;
  106.     /**
  107.      * @ORM\OneToMany(targetEntity=SocialPost::class, mappedBy="article", cascade={"remove"})
  108.      */
  109.     private $socialPosts;
  110.     /**
  111.      * @ORM\Column(type="json", nullable=true)
  112.      */
  113.     private $metadata = [];
  114.     /**
  115.      * @ORM\Column(type="text", nullable=true)
  116.      */
  117.     private $aiPrompt;
  118.     /**
  119.      * @ORM\Column(type="text", nullable=true)
  120.      */
  121.     private $aiResponse;
  122.     public function __construct()
  123.     {
  124.         $this->tags = new ArrayCollection();
  125.         $this->socialPosts = new ArrayCollection();
  126.     }
  127.     public function getId(): ?int
  128.     {
  129.         return $this->id;
  130.     }
  131.     public function getTitle(): ?string
  132.     {
  133.         return $this->title;
  134.     }
  135.     public function setTitle(string $title): self
  136.     {
  137.         $this->title $title;
  138.         return $this;
  139.     }
  140.     public function getSlug(): ?string
  141.     {
  142.         return $this->slug;
  143.     }
  144.     public function setSlug(string $slug): self
  145.     {
  146.         $this->slug $slug;
  147.         return $this;
  148.     }
  149.     public function getSubtitle(): ?string
  150.     {
  151.         return $this->subtitle;
  152.     }
  153.     public function setSubtitle(?string $subtitle): self
  154.     {
  155.         $this->subtitle $subtitle;
  156.         return $this;
  157.     }
  158.     public function getExcerpt(): ?string
  159.     {
  160.         return $this->excerpt;
  161.     }
  162.     public function setExcerpt(string $excerpt): self
  163.     {
  164.         $this->excerpt $excerpt;
  165.         return $this;
  166.     }
  167.     public function getBody(): ?string
  168.     {
  169.         return $this->body;
  170.     }
  171.     public function setBody(string $body): self
  172.     {
  173.         $this->body $body;
  174.         return $this;
  175.     }
  176.     public function getCategory(): ?Category
  177.     {
  178.         return $this->category;
  179.     }
  180.     public function setCategory(?Category $category): self
  181.     {
  182.         $this->category $category;
  183.         return $this;
  184.     }
  185.     public function getStatus(): ?string
  186.     {
  187.         return $this->status;
  188.     }
  189.     public function setStatus(string $status): self
  190.     {
  191.         $this->status $status;
  192.         return $this;
  193.     }
  194.     public function getSourceTopic(): ?string
  195.     {
  196.         return $this->sourceTopic;
  197.     }
  198.     public function setSourceTopic(?string $sourceTopic): self
  199.     {
  200.         $this->sourceTopic $sourceTopic;
  201.         return $this;
  202.     }
  203.     public function getSatireScore(): ?float
  204.     {
  205.         return $this->satireScore;
  206.     }
  207.     public function setSatireScore(?float $satireScore): self
  208.     {
  209.         $this->satireScore $satireScore;
  210.         return $this;
  211.     }
  212.     public function getRiskScore(): ?float
  213.     {
  214.         return $this->riskScore;
  215.     }
  216.     public function setRiskScore(?float $riskScore): self
  217.     {
  218.         $this->riskScore $riskScore;
  219.         return $this;
  220.     }
  221.     public function getFeaturedImage(): ?MediaAsset
  222.     {
  223.         return $this->featuredImage;
  224.     }
  225.     public function setFeaturedImage(?MediaAsset $featuredImage): self
  226.     {
  227.         $this->featuredImage $featuredImage;
  228.         return $this;
  229.     }
  230.     public function getIsAiGenerated(): ?bool
  231.     {
  232.         return $this->isAiGenerated;
  233.     }
  234.     public function setIsAiGenerated(bool $isAiGenerated): self
  235.     {
  236.         $this->isAiGenerated $isAiGenerated;
  237.         return $this;
  238.     }
  239.     public function getIsFeatured(): ?bool
  240.     {
  241.         return $this->isFeatured;
  242.     }
  243.     public function setIsFeatured(bool $isFeatured): self
  244.     {
  245.         $this->isFeatured $isFeatured;
  246.         return $this;
  247.     }
  248.     public function getViewCount(): ?int
  249.     {
  250.         return $this->viewCount;
  251.     }
  252.     public function setViewCount(int $viewCount): self
  253.     {
  254.         $this->viewCount $viewCount;
  255.         return $this;
  256.     }
  257.     public function incrementViewCount(): self
  258.     {
  259.         $this->viewCount++;
  260.         return $this;
  261.     }
  262.     public function getAuthor(): ?string
  263.     {
  264.         return $this->author;
  265.     }
  266.     public function setAuthor(?string $author): self
  267.     {
  268.         $this->author $author;
  269.         return $this;
  270.     }
  271.     public function getPublishedAt(): ?\DateTimeInterface
  272.     {
  273.         return $this->publishedAt;
  274.     }
  275.     public function setPublishedAt(?\DateTimeInterface $publishedAt): self
  276.     {
  277.         $this->publishedAt $publishedAt;
  278.         return $this;
  279.     }
  280.     public function getCreatedAt(): ?\DateTimeInterface
  281.     {
  282.         return $this->createdAt;
  283.     }
  284.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  285.     {
  286.         $this->createdAt $createdAt;
  287.         return $this;
  288.     }
  289.     public function getUpdatedAt(): ?\DateTimeInterface
  290.     {
  291.         return $this->updatedAt;
  292.     }
  293.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  294.     {
  295.         $this->updatedAt $updatedAt;
  296.         return $this;
  297.     }
  298.     /**
  299.      * @return Collection|Tag[]
  300.      */
  301.     public function getTags(): Collection
  302.     {
  303.         return $this->tags;
  304.     }
  305.     public function addTag(Tag $tag): self
  306.     {
  307.         if (!$this->tags->contains($tag)) {
  308.             $this->tags[] = $tag;
  309.         }
  310.         return $this;
  311.     }
  312.     public function removeTag(Tag $tag): self
  313.     {
  314.         $this->tags->removeElement($tag);
  315.         return $this;
  316.     }
  317.     /**
  318.      * @return Collection|SocialPost[]
  319.      */
  320.     public function getSocialPosts(): Collection
  321.     {
  322.         return $this->socialPosts;
  323.     }
  324.     public function addSocialPost(SocialPost $socialPost): self
  325.     {
  326.         if (!$this->socialPosts->contains($socialPost)) {
  327.             $this->socialPosts[] = $socialPost;
  328.             $socialPost->setArticle($this);
  329.         }
  330.         return $this;
  331.     }
  332.     public function removeSocialPost(SocialPost $socialPost): self
  333.     {
  334.         if ($this->socialPosts->removeElement($socialPost)) {
  335.             if ($socialPost->getArticle() === $this) {
  336.                 $socialPost->setArticle(null);
  337.             }
  338.         }
  339.         return $this;
  340.     }
  341.     public function getMetadata(): ?array
  342.     {
  343.         return $this->metadata;
  344.     }
  345.     public function setMetadata(?array $metadata): self
  346.     {
  347.         $this->metadata $metadata;
  348.         return $this;
  349.     }
  350.     public function getAiPrompt(): ?string
  351.     {
  352.         return $this->aiPrompt;
  353.     }
  354.     public function setAiPrompt(?string $aiPrompt): self
  355.     {
  356.         $this->aiPrompt $aiPrompt;
  357.         return $this;
  358.     }
  359.     public function getAiResponse(): ?string
  360.     {
  361.         return $this->aiResponse;
  362.     }
  363.     public function setAiResponse(?string $aiResponse): self
  364.     {
  365.         $this->aiResponse $aiResponse;
  366.         return $this;
  367.     }
  368.     public function isPublished(): bool
  369.     {
  370.         return $this->status === self::STATUS_PUBLISHED;
  371.     }
  372.     public function publish(): self
  373.     {
  374.         $this->status self::STATUS_PUBLISHED;
  375.         $this->publishedAt = new \DateTime();
  376.         return $this;
  377.     }
  378.     public function __toString(): string
  379.     {
  380.         return $this->title ?? '';
  381.     }
  382. }