src/Flexy/ShopBundle/Entity/Product/ImageProduct.php line 16
<?php
namespace App\Flexy\ShopBundle\Entity\Product;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Flexy\ShopBundle\Repository\Product\ImageProductRepository;
use Doctrine\ORM\Mapping as ORM;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\HttpFoundation\File\File;
/**
* @Vich\Uploadable
*/
#[ApiResource]
#[ORM\Entity(repositoryClass: ImageProductRepository::class)]
class ImageProduct
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private ?string $path = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $alt = null;
/**
* @Vich\UploadableField(mapping="product_images", fileNameProperty="path")
*/
private ?\Symfony\Component\HttpFoundation\File\File $imageFile = null;
#[ORM\Column(type: 'datetime')]
private \DateTime|\DateTimeInterface|null $updatedAt = null;
#[ORM\ManyToOne(targetEntity: Product::class, inversedBy: 'images', cascade: ['persist'])]
private ?\App\Flexy\ShopBundle\Entity\Product\Product $product = null;
public function getId(): ?int
{
return $this->id;
}
public function getPath(): ?string
{
return $this->path;
}
public function setPath(string $path): self
{
$this->path = $path;
return $this;
}
public function setImageFile(File $path = null)
{
$this->imageFile = $path;
// VERY IMPORTANT:
// 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
if ($path) {
// if 'updatedAt' is not defined in your entity, use another property
$this->updatedAt = new \DateTime('now');
}
}
public function getImageFile()
{
return $this->imageFile;
}
public function getAlt(): ?string
{
return $this->alt;
}
public function setAlt(?string $alt): self
{
$this->alt = $alt;
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): self
{
$this->product = $product;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
}