src/Entity/Post.php line 24

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