src/Flexy/ShopBundle/Entity/Product/ImageProduct.php line 16

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Product;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Repository\Product\ImageProductRepository;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. /**
  9.  * @Vich\Uploadable
  10.  */
  11. #[ApiResource]
  12. #[ORM\Entity(repositoryClassImageProductRepository::class)]
  13. class ImageProduct
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column(type'integer')]
  18.     private $id;
  19.     #[ORM\Column(type'string'length255)]
  20.     private ?string $path null;
  21.     #[ORM\Column(type'string'length255nullabletrue)]
  22.     private ?string $alt null;
  23.     /**
  24.      * @Vich\UploadableField(mapping="product_images", fileNameProperty="path")
  25.      */
  26.     private ?\Symfony\Component\HttpFoundation\File\File $imageFile null;
  27.     #[ORM\Column(type'datetime',nullable:true)]
  28.     private \DateTime|\DateTimeInterface|null $updatedAt null;
  29.     #[ORM\ManyToOne(targetEntityProduct::class, inversedBy'images'cascade: ['persist'])]
  30.     private ?\App\Flexy\ShopBundle\Entity\Product\Product $product null;
  31.     public function getId(): ?int
  32.     {
  33.         return $this->id;
  34.     }
  35.     public function getPath(): ?string
  36.     {
  37.         return $this->path;
  38.     }
  39.     public function setPath(string $path): self
  40.     {
  41.         $this->path $path;
  42.         return $this;
  43.     }
  44.     public function setImageFile(File $path null)
  45.     {
  46.         $this->imageFile $path;
  47.         // VERY IMPORTANT:
  48.         // It is required that at least one field changes if you are using Doctrine,
  49.         // otherwise the event listeners won't be called and the file is lost
  50.         if ($path) {
  51.             // if 'updatedAt' is not defined in your entity, use another property
  52.             $this->updatedAt = new \DateTime('now');
  53.         }
  54.     }
  55.     public function getImageFile()
  56.     {
  57.         return $this->imageFile;
  58.     }
  59.     public function getAlt(): ?string
  60.     {
  61.         return $this->alt;
  62.     }
  63.     public function setAlt(?string $alt): self
  64.     {
  65.         $this->alt $alt;
  66.         return $this;
  67.     }
  68.     public function getProduct(): ?Product
  69.     {
  70.         return $this->product;
  71.     }
  72.     public function setProduct(?Product $product): self
  73.     {
  74.         $this->product $product;
  75.         return $this;
  76.     }
  77.     public function getUpdatedAt(): ?\DateTimeInterface
  78.     {
  79.         return $this->updatedAt;
  80.     }
  81.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  82.     {
  83.         $this->updatedAt $updatedAt;
  84.         return $this;
  85.     }
  86. }