src/Entity/Gos/ProductImage.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\HttpFoundation\File\File;
  5. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\ProductImageRepository")
  9.  * @Vich\Uploadable
  10.  */
  11. class ProductImage
  12. {
  13.     /**
  14.      * @ORM\Id()
  15.      * @ORM\GeneratedValue()
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $position;
  23.     /**
  24.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\ProductAssociation", inversedBy="productImages", cascade={"persist"})
  25.      * @ORM\JoinColumn(nullable=false)
  26.      */
  27.     private $productAssociation;
  28.     /**
  29.      * @ORM\Column(type="string", length=255, nullable=true)
  30.      * @var string
  31.      */
  32.     private $image;
  33.     /**
  34.      * @Vich\UploadableField(mapping="product_images", fileNameProperty="image")
  35.      * @Assert\File(
  36.      *     maxSize = "2M",
  37.      *     maxSizeMessage = "File is too big, allowed maximum size is {{ limit }} {{ suffix }}"
  38.      * )
  39.      * @var File
  40.      */
  41.     private $imageFile;
  42.     /**
  43.      * @ORM\Column(type="datetime", nullable=true)
  44.      * @var \DateTime
  45.      */
  46.     private $updatedAt;
  47.     /** @ORM\PreUpdate() */
  48.     public function preUpdate()
  49.     {
  50.         $this->updatedAt = new \DateTime('now');
  51.     }
  52.     public function getId(): ?int
  53.     {
  54.         return $this->id;
  55.     }
  56.     public function getPosition(): ?int
  57.     {
  58.         return $this->position;
  59.     }
  60.     public function setPosition(int $position): self
  61.     {
  62.         $this->position $position;
  63.         return $this;
  64.     }
  65.     public function setImageFile(File $imageFile null)
  66.     {
  67.         $this->imageFile $imageFile;
  68.         // VERY IMPORTANT:
  69.         // It is required that at least one field changes if you are using Doctrine,
  70.         // otherwise the event listeners won't be called and the file is lost
  71.         if ($imageFile)
  72.         {
  73.             // if 'updatedAt' is not defined in your entity, use another property
  74.             $this->updatedAt = new \DateTime('now');
  75.         }
  76.     }
  77.     public function getImageFile()
  78.     {
  79.         return $this->imageFile;
  80.     }
  81.     public function setImage($image)
  82.     {
  83.         $this->image $image;
  84.     }
  85.     public function getImage()
  86.     {
  87.         return $this->image;
  88.     }
  89.     public function getUpdatedAt(): ?\DateTimeInterface
  90.     {
  91.         return $this->updatedAt;
  92.     }
  93.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  94.     {
  95.         $this->updatedAt $updatedAt;
  96.         return $this;
  97.     }
  98.     public function getProductAssociation(): ?ProductAssociation
  99.     {
  100.         return $this->productAssociation;
  101.     }
  102.     public function setProductAssociation(?ProductAssociation $productAssociation): self
  103.     {
  104.         $this->productAssociation $productAssociation;
  105.         return $this;
  106.     }
  107. }