✨ feat(Product): Ajoute la gestion des images des produits avec VichUploader.
This commit is contained in:
@@ -4,8 +4,11 @@ namespace App\Entity;
|
||||
|
||||
use App\Repository\ProductRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
use Vich\UploaderBundle\Mapping\Annotation as Vich;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ProductRepository::class)]
|
||||
#[Vich\Uploadable()]
|
||||
class Product
|
||||
{
|
||||
#[ORM\Id]
|
||||
@@ -34,6 +37,18 @@ class Product
|
||||
#[ORM\Column]
|
||||
private ?float $caution = null;
|
||||
|
||||
|
||||
#[Vich\UploadableField(mapping: 'image_product', fileNameProperty: 'imageName', size: 'imageSize')]
|
||||
private ?File $imageFile = null;
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?string $imageName = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $imageSize = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?\DateTimeImmutable $updatedAt = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@@ -122,4 +137,40 @@ class Product
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setImageFile(?File $imageFile = null): void
|
||||
{
|
||||
$this->imageFile = $imageFile;
|
||||
|
||||
if (null !== $imageFile) {
|
||||
// It is required that at least one field changes if you are using doctrine
|
||||
// otherwise the event listeners won't be called and the file is lost
|
||||
$this->updatedAt = new \DateTimeImmutable();
|
||||
}
|
||||
}
|
||||
|
||||
public function getImageFile(): ?File
|
||||
{
|
||||
return $this->imageFile;
|
||||
}
|
||||
|
||||
public function setImageName(?string $imageName): void
|
||||
{
|
||||
$this->imageName = $imageName;
|
||||
}
|
||||
|
||||
public function getImageName(): ?string
|
||||
{
|
||||
return $this->imageName;
|
||||
}
|
||||
|
||||
public function setImageSize(?int $imageSize): void
|
||||
{
|
||||
$this->imageSize = $imageSize;
|
||||
}
|
||||
|
||||
public function getImageSize(): ?int
|
||||
{
|
||||
return $this->imageSize;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user