<?php
namespace Boab\CmsBundle\Entity;
use Boab\CmsBundle\Entity\Media;
use Boab\CmsBundle\Contract\ThumbnailInterface;
use Boab\CmsBundle\Contract\ThumbnailTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Boab\CmsBundle\Entity\UserRelationInterface;
use Boab\CmsBundle\Entity\User;
use Boab\CmsBundle\Model\SeoInterface;
use Boab\CmsBundle\Model\SeoTrait;
/**
* @ORM\Entity (repositoryClass="Boab\CmsBundle\Repository\ContentRepository")
* @ORM\Table(name="contents")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="content_type", type="string")
*/
abstract class Content implements ContentInterface, UserRelationInterface, SeoInterface, ThumbnailInterface
{
protected $dateformat = 'Y-m-d H:i:s';
use ThumbnailTrait;
use SeoTrait;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="unique_id", type="string", nullable=true, unique=true)
*/
protected $uniqueId;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255, precision=0, scale=0, nullable=false, unique=false)
*/
protected $title;
/**
* @var string
*
* @ORM\Column(name="slug", type="string", length=255, precision=0, scale=0, nullable=false, unique=true)
*/
protected $slug;
/**
* @var string
*
* @ORM\Column(name="summary", type="text", precision=0, scale=0, nullable=true, unique=false)
*/
protected $summary;
/**
* @var string
*
* @ORM\Column(name="body", type="text", precision=0, scale=0, nullable=true, unique=false)
*/
protected $body;
/**
* @var string
*
* @ORM\Column(name="thumbnail", type="string", length=255, precision=0, scale=0, nullable=true, unique=false)
*/
protected $thumbnail;
/**
* @var integer
*
* @ORM\Column(name="status", type="string", length=20, precision=0, scale=0, nullable=false, unique=false)
*/
protected $status;
/**
* @var integer
*
* @ORM\Column(name="is_featured", type="boolean", nullable=true)
*/
protected $isFeatured=null;
/**
* @var integer
*
* @ORM\Column(name="promoted", type="boolean", nullable=true)
*/
protected $promoted;
/**
* @var integer
*
* @ORM\Column(name="publish_on_socialmedia", type="boolean", nullable=true)
*/
protected $publishOnSocialMedia;
/**
* @var integer
*
* @ORM\Column(name="is_published_social_media", type="boolean", nullable=true)
*/
protected $isPublishedOnSocialMedia;
/**
* @var integer
*
* @ORM\Column(name="is_home", type="boolean", nullable=true)
*/
protected $isHome;
/**
* @var \DateTime
*
* @ORM\Column(name="date_created", type="datetime", precision=0, scale=0, nullable=false)
*/
protected $dateCreated;
/**
* @var \DateTime
*
* @ORM\Column(name="date_published", type="datetime", precision=0, scale=0, nullable=true)
*/
protected $datePublished;
/**
* @var string
*
* @ORM\Column(name="meta_keywords", type="string", length=255, precision=0, scale=0, nullable=true, unique=false)
*/
protected $metaKeywords;
/**
* @var string
*
* @ORM\Column(name="meta_description", type="string", length=255, precision=0, scale=0, nullable=true, unique=false)
*/
protected $metaDescription;
/**
* @var \Boab\CmsBundle\Entity\UserAdmin
*
* @ORM\ManyToOne(targetEntity="Boab\CmsBundle\Entity\User", inversedBy="contents")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
* })
*/
protected $user;
/**
*
* @ORM\ManyToOne(targetEntity="Boab\CmsBundle\Entity\Term", fetch="EAGER")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="term_id", referencedColumnName="id", nullable=true)
* })
*/
protected $term;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="Boab\CmsBundle\Entity\Photo", mappedBy="content", cascade={"persist","remove"}, orphanRemoval=true)
*/
protected $photos;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $position;
/**
* @ORM\OneToMany(targetEntity=Media::class, mappedBy="content")
*/
private $medias;
/**
* Constructor
*/
public function __construct()
{
$this->photos = new \Doctrine\Common\Collections\ArrayCollection();
$this->medias = new ArrayCollection();
}
/**
* Add photo
*
* @param \Boab\CmsBundle\Entity\Photo $photo
*
* @return Content
*/
public function addPhoto(\Boab\CmsBundle\Entity\Photo $photo)
{
$this->photos[] = $photo;
return $this;
}
/**
* Remove photo
*
* @param \Boab\CmsBundle\Entity\Photo $photo
*/
public function removePhoto(\Boab\CmsBundle\Entity\Photo $photo)
{
$this->photos->removeElement($photo);
}
/**
* Get photos
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getPhotos()
{
return $this->photos;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set uniqueId.
*
* @param string $uniqueId
*
* @return Content
*/
public function setUniqueId($uniqueId)
{
$this->uniqueId = $uniqueId;
return $this;
}
/**
* Get uniqueId.
*
* @return string
*/
public function getUniqueId()
{
return $this->uniqueId;
}
/**
* Set title
*
* @param string $title
* @return Page
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set slug
*
* @param string $slug
* @return Page
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* Set summary
*
* @param string $summary
* @return Page
*/
public function setSummary($summary)
{
$this->summary = $summary;
return $this;
}
/**
* Get summary
*
* @return string
*/
public function getSummary()
{
return $this->summary;
}
/**
* Set body
*
* @param string $body
* @return Content
*/
public function setBody($body)
{
$this->body = $body;
return $this;
}
/**
* Get body
*
* @return string
*/
public function getBody()
{
return $this->body;
}
/**
* Set user
*
* @param \Boab\CmsBundle\Entity\User $user
* @return Page
*/
public function setUser(User $user)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return \Boab\CmsBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
/**
* Set status
*
* @param integer $status
* @return Page
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* Get status
*
* @return integer
*/
public function getStatus()
{
return $this->status;
}
/**
* Set isFeatured
*
* @param integer $isFeatured
* @return Content
*/
public function setIsFeatured($isFeatured)
{
$this->isFeatured = !empty($isFeatured) ? 1 : 0;
return $this;
}
/**
* Get isFeatured
*
* @return integer
*/
public function getIsFeatured()
{
return $this->isFeatured;
}
public function isFeatured()
{
return (bool) $this->getIsFeatured();
}
/**
* Set promoted
*
* @param integer $promoted
* @return Content
*/
public function setPromoted($promoted='')
{
$this->promoted = !empty($promoted) ? 1 : 0;
return $this;
}
/**
* Get promoted
*
* @return integer
*/
public function getPromoted()
{
return $this->promoted;
}
public function isPromoted()
{
return (bool) $this->getPromoted();
}
/**
* Set isHome
*
* @param boolean $isHome
*
* @return Content
*/
public function setIsHome($isHome)
{
$this->isHome = $isHome;
return $this;
}
/**
* Get isHome
*
* @return boolean
*/
public function getIsHome()
{
return $this->isHome;
}
/**
* Set dateCreated
*
* @param \DateTime $dateCreated
* @return Page
*/
public function setDateCreated($dateCreated)
{
$this->dateCreated = $dateCreated;
return $this;
}
/**
* Get dateCreated
*
* @return \DateTime
*/
public function getDateCreated()
{
return $this->dateCreated->format($this->dateformat);
}
/**
* Set datePublished
*
* @param \DateTime $datePublished
* @return Page
*/
public function setDatePublished($datePublished = null)
{
$this->datePublished = $datePublished;
return $this;
}
/**
* Get datePublished
*
* @return \DateTime
*/
public function getDatePublished()
{
return $this->datePublished;
}
/**
* Set metaKeyWords
*
* @param string $metaKeyWords
*
* @return Content
*/
public function setMetaKeywords($metaKeywords)
{
$this->metaKeywords = $metaKeywords;
return $this;
}
/**
* Get metaKeyWords
*
* @return string
*/
public function getMetaKeyWords()
{
return $this->metaKeywords;
}
/**
* Set metaDescription
*
* @param string $metaDescription
*
* @return Content
*/
public function setMetaDescription($metaDescription)
{
$this->metaDescription = $metaDescription;
return $this;
}
/**
* Get metaDescription
*
* @return string
*/
public function getMetaDescription()
{
return $this->metaDescription;
}
/**
* Set term
*
* @param \Boab\CmsBundle\Entity\Term $term
*
* @return Content
*/
public function setTerm(\Boab\CmsBundle\Entity\Term $term = null)
{
$this->term = $term;
return $this;
}
/**
* Get term
*
* @return \Boab\CmsBundle\Entity\Term
*/
public function getTerm()
{
return $this->term;
}
/**
* Remove all user Roles
*/
public function removeAllPhotos()
{
$this->photos->clear();
}
public function getAuthoredBy()
{
if(null == $this->getUser()){
return;
}
return $this->getUser()->getFullName();
}
public function isPublished()
{
return (self::STATUS_PUBLISHED == $this->getStatus());
}
/**
* Set publishOnSocialMedia.
*
* @param bool|null $publishOnSocialMedia
*
* @return Content
*/
public function setPublishOnSocialMedia($publishOnSocialMedia = null)
{
$this->publishOnSocialMedia = $publishOnSocialMedia;
return $this;
}
/**
* Get publishOnSocialMedia.
*
* @return bool|null
*/
public function getPublishOnSocialMedia()
{
return $this->publishOnSocialMedia;
}
/**
* Set isPublishedOnSocialMedia.
*
* @param bool|null $isPublishedOnSocialMedia
*
* @return Content
*/
public function setIsPublishedOnSocialMedia($isPublishedOnSocialMedia = null)
{
$this->isPublishedOnSocialMedia = $isPublishedOnSocialMedia;
return $this;
}
/**
* Get isPublishedOnSocialMedia.
*
* @return bool|null
*/
public function getIsPublishedOnSocialMedia()
{
return $this->isPublishedOnSocialMedia;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
/**
* @return Collection<int, Media>
*/
public function getMedias(): Collection
{
return $this->medias;
}
public function addMedia(Media $media): self
{
if (!$this->medias->contains($media)) {
$this->medias[] = $media;
$media->setContent($this);
}
return $this;
}
public function removeMedia(Media $media): self
{
if ($this->medias->removeElement($media)) {
// set the owning side to null (unless already changed)
if ($media->getContent() === $this) {
$media->setContent(null);
}
}
return $this;
}
}