<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\ArticleRepository")
*
* @ORM\HasLifecycleCallbacks()
*
* @ORM\Table(indexes={
*
* @ORM\Index(name="article_deleted_idx", columns={"deleted_at"}),
* @ORM\Index(name="publication_start_idx", columns={"publication_start"}),
* @ORM\Index(name="publication_end_idx", columns={"publication_end"}),
* @ORM\Index(name="highlight_start_idx", columns={"highlight_start"}),
* @ORM\Index(name="highlight_end_idx", columns={"highlight_end"}),
* @ORM\Index(name="slug_idx", columns={"slug"})
* })
*/
class Article
{
public const PUBLICATION_STATUS_DRAFT = 0;
public const PUBLICATION_STATUS_PUBLISHED = 1;
public const HIGHLIGHT_STATUS_OFF = 0;
public const HIGHLIGHT_STATUS_ON = 1;
public const SCOOPS_ON = 1;
public function __construct()
{
$this->article_blocks = new ArrayCollection();
$this->newsletter_articles = new ArrayCollection();
$this->article_tags = new ArrayCollection();
$this->comments = new ArrayCollection();
$this->articleCategories = new ArrayCollection();
$this->views = new ArrayCollection();
$this->newsletter_highlights = new ArrayCollection();
$this->article_products = new ArrayCollection();
$this->articles_favorite = new ArrayCollection();
}
/**
* @ORM\Id()
*
* @ORM\GeneratedValue()
*
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ArticleFavoris", mappedBy="article", cascade={"persist", "remove"})
*/
private $articles_favorite;
/**
* @ORM\Column(type="string", nullable=true, length=180)
*/
private $author_email = null;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $publication_start = null;
/**
* @ORM\Column(type="string", nullable=true, length=180)
*/
private $slug = null;
/**
* @ORM\Column(type="string", nullable=true, length=180)
*/
private $author_name = null;
/**
* @ORM\Column(type="text",nullable=false)
*/
private $title = null;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $publication_end = null;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $highlight_start = null;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $highlight_end = null;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $hat = null;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $summary = null;
/**
* @ORM\Column(type="integer", nullable=false)
*/
private $publication_status = 0;
/**
* @ORM\Column(type="integer", nullable=false)
*/
private $highlight_status = 0;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $legacy_id = null;
/**
* @ORM\Column(type="string", nullable=true, length=180)
*/
private $source_platform_name = null;
/**
* @ORM\Column(type="string", nullable=true, length=180)
*/
private $source_platform_uid = null;
/**
* @ORM\Column(type="integer", nullable=true, length=180)
*/
private $source_article_id = null;
/**
* @ORM\Column(type="integer", nullable=false, options={"default": 0})
*/
private $subscribers_only = 0;
/**
* @ORM\Column(type="integer", nullable=false, options={"default": 0})
*/
private $scoop = 0;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $marketplace_tags;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $e_shop_url_product;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $e_shop_url_product_sub;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $free_period_end;
/**
* @ORM\Column(type="string", length=255, nullable=true, unique=true)
*/
private $rss_uuid;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $rss_original_link = null;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $iscontribution = false;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $publishAsExpert = false;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $publishAsAdmin = false;
/**
* @ORM\Column(type="boolean", nullable=false)
*/
private $imported = false;
/**
* @return bool
*/
public function isIscontribution(): ?bool
{
return $this->iscontribution;
}
public function setIscontribution(bool $iscontribution): void
{
$this->iscontribution = $iscontribution;
}
public function getId(): ?int
{
return $this->id;
}
public function getAuthorEmail()
{
return $this->author_email;
}
public function setAuthorEmail($author_email)
{
$this->author_email = $author_email;
return $this;
}
public function getPublicationStart()
{
return $this->publication_start;
}
public function setPublicationStart($publication_start)
{
$this->publication_start = $publication_start;
return $this;
}
public function getSlug()
{
return $this->slug;
}
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
public function getLegacyId()
{
return $this->legacy_id;
}
public function setLegacyId($legacy_id)
{
$this->legacy_id = $legacy_id;
return $this;
}
public function getAuthorName()
{
return $this->author_name;
}
public function setAuthorName($author_name)
{
$this->author_name = $author_name;
return $this;
}
public function getTitle()
{
return $this->title;
}
public function setTitle($title)
{
$this->title = $title;
return $this;
}
public function getPublicationEnd()
{
return $this->publication_end;
}
public function setPublicationEnd($publication_end)
{
$this->publication_end = $publication_end;
return $this;
}
public function getHighlightStart()
{
return $this->highlight_start;
}
public function setHighlightStart($highlight_start)
{
$this->highlight_start = $highlight_start;
return $this;
}
public function getHighlightEnd()
{
return $this->highlight_end;
}
public function setHighlightEnd($highlight_end)
{
$this->highlight_end = $highlight_end;
return $this;
}
public function getHat()
{
return $this->hat;
}
public function setHat($hat)
{
$this->hat = $hat;
return $this;
}
public function getSummary()
{
return $this->summary;
}
public function setSummary($summary)
{
$this->summary = $summary;
return $this;
}
public function getPublicationStatus()
{
return $this->publication_status;
}
public function setPublicationStatus($publication_status)
{
$this->publication_status = $publication_status;
return $this;
}
public function getHighlightStatus()
{
return $this->highlight_status;
}
public function setHighlightStatus($highlight_status)
{
$this->highlight_status = $highlight_status;
return $this;
}
public function getSourcePlatformUid()
{
return $this->source_platform_uid;
}
public function setSourcePlatformUid($source_platform_uid)
{
$this->source_platform_uid = $source_platform_uid;
return $this;
}
public function getSourcePlatformName()
{
return $this->source_platform_name;
}
public function setSourcePlatformName($source_platform_name)
{
$this->source_platform_name = $source_platform_name;
return $this;
}
public function getSourceArticleId()
{
return $this->source_article_id;
}
public function setSourceArticleId($source_article_id)
{
$this->source_article_id = $source_article_id;
return $this;
}
/**
* @return int
*/
public function getSubscribersOnly()
{
return $this->subscribers_only;
}
public function setSubscribersOnly(int $subscribers_only): self
{
$this->subscribers_only = $subscribers_only;
return $this;
}
/**
* @return int
*/
public function getScoop()
{
return $this->scoop;
}
public function setScoop(int $scoop): self
{
$this->scoop = $scoop;
return $this;
}
/**
* @return mixed
*/
public function getMarketplaceTags()
{
return $this->marketplace_tags;
}
/**
* @param mixed $marketplace_tags
*
* @return Article
*/
public function setMarketplaceTags($marketplace_tags)
{
$this->marketplace_tags = $marketplace_tags;
return $this;
}
/**
* @return mixed
*/
public function getEshopUrlProduct()
{
return $this->e_shop_url_product;
}
/**
* @param mixed $e_shop_url_product
*
* @return Article
*/
public function setEshopUrlProduct($e_shop_url_product)
{
$this->e_shop_url_product = $e_shop_url_product;
return $this;
}
/**
* @return mixed
*/
public function getEShopUrlProductSub()
{
return $this->e_shop_url_product_sub;
}
/**
* @param mixed $e_shop_url_product_sub
*
* @return Article
*/
public function setEShopUrlProductSub($e_shop_url_product_sub)
{
$this->e_shop_url_product_sub = $e_shop_url_product_sub;
return $this;
}
/**
* @ORM\Column(type="datetime", nullable=false)
*/
private $created_at;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updated_at = null;
public function getCreatedAt(): \DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(?\DateTimeInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
/**
* @ORM\PrePersist
*/
public function setCreatedAtValue()
{
$this->setCreatedAt(new \DateTime());
}
/**
* @ORM\PreUpdate
*/
public function setUpdatedAtValue()
{
$this->setUpdatedAt(new \DateTime());
}
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $deleted_at;
public function getDeletedAt(): ?\DateTimeInterface
{
return $this->deleted_at;
}
public function setDeletedAt(?\DateTimeInterface $deleted_at): self
{
$this->deleted_at = $deleted_at;
return $this;
}
/**
* @return null
*/
public function getFreePeriodEnd()
{
return $this->free_period_end;
}
/**
* @param null $free_period_end
*
* @return Article
*/
public function setFreePeriodEnd($free_period_end)
{
$this->free_period_end = $free_period_end;
return $this;
}
/**
* @ORM\OneToMany(targetEntity="App\Entity\ArticleBlock", mappedBy="article")
*/
private $article_blocks;
/**
* @return Collection|ArticleBlock[]
*/
public function getArticleBlocks(): Collection
{
return $this->article_blocks;
}
public function addArticleBlock(ArticleBlock $article_block): self
{
if (!$this->article_blocks->contains($article_block)) {
$this->article_blocks[] = $article_block;
$article_block->setArticle($this);
}
return $this;
}
public function removeArticleBlock(ArticleBlock $article_block): self
{
if ($this->article_blocks->contains($article_block)) {
$this->article_blocks->removeElement($article_block);
if ($article_block->getArticle() === $this) {
$article_block->setArticle(null);
}
}
return $this;
}
/**
* @ORM\OneToMany(targetEntity="App\Entity\ArticleProduct", mappedBy="article")
*/
private $article_products;
/**
* @return Collection|ArticleProduct[]
*/
public function getArticleProducts(): Collection
{
return $this->article_products;
}
public function addArticleProduct(ArticleProduct $article_product): self
{
if (!$this->article_products->contains($article_product)) {
$this->article_products[] = $article_product;
$article_product->setArticle($this);
}
return $this;
}
public function removeArticleProduct(ArticleProduct $article_product): self
{
if ($this->article_products->contains($article_product)) {
$this->article_products->removeElement($article_product);
if ($article_product->getArticle() === $this) {
$article_product->setArticle(null);
}
}
return $this;
}
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="articles")
*/
private $user;
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @ORM\OneToMany(targetEntity="App\Entity\ArticleTag", mappedBy="article")
*/
private $article_tags;
/**
* @return Collection|ArticleTag[]
*/
public function getArticleTags(): Collection
{
return $this->article_tags;
}
public function addArticleTag(ArticleTag $article_tag): self
{
if (!$this->article_tags->contains($article_tag)) {
$this->article_tags[] = $article_tag;
$article_tag->setArticle($this);
}
return $this;
}
public function removeArticleTag(ArticleTag $article_tag): self
{
if ($this->article_tags->contains($article_tag)) {
$this->article_tags->removeElement($article_tag);
if ($article_tag->getArticle() === $this) {
$article_tag->setArticle(null);
}
}
return $this;
}
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Media")
*
* @ORM\JoinColumn(nullable=true)
*/
private $cover;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="article")
*/
private $comments;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ArticleCategory", mappedBy="article")
*/
private $articleCategories;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ArticleView", mappedBy="article")
*/
private $views;
public function getCover(): ?Media
{
return $this->cover;
}
public function setCover(?Media $cover): self
{
$this->cover = $cover;
return $this;
}
/**
* @return Collection|Comment[]
*/
public function getComments(): Collection
{
return $this->comments;
}
public function getPublishedComments(): array
{
$publishedComments = [];
$comments = $this->getComments();
if ($comments) {
foreach ($comments as $comment) {
if ($comment->getParent()) {
$parentDeleted = $comment->getParent()->getDeletedAt();
if (!$comment->getDeletedAt() && !$parentDeleted) {
$publishedComments[] = $comment;
}
} else {
if (!$comment->getDeletedAt()) {
$publishedComments[] = $comment;
}
}
}
}
return $publishedComments;
}
public function addComment(Comment $comment): self
{
if (!$this->comments->contains($comment)) {
$this->comments[] = $comment;
$comment->setArticle($this);
}
return $this;
}
public function removeComment(Comment $comment): self
{
if ($this->comments->contains($comment)) {
$this->comments->removeElement($comment);
// set the owning side to null (unless already changed)
if ($comment->getArticle() === $this) {
$comment->setArticle(null);
}
}
return $this;
}
/**
* @return Collection|ArticleCategory[]
*/
public function getArticleCategories(): Collection
{
return $this->articleCategories;
}
public function addArticleCategory(ArticleCategory $articleCategory): self
{
if (!$this->articleCategories->contains($articleCategory)) {
$this->articleCategories[] = $articleCategory;
$articleCategory->setArticle($this);
}
return $this;
}
public function removeArticleCategory(ArticleCategory $articleCategory): self
{
if ($this->articleCategories->contains($articleCategory)) {
$this->articleCategories->removeElement($articleCategory);
// set the owning side to null (unless already changed)
if ($articleCategory->getArticle() === $this) {
$articleCategory->setArticle(null);
}
}
return $this;
}
/**
* @ORM\OneToMany(targetEntity="App\Entity\NewsletterArticle", mappedBy="article")
*/
private $newsletter_articles;
/**
* @return Collection|NewsletterArticle[]
*/
public function getNewsletterArticles(): Collection
{
return $this->newsletter_articles;
}
public function addNewsletterArticle(NewsletterArticle $newsletter_article): self
{
if (!$this->newsletter_articles->contains($newsletter_article)) {
$this->newsletter_articles[] = $newsletter_article;
$newsletter_article->setArticle($this);
}
return $this;
}
public function removeNewsletterArticle(NewsletterArticle $newsletter_article): self
{
if ($this->newsletter_articles->contains($newsletter_article)) {
$this->newsletter_articles->removeElement($newsletter_article);
if ($newsletter_article->getArticle() === $this) {
$newsletter_article->setArticle(null);
}
}
return $this;
}
/**
* @ORM\OneToMany(targetEntity="App\Entity\Newsletter", mappedBy="highlighted_article")
*/
private $newsletter_highlights;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $rss_data = [];
/**
* @ORM\ManyToOne(targetEntity=RssFeed::class, inversedBy="articles")
*/
private $rss_feed;
/**
* @return Collection|Newsletter[]
*/
public function getNewsletterHighlights(): Collection
{
return $this->newsletter_highlights;
}
public function addNewsletterHighlight(Newsletter $newsletter_highlight): self
{
if (!$this->newsletter_highlights->contains($newsletter_highlight)) {
$this->newsletter_highlights[] = $newsletter_highlight;
$newsletter_highlight->setHighlightedArticle($this);
}
return $this;
}
public function removeNewsletterHighlight(Newsletter $newsletter_highlight): self
{
if ($this->newsletter_highlights->contains($newsletter_highlight)) {
$this->newsletter_highlights->removeElement($newsletter_highlight);
if ($newsletter_highlight->getHighlightedArticle() === $this) {
$newsletter_highlight->setHighlightedArticle(null);
}
}
return $this;
}
/**
* @return mixed
*/
public function getViews()
{
return $this->views;
}
/**
* @param mixed $views
*
* @return Article
*/
public function setViews($views)
{
$this->views = $views;
return $this;
}
// Custom methods
public function isPremium(): bool
{
// Legacy
if ($this->subscribers_only && $this->publication_start instanceof \DateTime && !$this->free_period_end) {
$this->free_period_end = (clone $this->publication_start)->modify('+7 days');
}
// Keep only this condition in the future, $this->subscribers_only will become useless
if ($this->free_period_end && $this->free_period_end < new \DateTime()) {
return true;
}
return false;
}
/**
* @return mixed
*/
public function getRssUuid()
{
return $this->rss_uuid;
}
/**
* @param mixed $rss_uuid
*
* @return Article
*/
public function setRssUuid($rss_uuid)
{
$this->rss_uuid = $rss_uuid;
return $this;
}
public function getRssData(): ?array
{
return $this->rss_data;
}
public function setRssData(?array $rssdata): self
{
$this->rss_data = $rssdata;
return $this;
}
public function getRssFeed(): ?RssFeed
{
return $this->rss_feed;
}
public function setRssFeed(?RssFeed $rss_feed): self
{
$this->rss_feed = $rss_feed;
return $this;
}
public function getRssOriginalLink(): ?string
{
return $this->rss_original_link;
}
public function setRssOriginalLink(string $rss_original_link): self
{
$this->rss_original_link = $rss_original_link;
return $this;
}
/**
* @return bool
*/
public function isPublishAsExpert(): ?bool
{
return $this->publishAsExpert;
}
/**
* @param bool $publishAsExpert
*/
public function setPublishAsExpert(?bool $publishAsExpert)
{
$this->publishAsExpert = $publishAsExpert;
}
/**
* @return bool
*/
public function isPublishAsAdmin(): ?bool
{
return $this->publishAsAdmin;
}
/**
* @param bool $publishAsAdmin
*/
public function setPublishAsAdmin(?bool $publishAsAdmin)
{
$this->publishAsAdmin = $publishAsAdmin;
}
public function isImported(): bool
{
return $this->imported;
}
public function setImported(bool $imported): void
{
$this->imported = $imported;
}
/**
* @return void
*
* @ORM\PreFlush()
*/
public function handlePreFlush()
{
if ($this->subscribers_only && $this->publication_start instanceof \DateTime && !$this->free_period_end) {
$this->free_period_end = (clone $this->publication_start)->modify('+7 days');
}
if (!$this->subscribers_only) {
$this->free_period_end = null;
}
}
public function getArticleFavorite(): Collection
{
return $this->articles_favorite;
}
}