<?php
namespace App\Entity;
use App\Repository\ArticleRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=ArticleRepository::class)
* @ORM\HasLifecycleCallbacks()
*/
class Article
{
const STATUS_DRAFT = 'draft';
const STATUS_PENDING = 'pending';
const STATUS_PUBLISHED = 'published';
const STATUS_REJECTED = 'rejected';
const STATUS_ARCHIVED = 'archived';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=500)
*/
private $title;
/**
* @ORM\Column(type="string", length=191, unique=true)
* @Gedmo\Slug(fields={"title"})
*/
private $slug;
/**
* @ORM\Column(type="string", length=1000, nullable=true)
*/
private $subtitle;
/**
* @ORM\Column(type="text")
*/
private $excerpt;
/**
* @ORM\Column(type="text")
*/
private $body;
/**
* @ORM\ManyToOne(targetEntity=Category::class, inversedBy="articles")
* @ORM\JoinColumn(nullable=false)
*/
private $category;
/**
* @ORM\Column(type="string", length=50)
*/
private $status = self::STATUS_DRAFT;
/**
* @ORM\Column(type="string", length=500, nullable=true)
*/
private $sourceTopic;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $satireScore;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $riskScore;
/**
* @ORM\ManyToOne(targetEntity=MediaAsset::class)
* @ORM\JoinColumn(nullable=true)
*/
private $featuredImage;
/**
* @ORM\Column(type="boolean")
*/
private $isAiGenerated = false;
/**
* @ORM\Column(type="boolean")
*/
private $isFeatured = false;
/**
* @ORM\Column(type="integer")
*/
private $viewCount = 0;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $author;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $publishedAt;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="update")
*/
private $updatedAt;
/**
* @ORM\ManyToMany(targetEntity=Tag::class, inversedBy="articles")
*/
private $tags;
/**
* @ORM\OneToMany(targetEntity=SocialPost::class, mappedBy="article", cascade={"remove"})
*/
private $socialPosts;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $metadata = [];
/**
* @ORM\Column(type="text", nullable=true)
*/
private $aiPrompt;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $aiResponse;
public function __construct()
{
$this->tags = new ArrayCollection();
$this->socialPosts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getSubtitle(): ?string
{
return $this->subtitle;
}
public function setSubtitle(?string $subtitle): self
{
$this->subtitle = $subtitle;
return $this;
}
public function getExcerpt(): ?string
{
return $this->excerpt;
}
public function setExcerpt(string $excerpt): self
{
$this->excerpt = $excerpt;
return $this;
}
public function getBody(): ?string
{
return $this->body;
}
public function setBody(string $body): self
{
$this->body = $body;
return $this;
}
public function getCategory(): ?Category
{
return $this->category;
}
public function setCategory(?Category $category): self
{
$this->category = $category;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getSourceTopic(): ?string
{
return $this->sourceTopic;
}
public function setSourceTopic(?string $sourceTopic): self
{
$this->sourceTopic = $sourceTopic;
return $this;
}
public function getSatireScore(): ?float
{
return $this->satireScore;
}
public function setSatireScore(?float $satireScore): self
{
$this->satireScore = $satireScore;
return $this;
}
public function getRiskScore(): ?float
{
return $this->riskScore;
}
public function setRiskScore(?float $riskScore): self
{
$this->riskScore = $riskScore;
return $this;
}
public function getFeaturedImage(): ?MediaAsset
{
return $this->featuredImage;
}
public function setFeaturedImage(?MediaAsset $featuredImage): self
{
$this->featuredImage = $featuredImage;
return $this;
}
public function getIsAiGenerated(): ?bool
{
return $this->isAiGenerated;
}
public function setIsAiGenerated(bool $isAiGenerated): self
{
$this->isAiGenerated = $isAiGenerated;
return $this;
}
public function getIsFeatured(): ?bool
{
return $this->isFeatured;
}
public function setIsFeatured(bool $isFeatured): self
{
$this->isFeatured = $isFeatured;
return $this;
}
public function getViewCount(): ?int
{
return $this->viewCount;
}
public function setViewCount(int $viewCount): self
{
$this->viewCount = $viewCount;
return $this;
}
public function incrementViewCount(): self
{
$this->viewCount++;
return $this;
}
public function getAuthor(): ?string
{
return $this->author;
}
public function setAuthor(?string $author): self
{
$this->author = $author;
return $this;
}
public function getPublishedAt(): ?\DateTimeInterface
{
return $this->publishedAt;
}
public function setPublishedAt(?\DateTimeInterface $publishedAt): self
{
$this->publishedAt = $publishedAt;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection|Tag[]
*/
public function getTags(): Collection
{
return $this->tags;
}
public function addTag(Tag $tag): self
{
if (!$this->tags->contains($tag)) {
$this->tags[] = $tag;
}
return $this;
}
public function removeTag(Tag $tag): self
{
$this->tags->removeElement($tag);
return $this;
}
/**
* @return Collection|SocialPost[]
*/
public function getSocialPosts(): Collection
{
return $this->socialPosts;
}
public function addSocialPost(SocialPost $socialPost): self
{
if (!$this->socialPosts->contains($socialPost)) {
$this->socialPosts[] = $socialPost;
$socialPost->setArticle($this);
}
return $this;
}
public function removeSocialPost(SocialPost $socialPost): self
{
if ($this->socialPosts->removeElement($socialPost)) {
if ($socialPost->getArticle() === $this) {
$socialPost->setArticle(null);
}
}
return $this;
}
public function getMetadata(): ?array
{
return $this->metadata;
}
public function setMetadata(?array $metadata): self
{
$this->metadata = $metadata;
return $this;
}
public function getAiPrompt(): ?string
{
return $this->aiPrompt;
}
public function setAiPrompt(?string $aiPrompt): self
{
$this->aiPrompt = $aiPrompt;
return $this;
}
public function getAiResponse(): ?string
{
return $this->aiResponse;
}
public function setAiResponse(?string $aiResponse): self
{
$this->aiResponse = $aiResponse;
return $this;
}
public function isPublished(): bool
{
return $this->status === self::STATUS_PUBLISHED;
}
public function publish(): self
{
$this->status = self::STATUS_PUBLISHED;
$this->publishedAt = new \DateTime();
return $this;
}
public function __toString(): string
{
return $this->title ?? '';
}
}