Created
September 12, 2016 16:54
-
-
Save treetop1500/f4d38bf8221af65a27a8618a69d1154d to your computer and use it in GitHub Desktop.
Base Content Entity for Symfony 3 projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Common\ContentBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
use DoctrineExtensions\Taggable\Taggable; | |
use Symfony\Component\Validator\Constraints as Assert; | |
use Symfony\Component\HttpFoundation\File\File; | |
use Vich\UploaderBundle\Mapping\Annotation as Vich; | |
use Gedmo\Mapping\Annotation as Gedmo; | |
use Doctrine\Common\Collections\ArrayCollection; | |
/** | |
* BaseContent | |
* | |
* @ORM\Entity | |
* @ORM\InheritanceType("SINGLE_TABLE") | |
* @ORM\DiscriminatorColumn(name="discr", type="string") | |
* @ORM\DiscriminatorMap({ | |
* "page" = "Common\ContentBundle\Entity\Page", | |
* "product" = "Common\ContentBundle\Entity\Product", | |
* }) | |
* | |
* @Vich\Uploadable | |
* @ORM\HasLifecycleCallbacks() | |
*/ | |
abstract class BaseContent implements Taggable | |
{ | |
/** | |
* @var int | |
* | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
protected $id; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="title", type="string", length=255, unique=true) | |
* @Assert\NotBlank(message="This is a required field.") | |
*/ | |
private $title; | |
/** | |
* @Gedmo\Slug(fields={"title"}) | |
* @ORM\Column(length=128, unique=true) | |
*/ | |
private $slug; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="body", type="text", nullable=true) | |
*/ | |
private $body; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="status", type="string", length=32) | |
* @Assert\NotBlank(message="This is a required field.") | |
*/ | |
private $status; | |
/** | |
* @var int | |
* | |
* @ORM\Column(name="sortOrder", type="integer", nullable=true) | |
*/ | |
private $sortOrder; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="meta_title", type="string", length=255, nullable=true) | |
*/ | |
private $metaTitle; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="meta_description", type="text", nullable=true) | |
*/ | |
private $metaDescription; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="og_title", type="string", length=255, nullable=true) | |
*/ | |
private $ogTitle; | |
/** | |
* @Vich\UploadableField(mapping="og_image", fileNameProperty="ogImagePath") | |
* | |
* @var File | |
*/ | |
private $ogImageFile; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="og_image_path", type="string", length=255, nullable=true) | |
*/ | |
private $ogImagePath; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="og_description", type="text", nullable=true) | |
*/ | |
private $ogDescription; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="head_content", type="text", nullable=true) | |
*/ | |
private $headContent; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="foot_content", type="text", nullable=true) | |
*/ | |
private $footContent; | |
/** | |
* @ORM\Column(type="datetime") | |
* | |
* @var \DateTime | |
*/ | |
private $createdAt; | |
/** | |
* @ORM\Column(type="datetime") | |
* | |
* @var \DateTime | |
*/ | |
private $updatedAt; | |
/** | |
* @var string $createdBy | |
* | |
* @Gedmo\Blameable(on="create") | |
* @ORM\Column | |
*/ | |
private $createdBy; | |
/** | |
* @var string $updatedBy | |
* | |
* @Gedmo\Blameable(on="update") | |
* @ORM\Column | |
*/ | |
private $updatedBy; | |
/** | |
* @var | |
*/ | |
private $tags; | |
/** | |
* BaseContent constructor. | |
*/ | |
public function __construct() { | |
} | |
/** | |
* Get id | |
* | |
* @return int | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* Set title | |
* | |
* @param string $title | |
* | |
* @return BaseContent | |
*/ | |
public function setTitle($title) | |
{ | |
$this->title = $title; | |
return $this; | |
} | |
/** | |
* Get title | |
* | |
* @return string | |
*/ | |
public function getTitle() | |
{ | |
return $this->title; | |
} | |
/** | |
* @return string | |
*/ | |
public function getBody() | |
{ | |
return $this->body; | |
} | |
/** | |
* @param string $body | |
*/ | |
public function setBody($body) | |
{ | |
$this->body = $body; | |
} | |
/** | |
* Set status | |
* | |
* @param string $status | |
* | |
* @return BaseContent | |
*/ | |
public function setStatus($status) | |
{ | |
$this->status = $status; | |
return $this; | |
} | |
/** | |
* Get status | |
* | |
* @return string | |
*/ | |
public function getStatus() | |
{ | |
return $this->status; | |
} | |
/** | |
* Set metaTitle | |
* | |
* @param string $metaTitle | |
* | |
* @return BaseContent | |
*/ | |
public function setMetaTitle($metaTitle) | |
{ | |
$this->metaTitle = $metaTitle; | |
return $this; | |
} | |
/** | |
* Get metaTitle | |
* | |
* @return string | |
*/ | |
public function getMetaTitle() | |
{ | |
return $this->metaTitle; | |
} | |
/** | |
* Set metaDescription | |
* | |
* @param string $metaDescription | |
* | |
* @return BaseContent | |
*/ | |
public function setMetaDescription($metaDescription) | |
{ | |
$this->metaDescription = $metaDescription; | |
return $this; | |
} | |
/** | |
* Get metaDescription | |
* | |
* @return string | |
*/ | |
public function getMetaDescription() | |
{ | |
return $this->metaDescription; | |
} | |
/** | |
* Set ogTitle | |
* | |
* @param string $ogTitle | |
* | |
* @return BaseContent | |
*/ | |
public function setOgTitle($ogTitle) | |
{ | |
$this->ogTitle = $ogTitle; | |
return $this; | |
} | |
/** | |
* Get ogTitle | |
* | |
* @return string | |
*/ | |
public function getOgTitle() | |
{ | |
return $this->ogTitle; | |
} | |
/** | |
* Set ogDescription | |
* | |
* @param string $ogDescription | |
* | |
* @return BaseContent | |
*/ | |
public function setOgDescription($ogDescription) | |
{ | |
$this->ogDescription = $ogDescription; | |
return $this; | |
} | |
/** | |
* Get ogDescription | |
* | |
* @return string | |
*/ | |
public function getOgDescription() | |
{ | |
return $this->ogDescription; | |
} | |
/** | |
* Set headContent | |
* | |
* @param string $headContent | |
* | |
* @return BaseContent | |
*/ | |
public function setHeadContent($headContent) | |
{ | |
$this->headContent = $headContent; | |
return $this; | |
} | |
/** | |
* Get headContent | |
* | |
* @return string | |
*/ | |
public function getHeadContent() | |
{ | |
return $this->headContent; | |
} | |
/** | |
* Set footContent | |
* | |
* @param string $footContent | |
* | |
* @return BaseContent | |
*/ | |
public function setFootContent($footContent) | |
{ | |
$this->footContent = $footContent; | |
return $this; | |
} | |
/** | |
* Get footContent | |
* | |
* @return string | |
*/ | |
public function getFootContent() | |
{ | |
return $this->footContent; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getSlug() | |
{ | |
return $this->slug; | |
} | |
/** | |
* @param mixed $slug | |
*/ | |
public function setSlug($slug) | |
{ | |
$this->slug = $slug; | |
} | |
/** | |
* Set ogImagePath | |
* | |
* @param string $ogImagePath | |
* | |
* @return BaseContent | |
*/ | |
public function setOgImagePath($ogImagePath) | |
{ | |
$this->ogImagePath = $ogImagePath; | |
return $this; | |
} | |
/** | |
* Get ogImagePath | |
* | |
* @return string | |
*/ | |
public function getOgImagePath() | |
{ | |
return $this->ogImagePath; | |
} | |
/** | |
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance | |
* of 'UploadedFile' is injected into this setter to trigger the update. If this | |
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter | |
* must be able to accept an instance of 'File' as the bundle will inject one here | |
* during Doctrine hydration. | |
* | |
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $ogImage | |
* | |
* @return BaseContent | |
*/ | |
public function setOgImageFile(File $ogImage = null) | |
{ | |
$this->ogImageFile = $ogImage; | |
if ($ogImage) { | |
$this->setUpdatedAt(new \DateTime('now')); | |
} | |
return $this; | |
} | |
/** | |
* @return File | |
*/ | |
public function getOgImageFile() | |
{ | |
return $this->ogImageFile; | |
} | |
/** | |
* Set sortOrder | |
* | |
* @param integer $sortOrder | |
* | |
* @return BaseContent | |
*/ | |
public function setSortOrder($sortOrder) | |
{ | |
$this->sortOrder = $sortOrder; | |
return $this; | |
} | |
/** | |
* Get sortOrder | |
* | |
* @return int | |
*/ | |
public function getSortOrder() | |
{ | |
return $this->sortOrder; | |
} | |
/** | |
* @param \DateTime $createdAt | |
*/ | |
public function setCreatedAt($createdAt) | |
{ | |
$this->createdAt = $createdAt; | |
} | |
/** | |
* @return \DateTime | |
*/ | |
public function getCreatedAt() | |
{ | |
return $this->createdAt; | |
} | |
/** | |
* @param \DateTime $updatedAt | |
*/ | |
public function setUpdatedAt($updatedAt) | |
{ | |
$this->updatedAt = $updatedAt; | |
} | |
/** | |
* @return \DateTime | |
*/ | |
public function getUpdatedAt() | |
{ | |
return $this->updatedAt; | |
} | |
/** | |
* @return string | |
*/ | |
public function getCreatedBy() | |
{ | |
return $this->createdBy; | |
} | |
/** | |
* @param string $createdBy | |
*/ | |
public function setCreatedBy($createdBy) | |
{ | |
$this->createdBy = $createdBy; | |
} | |
/** | |
* @return string | |
*/ | |
public function getUpdatedBy() | |
{ | |
return $this->updatedBy; | |
} | |
/** | |
* @param string $updatedBy | |
*/ | |
public function setUpdatedBy($updatedBy) | |
{ | |
$this->updatedBy = $updatedBy; | |
} | |
/** | |
* @ORM\PrePersist | |
*/ | |
public function prePersist(){ | |
$this->setCreatedAt(new \DateTime); | |
$this->setUpdatedAt(new \DateTime); | |
} | |
/** | |
* @ORM\PreUpdate | |
*/ | |
public function preUpdate(){ | |
$this->setUpdatedAt(new \DateTime); | |
} | |
public function getTags() | |
{ | |
$this->tags = $this->tags ?: new ArrayCollection(); | |
return $this->tags; | |
} | |
public function getTaggableType() | |
{ | |
return 'acme_tag'; | |
} | |
public function getTaggableId() | |
{ | |
return $this->getId(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment