src/Entity/Celebrites.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Common\DatesTrait;
  4. use App\Entity\Common\IdTrait;
  5. use App\Entity\Common\OrdreTrait;
  6. use App\Entity\Common\SlugTrait;
  7. use DateTime;
  8. use DateTimeImmutable;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Exception;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Symfony\Component\HttpFoundation\File\UploadedFile;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  16. /**
  17.  * @ORM\Entity(repositoryClass="App\Repository\CelebritesRepository")
  18.  * @UniqueEntity("name")
  19.  * @Vich\Uploadable
  20.  */
  21. class Celebrites
  22. {
  23.     use IdTrait;
  24.     use OrdreTrait;
  25.     use DatesTrait;
  26.     use SlugTrait;
  27.     /**
  28.      * @ORM\Column(type="string", length=255)
  29.      * @Assert\NotBlank(message="Veuillez saisir un nom")
  30.      */
  31.     private $name;
  32.     /**
  33.      * @ORM\Column(type="text", nullable=true)
  34.      */
  35.     private $content;
  36.     /**
  37.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  38.      *
  39.      * @Vich\UploadableField(mapping="celebrites_image", fileNameProperty="filename")
  40.      * @var File|null
  41.      * @Assert\Image(
  42.      *     mimeTypes={"image/jpeg", "image/png"},
  43.      *
  44.      *     maxHeight=1280,
  45.      *     maxWidth=1920,
  46.      *     maxHeightMessage="Votre image doit faire 1280 d'hauteur",
  47.      *     maxWidthMessage="Votre image doit faire 1920 de largeur"
  48.      * )
  49.      */
  50.     private $imageFile;
  51.     /**
  52.      * @ORM\Column(type="string", length=255, nullable=true)
  53.      */
  54.     private $filename;
  55.     /**
  56.      * @ORM\Column(type="boolean")
  57.      */
  58.     private $online;
  59.     public function getName(): ?string
  60.     {
  61.         return $this->name;
  62.     }
  63.     public function setName(string $name): self
  64.     {
  65.         $this->name $name;
  66.         return $this;
  67.     }
  68.     public function getContent(): ?string
  69.     {
  70.         return $this->content;
  71.     }
  72.     public function setContent(?string $content): self
  73.     {
  74.         $this->content $content;
  75.         return $this;
  76.     }
  77.     /**
  78.      * @return File|null
  79.      */
  80.     public function getImageFile(): ?File
  81.     {
  82.         return $this->imageFile;
  83.     }
  84.     /**
  85.      * @param File|null $imageFile
  86.      * @return Celebrites
  87.      * @throws Exception
  88.      */
  89.     public function setImageFile(?File $imageFile): Celebrites
  90.     {
  91.         $this->imageFile $imageFile;
  92.         if ($this->imageFile instanceof UploadedFile) {
  93.             // It is required that at least one field changes if you are using doctrine
  94.             // otherwise the event listeners won't be called and the file is lost
  95.             $this->updatedAt = new DateTimeImmutable('now');
  96.         }
  97.         return $this;
  98.     }
  99.     public function getFilename(): ?string
  100.     {
  101.         return $this->filename;
  102.     }
  103.     public function setFilename(?string $filename): self
  104.     {
  105.         $this->filename $filename;
  106.         return $this;
  107.     }
  108.     public function getOnline(): ?bool
  109.     {
  110.         return $this->online;
  111.     }
  112.     public function setOnline(bool $online): self
  113.     {
  114.         $this->online $online;
  115.         return $this;
  116.     }
  117. }