<?phpnamespace App\Entity;use App\Repository\CarImagesRepository;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\HttpFoundation\File\File;use Vich\UploaderBundle\Mapping\Annotation as Vich;/** * @ORM\Entity(repositoryClass=CarImagesRepository::class) * @ORM\HasLifecycleCallbacks() * @Vich\Uploadable */class CarImages{ /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * NOTE: This is not a mapped field of entity metadata, just a simple property. * * @Vich\UploadableField(mapping="car_image", fileNameProperty="image") * * @var File|null */ private $imageFile; /** * @ORM\Column(type="string", length=255) */ private $image; /** * @ORM\Column(type="boolean", nullable=true) */ private $isMain; /** * @ORM\Column(type="datetime") */ private $createdAt; /** * @ORM\Column(type="datetime", nullable=true) */ private $updatedAt; /** * @ORM\ManyToOne(targetEntity=Car::class, inversedBy="imageId") * @ORM\JoinColumn(nullable=false) */ private $car; /** * @ORM\Column(type="integer") */ private $position = 0; public function getId(): ?int { return $this->id; } /** * If manually uploading a file (i.e. not using Symfony Form) ensure an instance * of 'UploadedFile' is injected into this setter to trigger the update. If this * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter * must be able to accept an instance of 'File' as the bundle will inject one here * during Doctrine hydration. * * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile */ 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 \DateTime(); } } public function getImageFile(): ?File { return $this->imageFile; } public function getImage(): ?string { return $this->image; } public function setImage(?string $image): self { $this->image = $image; return $this; } public function getIsMain(): ?bool { return $this->isMain; } public function setIsMain(bool $isMain): self { $this->isMain = $isMain; return $this; } public function getCreatedAt(): ?\DateTimeInterface { return $this->createdAt; } /** * @ORM\PrePersist */ public function setCreatedAt(): self { $this->createdAt = new \DateTime(); return $this; } public function getUpdatedAt(): ?\DateTimeInterface { return $this->updatedAt; } /** * @ORM\PreUpdate */ public function setUpdatedAt(): self { $this->updatedAt = new \DateTime(); return $this; } public function getCar(): ?Car { return $this->car; } public function setCar(?Car $car): self { $this->car = $car; return $this; } public function __toString() { return $this->image; } public function getPosition(): int { return (int) $this->position; } public function setPosition(int $p): self { $this->position = $p; return $this; }}