<?php
namespace App\Entity\Gos;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\ProductImageRepository")
* @Vich\Uploadable
*/
class ProductImage
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="integer")
*/
private $position;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\ProductAssociation", inversedBy="productImages", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
private $productAssociation;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @var string
*/
private $image;
/**
* @Vich\UploadableField(mapping="product_images", fileNameProperty="image")
* @Assert\File(
* maxSize = "2M",
* maxSizeMessage = "File is too big, allowed maximum size is {{ limit }} {{ suffix }}"
* )
* @var File
*/
private $imageFile;
/**
* @ORM\Column(type="datetime", nullable=true)
* @var \DateTime
*/
private $updatedAt;
/** @ORM\PreUpdate() */
public function preUpdate()
{
$this->updatedAt = new \DateTime('now');
}
public function getId(): ?int
{
return $this->id;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
public function setImageFile(File $imageFile = null)
{
$this->imageFile = $imageFile;
// 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 ($imageFile)
{
// if 'updatedAt' is not defined in your entity, use another property
$this->updatedAt = new \DateTime('now');
}
}
public function getImageFile()
{
return $this->imageFile;
}
public function setImage($image)
{
$this->image = $image;
}
public function getImage()
{
return $this->image;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getProductAssociation(): ?ProductAssociation
{
return $this->productAssociation;
}
public function setProductAssociation(?ProductAssociation $productAssociation): self
{
$this->productAssociation = $productAssociation;
return $this;
}
}