src/Entity/CategoriProduct.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoriProductRepository;
  4. use DateTimeImmutable;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\HttpFoundation\File\File;
  7. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  8. /**
  9.  * @ORM\Entity(repositoryClass=CategoriProductRepository::class)
  10.  * @Vich\Uploadable
  11.  */
  12. class CategoriProduct
  13. {
  14.     public const MAX_IMAGE_FILESIZE 2097152// 2MB
  15.     public const MESSAGE_IMAGE_FILESIZE "La taille maximale d'image autorisée est de 2MB.";
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      */
  25.     private $title;
  26.      /**
  27.      * @ORM\Column(type="string", length=255, nullable=true)
  28.      */
  29.     private $imageName;
  30.     /**
  31.      * @Vich\UploadableField(mapping="categorie_image", fileNameProperty="imageName")
  32.      * @var File|null
  33.      */
  34.     private $imageFile;
  35.     public function getId(): ?int
  36.     {
  37.         return $this->id;
  38.     }
  39.     public function getTitle(): ?string
  40.     {
  41.         return $this->title;
  42.     }
  43.     public function setTitle(string $title): self
  44.     {
  45.         $this->title $title;
  46.         return $this;
  47.     }
  48.     public function getImageName(): ?string
  49.     {
  50.         return $this->imageName;
  51.     }
  52.     public function setImageName(string $imageName): self
  53.     {
  54.         $this->imageName $imageName;
  55.         return $this;
  56.     }
  57.     public function getImageFile(): ?File
  58.     {
  59.         return $this->imageFile;
  60.     }
  61.     public function setImageFile(?File $imageFile): self
  62.     {
  63.         $this->imageFile $imageFile;
  64.         if ($imageFile) {
  65.             // It is required that at least one field changes if you are using doctrine
  66.             // otherwise the event listeners won't be called and the file is lost
  67.             $this->updatedAt = new DateTimeImmutable();
  68.         }
  69.         return $this;
  70.     }
  71. }