<?php
namespace App\CasinoBundle\Entity;
use App\CasinoBundle\Helper\SlugHelper;
use App\CmsBundle\Entity\ContentTrait;
use App\CmsBundle\Entity\TitleTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\CmsBundle\Entity\Site;
use App\CmsBundle\Entity\SlugTrait;
use App\CmsBundle\Entity\TimeStampedTrait;
use App\CmsBundle\Entity\IdTrait;
/**
* Article
*
* @ORM\Table(
* name="article",
* indexes={
* @ORM\Index(name="slug_index", columns={"slug"}),
* @ORM\Index(name="site_index", columns={"site_id"}),
* @ORM\Index(name="created_index", columns={"created"}),
* @ORM\Index(name="updated_index", columns={"updated"})
* },
* uniqueConstraints={
* @ORM\UniqueConstraint(name="site_slug_uindex", columns={"site_id","slug"})
* }
* )
* @ORM\Entity(repositoryClass="App\CasinoBundle\Repository\ArticleRepository")
* @ORM\HasLifecycleCallbacks()
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="one_day")
* @ORM\HasLifecycleCallbacks()
*/
class Article
{
use IdTrait, TitleTrait, SlugTrait, TimeStampedTrait, ContentTrait;
/**
* @ORM\Column(name="title", type="string", length=255, nullable=false)
*/
private $title;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $contentPreview;
/**
* @ORM\Column(name="meta_title", type="string", length=255, nullable=true)
*/
private $metaTitle;
/**
* @ORM\Column(name="meta_description", type="string", length=255, nullable=true)
*/
private $metaDescription;
/**
* @ORM\Column(name="preview_source", type="string", length=255, nullable=true)
*/
private $previewSource;
/**
* @ORM\Column(name="desktop_source", type="string", length=255, nullable=true)
*/
private $desktopSource;
/**
* @ORM\Column(name="mobile_source", type="string", length=255, nullable=true)
*/
private $mobileSource;
/**
* @ORM\Column(name="time_to_read", type="integer", nullable=true)
*/
private $timeToRead;
/**
* @ORM\ManyToMany(targetEntity="App\CasinoBundle\Entity\BlogTag", inversedBy="articles", cascade={"persist"})
* @ORM\JoinTable(
* name="article_blog_tag",
* joinColumns={
* @ORM\JoinColumn(name="article_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="blog_tag_id", referencedColumnName="id")
* }
* )
*/
protected $blogTags;
/**
* @ORM\ManyToMany(targetEntity="App\CasinoBundle\Entity\BlogCategory", inversedBy="articles", cascade={"persist"})
* @ORM\JoinTable(
* name="article_blog_category",
* joinColumns={
* @ORM\JoinColumn(name="article_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="blog_category_id", referencedColumnName="id")
* }
* )
*/
protected $blogCategories;
/**
* @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\Site")
* @ORM\JoinColumn(name="site_id", referencedColumnName="id")
*/
private $site;
/**
* @ORM\ManyToOne(targetEntity="App\CasinoBundle\Entity\Author", inversedBy="articles")
* @ORM\JoinColumn(name="author_id", referencedColumnName="id")
*/
private $author;
public function __construct()
{
$this->blogCategories = new ArrayCollection();
$this->blogTags = new ArrayCollection();
}
/**
* @ORM\PrePersist
*/
public function getSlugFromTitle(): void
{
$this->slug = SlugHelper::slugify($this->title);
}
public function getContentPreview(): ?string
{
return $this->contentPreview;
}
public function setContentPreview(?string $contentPreview): self
{
$this->contentPreview = $contentPreview;
return $this;
}
public function getMetaTitle(): ?string
{
return $this->metaTitle;
}
public function setMetaTitle(?string $metaTitle): self
{
$this->metaTitle = $metaTitle;
return $this;
}
public function getMetaDescription(): ?string
{
return $this->metaDescription;
}
public function setMetaDescription(?string $metaDescription): self
{
$this->metaDescription = $metaDescription;
return $this;
}
public function getPreviewSource(): ?string
{
return $this->previewSource;
}
public function setPreviewSource(?string $previewSource): self
{
$this->previewSource = $previewSource;
return $this;
}
public function getDesktopSource(): ?string
{
return $this->desktopSource;
}
public function setDesktopSource(?string $desktopSource): self
{
$this->desktopSource = $desktopSource;
return $this;
}
public function getMobileSource(): ?string
{
return $this->mobileSource;
}
public function setMobileSource(?string $mobileSource): self
{
$this->mobileSource = $mobileSource;
return $this;
}
public function getTimeToRead(): ?string
{
return $this->timeToRead;
}
public function setTimeToRead(?string $timeToRead): self
{
$this->timeToRead = $timeToRead;
return $this;
}
public function getSite(): ?Site
{
return $this->site;
}
public function setSite(?Site $site): self
{
$this->site = $site;
return $this;
}
public function getAuthor(): ?Author
{
return $this->author;
}
public function setAuthor(?Author $author): self
{
$this->author = $author;
return $this;
}
public function getBlogTags(): Collection
{
return $this->blogTags;
}
public function addBlogTag(BlogTag $blogTag): self
{
if (!$this->blogTags->contains($blogTag)) {
$this->blogTags[] = $blogTag;
$blogTag->addArticle($this);
}
return $this;
}
public function removeBlogTag(BlogTag $blogTag): self
{
if ($this->blogTags->contains($blogTag)) {
$this->blogTags->removeElement($blogTag);
$blogTag->removeArticle($this);
}
return $this;
}
public function getBlogCategories(): Collection
{
return $this->blogCategories;
}
public function addBlogCategory(BlogCategory $blogCategory): self
{
if (!$this->blogCategories->contains($blogCategory)) {
$this->blogCategories[] = $blogCategory;
$blogCategory->addArticle($this);
}
return $this;
}
public function removeBlogCategory(BlogCategory $blogCategory): self
{
if ($this->blogCategories->contains($blogCategory)) {
$this->blogCategories->removeElement($blogCategory);
$blogCategory->removeArticle($this);
}
return $this;
}
}