<?php
namespace Score\CmsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Score\BaseBundle\Entity\BaseEntity;
/**
* @ORM\Entity(repositoryClass="Score\CmsBundle\Repository\ArticleRepository")
* @ORM\Table(name="cms_article")
* @ORM\HasLifecycleCallbacks()
*/
class Article extends BaseEntity {
private static $author_enum = array
(
'1' => '',
'2' => 'SAŽP',
);
private static $categoryEnum = array
(
'score.article.form.category.standard' => 'standard',
'score.article.form.category.flash' => 'flash'
);
public static function getAuthorEnum()
{
return self::$author_enum;
}
public function getAuthorName()
{
return self::$author_enum[$this->getAuthor()];
}
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=500)
*/
protected $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $icon;
/**
* @ORM\Column(type="text", length=2000, nullable=true)
*/
protected $teaser;
/**
* @ORM\Column(type="text", nullable=true)
*/
protected $body;
/**
* @ORM\Column(type="integer")
*/
protected $published;
/**
* @ORM\Column(type="integer")
*/
protected $createdBy;
/**
* @ORM\Column(type="integer", nullable=true)
*/
protected $priority;
/**
* @ORM\Column(type="string", length=200)
*/
protected $author;
/**
* @ORM\Column(type="datetime", name="published_from",nullable=true)
*/
private $publishedFrom;
/**
* @ORM\Column(type="datetime", name="published_to",nullable=true)
*/
private $publishedTo;
/**
* @ORM\Column(type="string")
*/
protected $slug;
/**
* @ORM\Column(type="string",name="seo_title", length=255, nullable=true)
*/
protected $seoTitle;
/**
* @ORM\Column(type="string",length=5000, nullable=true)
*/
protected $metadata;
/**
* @ORM\Column(type="text", nullable=true)
*/
protected $search;
/**
* @ORM\Column(type="string",length=255, nullable=true)
*/
protected $category;
/**
* @ORM\OneToMany(targetEntity="\Score\CmsBundle\Entity\Multisite\SiteItemArticle", mappedBy="article",cascade={"persist","remove"})
*/
private $siteItemArticle = [];
private $multisite;
protected $keywords;
protected $type;
protected $categoryName;
public function getPublishedFrom()
{
return $this->publishedFrom;
}
public function getPublishedTo()
{
return $this->publishedTo;
}
public function getSeoTitle()
{
return $this->seoTitle;
}
public function setPublishedFrom($publishedFrom)
{
$this->publishedFrom = $publishedFrom;
}
public function setPublishedTo($publishedTo)
{
$this->publishedTo = $publishedTo;
}
public function setSeoTitle($seoTitle)
{
$this->seoTitle = $seoTitle;
}
public function __construct()
{
}
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function getIcon()
{
return $this->icon;
}
public function getTeaser()
{
return $this->teaser;
}
public function getBody()
{
return $this->body;
}
public function getPublished()
{
return $this->published;
}
public function getPriority()
{
return $this->priority;
}
public function getAuthor()
{
return $this->author;
}
public function getSlug()
{
return $this->slug;
}
public function setId($id)
{
$this->id = $id;
}
public function setName($name)
{
$this->name = $name;
}
public function setIcon($icon)
{
$this->icon = $icon;
}
public function setTeaser($teaser)
{
$this->teaser = $teaser;
}
public function setBody($body)
{
$this->body = $body;
}
public function setPublished($published)
{
$this->published = $published;
}
public function setPriority($priority)
{
$this->priority = $priority;
}
public function setAuthor($author)
{
$this->author = $author;
}
public function setSlug($slug)
{
$this->slug = $slug;
}
public function __toString()
{
return $this->getName();
}
public function getCreatedBy()
{
return $this->createdBy;
}
public function setCreatedBy($createdBy)
{
$this->createdBy = $createdBy;
}
public function getType()
{
return $this->type;
}
public function setType($type)
{
$this->type = $type;
}
public function getMetadata()
{
return $this->metadata;
}
public function setMetadata($metadata)
{
$this->metadata = $metadata;
}
public function iconThumb($width, $height)
{
if (null == $this->getIcon())
{
return 'default_' . $width . 'x' . $height . '.png';
}
$parts = explode('.', $this->getIcon());
$extension = end($parts);
return str_replace('.' . $extension, '', $this->getIcon()) . '_thumb_' . $width . 'x' . $height . '.' . $extension;
}
public function getPublishedDate($format = 'd.m. Y')
{
if ($this->getPublished() == 1)
{
if (null != $this->getPublishedFrom())
{
return $this->getPublishedFrom()->format($format);
}
else
{
return date($format);
}
}
else
{
return 'nepublikované';
}
}
public function getStrip()
{
return mb_substr(strip_tags($this->getTeaser()), 0, 200) . '...';
}
public function getTeaserStrip($length = 200)
{
$tidy = new \tidy();
$strip = mb_substr($this->getTeaser(), 0, 200) . '...';
$strip = $tidy->repairString($strip,array('show-body-only' => true));
return $strip;
}
private function getMetadataArray()
{
$data = $this->getMetadata();
$arr = json_decode($data,true);
return $arr;
}
/**
* Get the value of search
*/
public function getSearch()
{
return $this->search;
}
/**
* Set the value of search
*
* @return self
*/
public function setSearch($search)
{
$this->search = $search;
return $this;
}
/**
* Get the value of siteItemArticle
*/
public function getSiteItemArticle()
{
return $this->siteItemArticle;
}
/**
* Set the value of siteItemArticle
*
* @return self
*/
public function setSiteItemArticle($siteItemArticle)
{
$this->siteItemArticle = $siteItemArticle;
return $this;
}
/**
* Get the value of multisite
*/
public function getMultisite()
{
return $this->multisite;
}
/**
* Set the value of multisite
*
* @return self
*/
public function setMultisite($multisite)
{
$this->multisite = $multisite;
return $this;
}
/**
* Get the value of category
*/
public function getCategory()
{
return $this->category;
}
/**
* Set the value of category
*
* @return self
*/
public function setCategory($category)
{
$this->category = $category;
return $this;
}
public function getCategoryName()
{
$category = $this->getCategory();
$categoryEnum = array_flip(self::$categoryEnum);
if(array_key_exists($category,$categoryEnum))
{
return $categoryEnum[$category];
}
}
}