<?php
namespace App\Entity;
use App\Repository\GalleryRepository;
use Doctrine\ORM\Mapping as ORM;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\HttpFoundation\File\File;
use DateTimeImmutable;
#[ORM\Entity(repositoryClass: GalleryRepository::class)]
#[Vich\Uploadable]
class Gallery
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'galleries')]
private ?Product $product = null;
#[ORM\Column(length: 255)]
private ?string $imageName = null;
#[Vich\UploadableField(mapping: 'product_imagenes', fileNameProperty: 'imageName')]
private ?File $imageFile = null;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?DateTimeImmutable $updatedAt = null;
public function __toString(){
return $this->imageName . "" ;
}
public function getId(): ?int
{
return $this->id;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): static
{
$this->product = $product;
return $this;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function setImageName(string $imageName): static
{
$this->imageName = $imageName;
return $this;
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function setImageFile(?File $imageFile = null): self
{
$this->imageFile = $imageFile;
// Si la imagen ha cambiado, se debe actualizar la fecha de modificación.
if ($imageFile) {
$this->updatedAt = new \DateTimeImmutable();
}
return $this;
}
public function getUpdatedAt(): ?DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(?DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
}