src/Entity/Gallery.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\GalleryRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  6. use Symfony\Component\HttpFoundation\File\File;
  7. use DateTimeImmutable;
  8. #[ORM\Entity(repositoryClassGalleryRepository::class)]
  9. #[Vich\Uploadable]
  10. class Gallery
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\ManyToOne(inversedBy'galleries')]
  17.     private ?Product $product null;
  18.     #[ORM\Column(length255)]
  19.     private ?string $imageName null;
  20.     #[Vich\UploadableField(mapping'product_imagenes'fileNameProperty'imageName')]
  21.     private ?File $imageFile null;
  22.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  23.     private ?DateTimeImmutable $updatedAt null;
  24.     public function __toString(){
  25.          return $this->imageName "" ;
  26.     }
  27.     public function getId(): ?int
  28.     {
  29.         return $this->id;
  30.     }
  31.     public function getProduct(): ?Product
  32.     {
  33.         return $this->product;
  34.     }
  35.     public function setProduct(?Product $product): static
  36.     {
  37.         $this->product $product;
  38.         return $this;
  39.     }
  40.     public function getImageName(): ?string
  41.     {
  42.         return $this->imageName;
  43.     }
  44.     public function setImageName(string $imageName): static
  45.     {
  46.         $this->imageName $imageName;
  47.         return $this;
  48.     }
  49.     public function getImageFile(): ?File
  50.     {
  51.         return $this->imageFile;
  52.     }
  53.     public function setImageFile(?File $imageFile null): self
  54.     {
  55.         $this->imageFile $imageFile;
  56.         // Si la imagen ha cambiado, se debe actualizar la fecha de modificación.
  57.         if ($imageFile) {
  58.             $this->updatedAt = new \DateTimeImmutable();
  59.         }
  60.         return $this;
  61.     }
  62.     public function getUpdatedAt(): ?DateTimeImmutable
  63.     {
  64.         return $this->updatedAt;
  65.     }
  66.     public function setUpdatedAt(?DateTimeImmutable $updatedAt): self
  67.     {
  68.         $this->updatedAt $updatedAt;
  69.         return $this;
  70.     }
  71. }