<?phpnamespace App\Entity;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\ORM\Mapping as ORM;use Gedmo\Timestampable\Traits\TimestampableEntity;use JMS\Serializer\Annotation as Serializer;use Symfony\Component\Validator\Constraints as Assert;/** * Class Post * @package App\Entity * * @ORM\Table(name="posts") * @ORM\Entity(repositoryClass="App\Repository\PostRepository") */class Post{ use TimestampableEntity; const STATUS_PUBLISHED = 1; const STATUS_DRAFT = 2; const STATUS_NAMES = [ self::STATUS_PUBLISHED => 'post.status.published', self::STATUS_DRAFT => 'post.status.draft', ]; /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ protected $id; /** * @var string * @ORM\Column(type="text") * @Assert\NotBlank() */ protected $title; /** * @var string * @ORM\Column(type="text") * @Assert\NotBlank() */ protected $thumbnail; /** * @var string * @ORM\Column(type="text", nullable=true) */ protected $video; /** * @var string * @ORM\Column(type="text") * @Assert\NotBlank() */ protected $excerpt; /** * @var PostContent[] * @ORM\OneToMany(targetEntity="App\Entity\PostContent", mappedBy="post", cascade={"all"}, orphanRemoval=true) * @Assert\Valid() * @Assert\Count(min="2") * @Serializer\Groups("Item") */ protected $contents; /** * @var int * @ORM\Column(type="smallint", options={"default": 1}) */ protected $status = 1; public function __construct() { $this->contents = new ArrayCollection(); } /** * @return mixed */ public function getId() { return $this->id; } /** * @return string */ public function getTitle() { return $this->title; } /** * @param string $title * @return Post */ public function setTitle(string $title) { $this->title = $title; return $this; } /** * @return string */ public function getThumbnail() { return $this->thumbnail; } /** * @param string $thumbnail * @return Post */ public function setThumbnail(string $thumbnail) { $this->thumbnail = $thumbnail; return $this; } /** * @return string */ public function getVideo() { return $this->video; } /** * @param string $video * @return Post */ public function setVideo($video) { $this->video = $video; return $this; } /** * @return string */ public function getExcerpt() { return $this->excerpt; } /** * @param string $excerpt * @return Post */ public function setExcerpt(string $excerpt) { $this->excerpt = $excerpt; return $this; } /** * @return PostContent[] */ public function getContents() { return $this->contents; } /** * @param PostContent[] $contents * @return Post */ public function setContents(array $contents) { $this->contents = $contents; return $this; } /** * @param PostContent $content * @return Post */ public function addContent($content) { if (!$this->contents->contains($content)) { $this->contents->add($content); $content->setPost($this); } return $this; } /** * @param PostContent $content * @return Post */ public function removeContent($content) { if ($this->contents->contains($content)) { $this->contents->removeElement($content); } return $this; } /** * @return int */ public function getStatus() { return $this->status; } /** * @param int $status * @return Post */ public function setStatus(int $status) { $this->status = $status; return $this; }}