src/CasinoBundle/Entity/Article.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\CasinoBundle\Entity;
  3. use App\CasinoBundle\Helper\SlugHelper;
  4. use App\CmsBundle\Entity\ContentTrait;
  5. use App\CmsBundle\Entity\TitleTrait;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use App\CmsBundle\Entity\Site;
  10. use App\CmsBundle\Entity\SlugTrait;
  11. use App\CmsBundle\Entity\TimeStampedTrait;
  12. use App\CmsBundle\Entity\IdTrait;
  13. /**
  14.  * Article
  15.  *
  16.  * @ORM\Table(
  17.  *     name="article",
  18.  *     indexes={
  19.  *         @ORM\Index(name="slug_index", columns={"slug"}),
  20.  *         @ORM\Index(name="site_index", columns={"site_id"}),
  21.  *         @ORM\Index(name="created_index", columns={"created"}),
  22.  *         @ORM\Index(name="updated_index", columns={"updated"})
  23.  *     },
  24.  *     uniqueConstraints={
  25.  *         @ORM\UniqueConstraint(name="site_slug_uindex", columns={"site_id","slug"})
  26.  *     }
  27.  * )
  28.  * @ORM\Entity(repositoryClass="App\CasinoBundle\Repository\ArticleRepository")
  29.  * @ORM\HasLifecycleCallbacks()
  30.  * @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="one_day")
  31.  * @ORM\HasLifecycleCallbacks()
  32.  */
  33. class Article
  34. {
  35.     use IdTraitTitleTraitSlugTraitTimeStampedTraitContentTrait;
  36.     /**
  37.      * @ORM\Column(name="title", type="string", length=255, nullable=false)
  38.      */
  39.     private $title;
  40.     /**
  41.      * @ORM\Column(type="text", nullable=true)
  42.      */
  43.     private $contentPreview;
  44.     /**
  45.      * @ORM\Column(name="meta_title", type="string", length=255, nullable=true)
  46.      */
  47.     private $metaTitle;
  48.     /**
  49.      * @ORM\Column(name="meta_description", type="string", length=255, nullable=true)
  50.      */
  51.     private $metaDescription;
  52.     /**
  53.      * @ORM\Column(name="preview_source", type="string", length=255, nullable=true)
  54.      */
  55.     private $previewSource;
  56.     /**
  57.      * @ORM\Column(name="desktop_source", type="string", length=255, nullable=true)
  58.      */
  59.     private $desktopSource;
  60.     /**
  61.      * @ORM\Column(name="mobile_source", type="string", length=255, nullable=true)
  62.      */
  63.     private $mobileSource;
  64.     /**
  65.      * @ORM\Column(name="time_to_read", type="integer", nullable=true)
  66.      */
  67.     private $timeToRead;
  68.     /**
  69.      * @ORM\ManyToMany(targetEntity="App\CasinoBundle\Entity\BlogTag", inversedBy="articles", cascade={"persist"})
  70.      * @ORM\JoinTable(
  71.      *     name="article_blog_tag",
  72.      *     joinColumns={
  73.      *          @ORM\JoinColumn(name="article_id", referencedColumnName="id")
  74.      *     },
  75.      *     inverseJoinColumns={
  76.      *          @ORM\JoinColumn(name="blog_tag_id", referencedColumnName="id")
  77.      *     }
  78.      * )
  79.      */
  80.     protected $blogTags;
  81.     /**
  82.      * @ORM\ManyToMany(targetEntity="App\CasinoBundle\Entity\BlogCategory", inversedBy="articles", cascade={"persist"})
  83.      * @ORM\JoinTable(
  84.      *     name="article_blog_category",
  85.      *     joinColumns={
  86.      *          @ORM\JoinColumn(name="article_id", referencedColumnName="id")
  87.      *     },
  88.      *     inverseJoinColumns={
  89.      *          @ORM\JoinColumn(name="blog_category_id", referencedColumnName="id")
  90.      *     }
  91.      * )
  92.      */
  93.     protected $blogCategories;
  94.     /**
  95.      * @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\Site")
  96.      * @ORM\JoinColumn(name="site_id", referencedColumnName="id")
  97.      */
  98.     private $site;
  99.     /**
  100.      * @ORM\ManyToOne(targetEntity="App\CasinoBundle\Entity\Author", inversedBy="articles")
  101.      * @ORM\JoinColumn(name="author_id", referencedColumnName="id")
  102.      */
  103.     private $author;
  104.     public function __construct()
  105.     {
  106.         $this->blogCategories = new ArrayCollection();
  107.         $this->blogTags = new ArrayCollection();
  108.     }
  109.     /**
  110.      * @ORM\PrePersist
  111.      */
  112.     public function getSlugFromTitle(): void
  113.     {
  114.         $this->slug SlugHelper::slugify($this->title);
  115.     }
  116.     public function getContentPreview(): ?string
  117.     {
  118.         return $this->contentPreview;
  119.     }
  120.     public function setContentPreview(?string $contentPreview): self
  121.     {
  122.         $this->contentPreview $contentPreview;
  123.         return $this;
  124.     }
  125.     public function getMetaTitle(): ?string
  126.     {
  127.         return $this->metaTitle;
  128.     }
  129.     public function setMetaTitle(?string $metaTitle): self
  130.     {
  131.         $this->metaTitle $metaTitle;
  132.         return $this;
  133.     }
  134.     public function getMetaDescription(): ?string
  135.     {
  136.         return $this->metaDescription;
  137.     }
  138.     public function setMetaDescription(?string $metaDescription): self
  139.     {
  140.         $this->metaDescription $metaDescription;
  141.         return $this;
  142.     }
  143.     public function getPreviewSource(): ?string
  144.     {
  145.         return $this->previewSource;
  146.     }
  147.     public function setPreviewSource(?string $previewSource): self
  148.     {
  149.         $this->previewSource $previewSource;
  150.         return $this;
  151.     }
  152.     public function getDesktopSource(): ?string
  153.     {
  154.         return $this->desktopSource;
  155.     }
  156.     public function setDesktopSource(?string $desktopSource): self
  157.     {
  158.         $this->desktopSource $desktopSource;
  159.         return $this;
  160.     }
  161.     public function getMobileSource(): ?string
  162.     {
  163.         return $this->mobileSource;
  164.     }
  165.     public function setMobileSource(?string $mobileSource): self
  166.     {
  167.         $this->mobileSource $mobileSource;
  168.         return $this;
  169.     }
  170.     public function getTimeToRead(): ?string
  171.     {
  172.         return $this->timeToRead;
  173.     }
  174.     public function setTimeToRead(?string $timeToRead): self
  175.     {
  176.         $this->timeToRead $timeToRead;
  177.         return $this;
  178.     }
  179.     public function getSite(): ?Site
  180.     {
  181.         return $this->site;
  182.     }
  183.     public function setSite(?Site $site): self
  184.     {
  185.         $this->site $site;
  186.         return $this;
  187.     }
  188.     public function getAuthor(): ?Author
  189.     {
  190.         return $this->author;
  191.     }
  192.     public function setAuthor(?Author $author): self
  193.     {
  194.         $this->author $author;
  195.         return $this;
  196.     }
  197.     public function getBlogTags(): Collection
  198.     {
  199.         return $this->blogTags;
  200.     }
  201.     public function addBlogTag(BlogTag $blogTag): self
  202.     {
  203.         if (!$this->blogTags->contains($blogTag)) {
  204.             $this->blogTags[] = $blogTag;
  205.             $blogTag->addArticle($this);
  206.         }
  207.         return $this;
  208.     }
  209.     public function removeBlogTag(BlogTag $blogTag): self
  210.     {
  211.         if ($this->blogTags->contains($blogTag)) {
  212.             $this->blogTags->removeElement($blogTag);
  213.             $blogTag->removeArticle($this);
  214.         }
  215.         return $this;
  216.     }
  217.     public function getBlogCategories(): Collection
  218.     {
  219.         return $this->blogCategories;
  220.     }
  221.     public function addBlogCategory(BlogCategory $blogCategory): self
  222.     {
  223.         if (!$this->blogCategories->contains($blogCategory)) {
  224.             $this->blogCategories[] = $blogCategory;
  225.             $blogCategory->addArticle($this);
  226.         }
  227.         return $this;
  228.     }
  229.     public function removeBlogCategory(BlogCategory $blogCategory): self
  230.     {
  231.         if ($this->blogCategories->contains($blogCategory)) {
  232.             $this->blogCategories->removeElement($blogCategory);
  233.             $blogCategory->removeArticle($this);
  234.         }
  235.         return $this;
  236.     }
  237. }