src/Entity/Distinctions/Distinctions.php line 25

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