src/Entity/Media.php line 16

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\Timestamp;
  4. use App\Repository\MediaRepository;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\HttpFoundation\File\File;
  7. use Symfony\Component\HttpFoundation\File\UploadedFile;
  8. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. #[ORM\Entity(repositoryClassMediaRepository::class)]
  11. #[ORM\HasLifecycleCallbacks]
  12. #[Vich\Uploadable]
  13. class Media
  14. {
  15.     use Timestamp;
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column]
  19.     private ?int $id null;
  20.     /**
  21.      * @var File|null
  22.      **/
  23.     #[Assert\Image(maxSize'50M'maxSizeMessage'Image trop volumineuse maximum 10Mb')]
  24.     #[Assert\Image(mimeTypes: ["image/jpeg""image/jpg""image/png"], mimeTypesMessage"Mauvais format d'image (jpeg, jpg et png)")]
  25.     #[Vich\UploadableField(mapping'medias'fileNameProperty'image')]
  26.     private $imageFile;
  27.     #[ORM\Column(length255nullabletrue)]
  28.     private ?string $image null;
  29.     #[ORM\ManyToOne(inversedBy'medias')]
  30.     private ?Projet $projets null;
  31.     public function getId(): ?int
  32.     {
  33.         return $this->id;
  34.     }
  35.     public function getImage(): ?string
  36.     {
  37.         return $this->image;
  38.     }
  39.     public function setImage(?string $image): self
  40.     {
  41.         $this->image $image;
  42.         return $this;
  43.     }
  44.     public function getProjets(): ?Projet
  45.     {
  46.         return $this->projets;
  47.     }
  48.     public function setProjets(?Projet $projets): self
  49.     {
  50.         $this->projets $projets;
  51.         return $this;
  52.     }
  53.     /**
  54.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
  55.      */
  56.     public function setImageFile(?File $imageFile null): void
  57.     {
  58.         $this->imageFile $imageFile;
  59.         if (null !== $imageFile) {
  60.             // It is required that at least one field changes if you are using doctrine
  61.             // otherwise the event listeners won't be called and the file is lost
  62.             $this->setUpdated(new \DateTimeImmutable());
  63.         }
  64.     }
  65.     public function getImageFile(): ?File
  66.     {
  67.         return $this->imageFile;
  68.     }
  69. }