src/Entity/Post.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Gedmo\Timestampable\Traits\TimestampableEntity;
  6. use JMS\Serializer\Annotation as Serializer;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. /**
  9.  * Class Post
  10.  * @package App\Entity
  11.  *
  12.  * @ORM\Table(name="posts")
  13.  * @ORM\Entity(repositoryClass="App\Repository\PostRepository")
  14.  */
  15. class Post
  16. {
  17.     use TimestampableEntity;
  18.     const STATUS_PUBLISHED 1;
  19.     const STATUS_DRAFT 2;
  20.     const STATUS_NAMES = [
  21.         self::STATUS_PUBLISHED => 'post.status.published',
  22.         self::STATUS_DRAFT => 'post.status.draft',
  23.     ];
  24.     /**
  25.      * @ORM\Id()
  26.      * @ORM\GeneratedValue()
  27.      * @ORM\Column(type="integer")
  28.      */
  29.     protected $id;
  30.     /**
  31.      * @var string
  32.      * @ORM\Column(type="text")
  33.      * @Assert\NotBlank()
  34.      */
  35.     protected $title;
  36.     /**
  37.      * @var string
  38.      * @ORM\Column(type="text")
  39.      * @Assert\NotBlank()
  40.      */
  41.     protected $thumbnail;
  42.     /**
  43.      * @var string
  44.      * @ORM\Column(type="text", nullable=true)
  45.      */
  46.     protected $video;
  47.     /**
  48.      * @var string
  49.      * @ORM\Column(type="text")
  50.      * @Assert\NotBlank()
  51.      */
  52.     protected $excerpt;
  53.     /**
  54.      * @var PostContent[]
  55.      * @ORM\OneToMany(targetEntity="App\Entity\PostContent", mappedBy="post", cascade={"all"}, orphanRemoval=true)
  56.      * @Assert\Valid()
  57.      * @Assert\Count(min="2")
  58.      * @Serializer\Groups("Item")
  59.      */
  60.     protected $contents;
  61.     /**
  62.      * @var int
  63.      * @ORM\Column(type="smallint", options={"default": 1})
  64.      */
  65.     protected $status 1;
  66.     public function __construct()
  67.     {
  68.         $this->contents = new ArrayCollection();
  69.     }
  70.     /**
  71.      * @return mixed
  72.      */
  73.     public function getId()
  74.     {
  75.         return $this->id;
  76.     }
  77.     /**
  78.      * @return string
  79.      */
  80.     public function getTitle()
  81.     {
  82.         return $this->title;
  83.     }
  84.     /**
  85.      * @param string $title
  86.      * @return Post
  87.      */
  88.     public function setTitle(string $title)
  89.     {
  90.         $this->title $title;
  91.         return $this;
  92.     }
  93.     /**
  94.      * @return string
  95.      */
  96.     public function getThumbnail()
  97.     {
  98.         return $this->thumbnail;
  99.     }
  100.     /**
  101.      * @param string $thumbnail
  102.      * @return Post
  103.      */
  104.     public function setThumbnail(string $thumbnail)
  105.     {
  106.         $this->thumbnail $thumbnail;
  107.         return $this;
  108.     }
  109.     /**
  110.      * @return string
  111.      */
  112.     public function getVideo()
  113.     {
  114.         return $this->video;
  115.     }
  116.     /**
  117.      * @param string $video
  118.      * @return Post
  119.      */
  120.     public function setVideo($video)
  121.     {
  122.         $this->video $video;
  123.         return $this;
  124.     }
  125.     /**
  126.      * @return string
  127.      */
  128.     public function getExcerpt()
  129.     {
  130.         return $this->excerpt;
  131.     }
  132.     /**
  133.      * @param string $excerpt
  134.      * @return Post
  135.      */
  136.     public function setExcerpt(string $excerpt)
  137.     {
  138.         $this->excerpt $excerpt;
  139.         return $this;
  140.     }
  141.     /**
  142.      * @return PostContent[]
  143.      */
  144.     public function getContents()
  145.     {
  146.         return $this->contents;
  147.     }
  148.     /**
  149.      * @param PostContent[] $contents
  150.      * @return Post
  151.      */
  152.     public function setContents(array $contents)
  153.     {
  154.         $this->contents $contents;
  155.         return $this;
  156.     }
  157.     /**
  158.      * @param PostContent $content
  159.      * @return Post
  160.      */
  161.     public function addContent($content)
  162.     {
  163.         if (!$this->contents->contains($content)) {
  164.             $this->contents->add($content);
  165.             $content->setPost($this);
  166.         }
  167.         return $this;
  168.     }
  169.     /**
  170.      * @param PostContent $content
  171.      * @return Post
  172.      */
  173.     public function removeContent($content)
  174.     {
  175.         if ($this->contents->contains($content)) {
  176.             $this->contents->removeElement($content);
  177.         }
  178.         return $this;
  179.     }
  180.     /**
  181.      * @return int
  182.      */
  183.     public function getStatus()
  184.     {
  185.         return $this->status;
  186.     }
  187.     /**
  188.      * @param int $status
  189.      * @return Post
  190.      */
  191.     public function setStatus(int $status)
  192.     {
  193.         $this->status $status;
  194.         return $this;
  195.     }
  196. }