vendor/score/cms/src/Entity/Article/Article.php line 22

Open in your IDE?
  1. <?php
  2. namespace Score\CmsBundle\Entity\Article;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Score\BaseBundle\Entity\BaseEntity;
  7. use Score\CmsBundle\Entity\Access\Access;
  8. use Score\CmsBundle\Entity\Access\AccessArticle;
  9. use Score\CmsBundle\Entity\Block\BlockJoint;
  10. use Score\CmsBundle\Entity\Block\BlockJointArticle;
  11. use Score\CmsBundle\Entity\Metatag\MetatagArticle;
  12. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  13. /**
  14.  * @ORM\Entity(repositoryClass="Score\CmsBundle\Repository\ArticleRepository")
  15.  * @ORM\Table(name="cms_article")
  16.  * @ORM\HasLifecycleCallbacks()
  17.  */
  18. class Article extends BaseEntity {
  19.     protected static $author_enum = array
  20.     (
  21.         '1' => '',
  22.         '2' => 'SAŽP',
  23.     );
  24.     public static function getAuthorEnum() {
  25.         return self::$author_enum;
  26.     }
  27.     public function getAuthorName() {
  28.         return self::$author_enum[$this->getAuthor()];
  29.     }
  30.     /**
  31.      * @ORM\Column(type="string", length=500)
  32.      */
  33.     protected $name;
  34.     /**
  35.      * @ORM\Column(type="string", length=255, nullable=true)
  36.      */
  37.     protected $icon;
  38.     /**
  39.      * @ORM\Column(type="text", length=2000, nullable=true)
  40.      */
  41.     protected $teaser;
  42.     /**
  43.      * @ORM\Column(type="text", nullable=true)
  44.      */
  45.     protected $body;
  46.     /**
  47.      * @ORM\Column(type="integer")
  48.      */
  49.     protected $published;
  50.     /**
  51.      * @ORM\Column(type="integer")
  52.      */
  53.     protected $createdBy;
  54.     /**
  55.      * @ORM\Column(type="integer", nullable=true)
  56.      */
  57.     protected $priority;
  58.     /**
  59.      * @ORM\Column(type="string", length=200)
  60.      */
  61.     protected $author;
  62.     /**
  63.      * @ORM\Column(type="datetime", name="published_from",nullable=true)
  64.      */
  65.     protected $publishedFrom;
  66.     /**
  67.      * @ORM\Column(type="datetime", name="published_to",nullable=true)
  68.      */
  69.     protected $publishedTo;
  70.     /**
  71.      * @ORM\Column(type="string", length=255, nullable = true, unique=true)
  72.      */
  73.     protected $slug;
  74.     /**
  75.      * @ORM\Column(type="string",name="seo_title", length=255, nullable=true)
  76.      */
  77.     protected $seoTitle;
  78.     /**
  79.      * @ORM\Column(type="string",length=5000, nullable=true)
  80.      */
  81.     protected $metadata;
  82.     /**
  83.      * @ORM\Column(type="text", nullable=true)
  84.      */
  85.     protected $search;
  86.     /**
  87.      * @ORM\OneToMany(targetEntity="\Score\CmsBundle\Entity\Multisite\SiteItemArticle", mappedBy="article",cascade={"persist","remove"})
  88.      */
  89.     protected $siteItemArticle = [];
  90.     /**
  91.      * @ORM\ManyToMany(targetEntity=ArticleCategory::class, inversedBy="articles", cascade={"persist", "remove"})
  92.      * @ORM\JoinTable(name="cms_conn_article_category",
  93.      *      joinColumns={@ORM\JoinColumn(name="article_id", referencedColumnName="id")},
  94.      *      inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")}
  95.      *      )
  96.      * @ORM\OrderBy({"seoName" = "ASC"})
  97.      */
  98.     protected $articleCategories;
  99.     /**
  100.      * @ORM\OneToMany(targetEntity=AccessArticle::class, mappedBy="article", cascade={"persist", "remove"}, orphanRemoval=true)
  101.      */
  102.     protected $accesses;
  103.     /**
  104.      * @ORM\OneToMany(targetEntity=BlockJointArticle::class, mappedBy="article", cascade={"persist", "remove"}, orphanRemoval=true)
  105.      * @ORM\OrderBy({"sortOrder"="ASC", "place"="ASC"})
  106.      */
  107.     protected $blockJoints;
  108.     /**
  109.      * @ORM\OneToMany(targetEntity=MetatagArticle::class, mappedBy="article", cascade={"persist", "remove"}, orphanRemoval=true)
  110.      */
  111.     protected $metatags;
  112.     protected $multisite;
  113.     protected $keywords;
  114.     protected $type;
  115.     public function __construct() {
  116.         $this->accesses = new ArrayCollection();
  117.         $this->blockJoints = new ArrayCollection();
  118.         $this->metatags = new ArrayCollection();
  119.         $this->articleCategories = new ArrayCollection();
  120.     }
  121.     public function getPublishedFrom() {
  122.         return $this->publishedFrom;
  123.     }
  124.     public function getPublishedTo() {
  125.         return $this->publishedTo;
  126.     }
  127.     public function getSeoTitle() {
  128.         return $this->seoTitle;
  129.     }
  130.     public function setPublishedFrom($publishedFrom) {
  131.         $this->publishedFrom = $publishedFrom;
  132.         return $this;
  133.     }
  134.     public function setPublishedTo($publishedTo) {
  135.         $this->publishedTo = $publishedTo;
  136.         return $this;
  137.     }
  138.     public function setSeoTitle($seoTitle) {
  139.         $this->seoTitle = $seoTitle;
  140.         return $this;
  141.     }
  142.     public function getId() {
  143.         return $this->id;
  144.     }
  145.     public function getName() {
  146.         return $this->name;
  147.     }
  148.     public function getIcon() {
  149.         return $this->icon;
  150.     }
  151.     public function getTeaser() {
  152.         return $this->teaser;
  153.     }
  154.     public function getBody() {
  155.         return $this->body;
  156.     }
  157.     public function getPublished() {
  158.         return $this->published;
  159.     }
  160.     public function getPriority() {
  161.         return $this->priority;
  162.     }
  163.     public function getAuthor() {
  164.         return $this->author;
  165.     }
  166.     public function getSlug() {
  167.         return $this->slug;
  168.     }
  169.     public function setId($id) {
  170.         $this->id = $id;
  171.         return $this;
  172.     }
  173.     public function setName($name) {
  174.         $this->name = $name;
  175.         return $this;
  176.     }
  177.     public function setIcon($icon) {
  178.         $this->icon = $icon;
  179.         return $this;
  180.     }
  181.     public function setTeaser($teaser) {
  182.         $this->teaser = $teaser;
  183.         return $this;
  184.     }
  185.     public function setBody($body) {
  186.         $this->body = $body;
  187.         return $this;
  188.     }
  189.     public function setPublished($published) {
  190.         $this->published = $published;
  191.         return $this;
  192.     }
  193.     public function setPriority($priority) {
  194.         $this->priority = $priority;
  195.         return $this;
  196.     }
  197.     public function setAuthor($author) {
  198.         $this->author = $author;
  199.         return $this;
  200.     }
  201.     public function setSlug($slug) {
  202.         $this->slug = $slug;
  203.         return $this;
  204.     }
  205.     public function __toString() {
  206.         return $this->getName();
  207.     }
  208.     public function getCreatedBy() {
  209.         return $this->createdBy;
  210.     }
  211.     public function setCreatedBy($createdBy) {
  212.         $this->createdBy = $createdBy;
  213.         return $this;
  214.     }
  215.     public function getType() {
  216.         return $this->type;
  217.     }
  218.     public function setType($type) {
  219.         $this->type = $type;
  220.         return $this;
  221.     }
  222.     public function getMetadata() {
  223.         return $this->metadata;
  224.     }
  225.     public function setMetadata($metadata) {
  226.         $this->metadata = $metadata;
  227.         return $this;
  228.     }
  229.     public function iconThumb($width, $height) {
  230.         if (!$this->getIcon()) {
  231.             return '';
  232. //            return 'default_' . $width . 'x' . $height . '.png';
  233.         }
  234.         $parts = explode('.', $this->getIcon());
  235.         $extension = end($parts);
  236.         return str_replace('.' . $extension, '', $this->getIcon()) . '_thumb_' . $width . 'x' . $height . '.' . $extension;
  237.     }
  238.     public function getPublishedDate($format = 'd.m. Y') {
  239.         if ($this->getPublished() == 1) {
  240.             if (null != $this->getPublishedFrom()) {
  241.                 return $this->getPublishedFrom()->format($format);
  242.             } else {
  243.                 return date($format);
  244.             }
  245.         } else {
  246.             return 'nepublikované';
  247.         }
  248.     }
  249.     public function getStrip() {
  250.         return mb_substr(strip_tags($this->getTeaser()), 0, 200) . '...';
  251.     }
  252.     public function getTeaserStrip($length = 200) {
  253.         $tidy = new \tidy();
  254.         $strip = mb_substr($this->getTeaser(), 0, 200) . '...';
  255.         $strip = $tidy->repairString($strip, array('show-body-only' => true));
  256.         return $strip;
  257.     }
  258.     protected function getMetadataArray() {
  259.         $data = $this->getMetadata();
  260.         $arr = json_decode($data, true);
  261.         return $arr;
  262.     }
  263.     /**
  264.      * Get the value of search
  265.      */
  266.     public function getSearch() {
  267.         return $this->search;
  268.     }
  269.     /**
  270.      * Set the value of search
  271.      *
  272.      * @return  self
  273.      */
  274.     public function setSearch($search) {
  275.         $this->search = $search;
  276.         return $this;
  277.     }
  278.     /**
  279.      * Get the value of siteItemArticle
  280.      */
  281.     public function getSiteItemArticle() {
  282.         return $this->siteItemArticle;
  283.     }
  284.     /**
  285.      * Set the value of siteItemArticle
  286.      *
  287.      * @return  self
  288.      */
  289.     public function setSiteItemArticle($siteItemArticle) {
  290.         $this->siteItemArticle = $siteItemArticle;
  291.         return $this;
  292.     }
  293.     /**
  294.      * Get the value of multisite
  295.      */
  296.     public function getMultisite() {
  297.         return $this->multisite;
  298.     }
  299.     /**
  300.      * Set the value of multisite
  301.      *
  302.      * @return  self
  303.      */
  304.     public function setMultisite($multisite) {
  305.         $this->multisite = $multisite;
  306.         return $this;
  307.     }
  308.     public function getCategoryNames() {
  309.         return implode(", ", $this->getArticleCategories()->map(function ($c) {
  310.             return $c->getName();
  311.         })->toArray());
  312.     }
  313.     /**
  314.      * @return Collection<int, ArticleCategory>
  315.      */
  316.     public function getArticleCategories(): Collection {
  317.         return $this->articleCategories;
  318.     }
  319.     public function addArticleCategory(ArticleCategory $articleCategory): self {
  320.         if (!$this->articleCategories->contains($articleCategory)) {
  321.             $this->articleCategories[] = $articleCategory;
  322.             $articleCategory->addArticle($this);
  323.         }
  324.         return $this;
  325.     }
  326.     public function removeArticleCategory(ArticleCategory $articleCategory): self {
  327.         if ($this->articleCategories->removeElement($articleCategory)) {
  328.             $articleCategory->removeArticle($this);
  329.         }
  330.         return $this;
  331.     }
  332.     /**
  333.      * @return Collection<int, Access>
  334.      */
  335.     public function getAccesses(): Collection {
  336.         return $this->accesses;
  337.     }
  338.     public function addAccess(AccessArticle $access): self {
  339.         if (!$this->accesses->contains($access)) {
  340.             $this->accesses[] = $access;
  341.             $access->setArticle($this);
  342.         }
  343.         return $this;
  344.     }
  345.     public function removeAccess(Access $access): self {
  346.         $this->accesses->removeElement($access);
  347.         return $this;
  348.     }
  349.     /**
  350.      * @return Collection<int, BlockJointPage>
  351.      */
  352.     public function getBlockJoints(): Collection {
  353.         return $this->blockJoints;
  354.     }
  355.     public function addBlockJoint(BlockJointArticle $blockJoint): self {
  356.         if (!$this->blockJoints->contains($blockJoint)) {
  357.             $this->blockJoints[] = $blockJoint;
  358.             $blockJoint->setArticle($this);
  359.         }
  360.         return $this;
  361.     }
  362.     public function removeBlockJoint(BlockJoint $blockJoint): self {
  363.         $this->blockJoints->removeElement($blockJoint);
  364.         return $this;
  365.     }
  366.     /**
  367.      * @return Collection<int, MetatagArticle>
  368.      */
  369.     public function getMetatags(): Collection {
  370.         return $this->metatags;
  371.     }
  372.     public function addMetatag(MetatagArticle $metatag): self {
  373.         if (!$this->metatags->contains($metatag)) {
  374.             $this->metatags[] = $metatag;
  375.             $metatag->setArticle($this);
  376.         }
  377.         return $this;
  378.     }
  379.     public function removeMetatag(MetatagArticle $metatag): self {
  380.         $this->metatags->removeElement($metatag);
  381.         return $this;
  382.     }
  383. }