src/Entity/Post.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PostRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Symfony\Component\HttpFoundation\File\File;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12.  * @Vich\Uploadable
  13.  * @ORM\Entity(repositoryClass=PostRepository::class)
  14.  */
  15. class Post
  16. {
  17.     public function __toString()
  18.     {
  19.         return "#" $this->id " " $this->getTitle();
  20.     }
  21.     /**
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue
  24.      * @ORM\Column(type="integer")
  25.      */
  26.     private $id;
  27.     /**
  28.      * @ORM\Column(type="string", length=255, nullable=true)
  29.      */
  30.     private $title;
  31.     /**
  32.      * @ORM\Column(type="text", nullable=true)
  33.      */
  34.     private $intro;
  35.     /**
  36.      * @ORM\Column(type="datetime", nullable=true)
  37.      */
  38.     private $date;
  39.     /**
  40.      * @ORM\OneToMany(targetEntity=Paragraph::class, mappedBy="post")
  41.      */
  42.     private $paragraphs;
  43.     /**
  44.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  45.      * @Vich\UploadableField(mapping="post", fileNameProperty="postFileName", size="postFileSize")
  46.      * @Assert\Expression("this.getPostFile() or this.getPostFileName()", message = "Veuillez sélectionner un fichier")
  47.      * @Assert\File(
  48.      *     maxSize = "1200k"
  49.      * )
  50.      *
  51.      * @var File
  52.      */
  53.     private $postFile;
  54.     /**
  55.      * @ORM\Column(type="string", length=255, nullable=true)
  56.      *
  57.      * @var string
  58.      */
  59.     private $postFileName;
  60.     /**
  61.      * @ORM\Column(type="integer", nullable=true)
  62.      *
  63.      * @var integer
  64.      */
  65.     private $postFileSize;
  66.     /**
  67.      * @ORM\Column(type="datetime", nullable=true)
  68.      *
  69.      * @var \DateTime
  70.      */
  71.     private $postFileUpdatedAt;
  72.     /**
  73.      * @ORM\Column(type="string", length=255, nullable=true)
  74.      */
  75.     private $metaTitle;
  76.     /**
  77.      * @ORM\Column(type="string", length=255, nullable=true)
  78.      */
  79.     private $metaDescription;
  80.     /**
  81.      * @Gedmo\Slug(fields={"title"})
  82.      * @ORM\Column(type="string", length=255, nullable=true)
  83.      */
  84.     private $slug;
  85.     /**
  86.      * @ORM\Column(type="boolean", nullable=true)
  87.      */
  88.     private $isPublished;
  89.     /**
  90.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  91.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  92.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  93.      * must be able to accept an instance of 'File' as the bundle will inject one here
  94.      * during Doctrine hydration.
  95.      *
  96.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  97.      */
  98.     public function setPostFile(File $image null)
  99.     {
  100.         $this->postFile $image;
  101.         if (null !== $image) {
  102.             // It is required that at least one field changes if you are using doctrine
  103.             // otherwise the event listeners won't be called and the file is lost
  104.             $this->postFileUpdatedAt = new \DateTimeImmutable();
  105.         }
  106.     }
  107.     public function getPostFile()
  108.     {
  109.         return $this->postFile;
  110.     }
  111.     public function getPostFileName(): ?string
  112.     {
  113.         return $this->postFileName;
  114.     }
  115.     public function setPostFileName(?string $postFileName): self
  116.     {
  117.         $this->postFileName $postFileName;
  118.         return $this;
  119.     }
  120.     public function getPostFileSize(): ?int
  121.     {
  122.         return $this->postFileSize;
  123.     }
  124.     public function setPostFileSize(?int $postFileSize): self
  125.     {
  126.         $this->postFileSize $postFileSize;
  127.         return $this;
  128.     }
  129.     public function getPostFileUpdatedAt(): ?\DateTimeInterface
  130.     {
  131.         return $this->postFileUpdatedAt;
  132.     }
  133.     public function setPostFileUpdatedAt(?\DateTimeInterface $postFileUpdatedAt): self
  134.     {
  135.         $this->postFileUpdatedAt $postFileUpdatedAt;
  136.         return $this;
  137.     }
  138.     public function __construct()
  139.     {
  140.         $this->paragraphs = new ArrayCollection();
  141.     }
  142.     public function getId(): ?int
  143.     {
  144.         return $this->id;
  145.     }
  146.     public function getTitle(): ?string
  147.     {
  148.         return $this->title;
  149.     }
  150.     public function setTitle(?string $title): self
  151.     {
  152.         $this->title $title;
  153.         return $this;
  154.     }
  155.     public function getIntro(): ?string
  156.     {
  157.         return $this->intro;
  158.     }
  159.     public function setIntro(?string $intro): self
  160.     {
  161.         $this->intro $intro;
  162.         return $this;
  163.     }
  164.     public function getDate(): ?\DateTimeInterface
  165.     {
  166.         return $this->date;
  167.     }
  168.     public function setDate(?\DateTimeInterface $date): self
  169.     {
  170.         $this->date $date;
  171.         return $this;
  172.     }
  173.     /**
  174.      * @return Collection|Paragraph[]
  175.      */
  176.     public function getParagraphs(): Collection
  177.     {
  178.         return $this->paragraphs;
  179.     }
  180.     public function addParagraph(Paragraph $paragraph): self
  181.     {
  182.         if (!$this->paragraphs->contains($paragraph)) {
  183.             $this->paragraphs[] = $paragraph;
  184.             $paragraph->setPost($this);
  185.         }
  186.         return $this;
  187.     }
  188.     public function removeParagraph(Paragraph $paragraph): self
  189.     {
  190.         if ($this->paragraphs->removeElement($paragraph)) {
  191.             // set the owning side to null (unless already changed)
  192.             if ($paragraph->getPost() === $this) {
  193.                 $paragraph->setPost(null);
  194.             }
  195.         }
  196.         return $this;
  197.     }
  198.     public function getMetaTitle(): ?string
  199.     {
  200.         return $this->metaTitle;
  201.     }
  202.     public function setMetaTitle(?string $metaTitle): self
  203.     {
  204.         $this->metaTitle $metaTitle;
  205.         return $this;
  206.     }
  207.     public function getMetaDescription(): ?string
  208.     {
  209.         return $this->metaDescription;
  210.     }
  211.     public function setMetaDescription(?string $metaDescription): self
  212.     {
  213.         $this->metaDescription $metaDescription;
  214.         return $this;
  215.     }
  216.     public function getSlug(): ?string
  217.     {
  218.         return $this->slug;
  219.     }
  220.     public function setSlug(?string $slug): self
  221.     {
  222.         $this->slug $slug;
  223.         return $this;
  224.     }
  225.     public function getIsPublished(): ?bool
  226.     {
  227.         return $this->isPublished;
  228.     }
  229.     public function setIsPublished(?bool $isPublished): self
  230.     {
  231.         $this->isPublished $isPublished;
  232.         return $this;
  233.     }
  234. }