src/Entity/CarImages.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CarImagesRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\HttpFoundation\File\File;
  6. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  7. /**
  8.  * @ORM\Entity(repositoryClass=CarImagesRepository::class)
  9.  * @ORM\HasLifecycleCallbacks()
  10.  * @Vich\Uploadable
  11.  */
  12. class CarImages
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  22.      *
  23.      * @Vich\UploadableField(mapping="car_image", fileNameProperty="image")
  24.      *
  25.      * @var File|null
  26.      */
  27.     private $imageFile;
  28.     /**
  29.      * @ORM\Column(type="string", length=255)
  30.      */
  31.     private $image;
  32.     /**
  33.      * @ORM\Column(type="boolean", nullable=true)
  34.      */
  35.     private $isMain;
  36.     /**
  37.      * @ORM\Column(type="datetime")
  38.      */
  39.     private $createdAt;
  40.     /**
  41.      * @ORM\Column(type="datetime", nullable=true)
  42.      */
  43.     private $updatedAt;
  44.     /**
  45.      * @ORM\ManyToOne(targetEntity=Car::class, inversedBy="imageId")
  46.      * @ORM\JoinColumn(nullable=false)
  47.      */
  48.     private $car;
  49.     /**
  50.      * @ORM\Column(type="integer")
  51.      */
  52.     private $position 0;
  53.     public function getId(): ?int
  54.     {
  55.         return $this->id;
  56.     }
  57.     /**
  58.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  59.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  60.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  61.      * must be able to accept an instance of 'File' as the bundle will inject one here
  62.      * during Doctrine hydration.
  63.      *
  64.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
  65.      */
  66.     public function setImageFile(?File $imageFile null): void
  67.     {
  68.         $this->imageFile $imageFile;
  69.         if (null !== $imageFile) {
  70.             // It is required that at least one field changes if you are using doctrine
  71.             // otherwise the event listeners won't be called and the file is lost
  72.             $this->updatedAt = new \DateTime();
  73.         }
  74.     }
  75.     public function getImageFile(): ?File
  76.     {
  77.         return $this->imageFile;
  78.     }
  79.     public function getImage(): ?string
  80.     {
  81.         return $this->image;
  82.     }
  83.     public function setImage(?string $image): self
  84.     {
  85.         $this->image $image;
  86.         return $this;
  87.     }
  88.     public function getIsMain(): ?bool
  89.     {
  90.         return $this->isMain;
  91.     }
  92.     public function setIsMain(bool $isMain): self
  93.     {
  94.         $this->isMain $isMain;
  95.         return $this;
  96.     }
  97.     public function getCreatedAt(): ?\DateTimeInterface
  98.     {
  99.         return $this->createdAt;
  100.     }
  101.     /**
  102.      * @ORM\PrePersist
  103.      */
  104.     public function setCreatedAt(): self
  105.     {
  106.         $this->createdAt = new \DateTime();
  107.         return $this;
  108.     }
  109.     public function getUpdatedAt(): ?\DateTimeInterface
  110.     {
  111.         return $this->updatedAt;
  112.     }
  113.     /**
  114.      * @ORM\PreUpdate
  115.      */
  116.     public function setUpdatedAt(): self
  117.     {
  118.         $this->updatedAt = new \DateTime();
  119.         return $this;
  120.     }
  121.     public function getCar(): ?Car
  122.     {
  123.         return $this->car;
  124.     }
  125.     public function setCar(?Car $car): self
  126.     {
  127.         $this->car $car;
  128.         return $this;
  129.     }
  130.     public function __toString()
  131.     {
  132.         return $this->image;
  133.     }
  134.     public function getPosition(): int
  135.     {
  136.         return (int) $this->position;
  137.     }
  138.     public function setPosition(int $p): self
  139.     {
  140.         $this->position $p;
  141.         return $this;
  142.     }
  143. }