<?phpnamespace App\Entity;use App\Repository\ImageRepository;use DateTime;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Serializer\Annotation\Ignore;use Vich\UploaderBundle\Mapping\Annotation as Vich;/** * @ORM\Entity(repositoryClass=ImageRepository::class) * @Vich\Uploadable() */class Image{ /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $image; /** * @Vich\UploadableField(mapping="imageFile", fileNameProperty="image") */ private $imageFile; /** * @ORM\Column(type="datetime") */ private $createdAt; /** * @ORM\Column(type="datetime") */ private $updatedAt; /** * @ORM\ManyToOne(targetEntity=Realisation::class, inversedBy="images") * @ORM\JoinColumn(nullable=false) * @Ignore() */ private $realisation; /** * @ORM\Column(type="string", length=255, nullable=true) */ private $altDesc; public function __construct() { $this->createdAt = new DateTime(); $this->updatedAt = new DateTime(); } public function getId(): ?int { return $this->id; } public function getImage(): ?string { return $this->image; } public function setImage(?string $image): self { $this->image = $image; return $this; } public function getCreatedAt(): ?\DateTimeInterface { return $this->createdAt; } public function setCreatedAt(\DateTimeInterface $createdAt): self { $this->createdAt = $createdAt; return $this; } public function getUpdatedAt(): ?\DateTimeInterface { return $this->updatedAt; } public function setUpdatedAt(\DateTimeInterface $updatedAt): self { $this->updatedAt = $updatedAt; return $this; } /** * @return mixed */ public function getImageFile() { return $this->imageFile; } /** * @param mixed $imageFile */ public function setImageFile($imageFile): void { $this->imageFile = $imageFile; if($imageFile){ $this->updatedAt = new DateTime(); } } public function getRealisation(): ?Realisation { return $this->realisation; } public function setRealisation(?Realisation $realisation): self { $this->realisation = $realisation; return $this; } public function getAltDesc(): ?string { return $this->altDesc; } public function setAltDesc(?string $altDesc): self { $this->altDesc = $altDesc; return $this; } public function getUrl(){ return "/images/upload/" . $this->getImage(); } public function getAbsoluteImage() : ?string { if(!empty($this->image)){ return sprintf("https://%s/images/upload/%s",$_SERVER['HTTP_HOST'],$this->image); } return null; }}