src/Entity/Image.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ImageRepository;
  4. use DateTime;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Serializer\Annotation\Ignore;
  7. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  8. /**
  9. * @ORM\Entity(repositoryClass=ImageRepository::class)
  10. * @Vich\Uploadable()
  11. */
  12. class Image
  13. {
  14. /**
  15. * @ORM\Id
  16. * @ORM\GeneratedValue
  17. * @ORM\Column(type="integer")
  18. */
  19. private $id;
  20. /**
  21. * @ORM\Column(type="string", length=255)
  22. */
  23. private $image;
  24. /**
  25. * @Vich\UploadableField(mapping="imageFile", fileNameProperty="image")
  26. */
  27. private $imageFile;
  28. /**
  29. * @ORM\Column(type="datetime")
  30. */
  31. private $createdAt;
  32. /**
  33. * @ORM\Column(type="datetime")
  34. */
  35. private $updatedAt;
  36. /**
  37. * @ORM\ManyToOne(targetEntity=Realisation::class, inversedBy="images")
  38. * @ORM\JoinColumn(nullable=false)
  39. * @Ignore()
  40. */
  41. private $realisation;
  42. /**
  43. * @ORM\Column(type="string", length=255, nullable=true)
  44. */
  45. private $altDesc;
  46. public function __construct()
  47. {
  48. $this->createdAt = new DateTime();
  49. $this->updatedAt = new DateTime();
  50. }
  51. public function getId(): ?int
  52. {
  53. return $this->id;
  54. }
  55. public function getImage(): ?string
  56. {
  57. return $this->image;
  58. }
  59. public function setImage(?string $image): self
  60. {
  61. $this->image = $image;
  62. return $this;
  63. }
  64. public function getCreatedAt(): ?\DateTimeInterface
  65. {
  66. return $this->createdAt;
  67. }
  68. public function setCreatedAt(\DateTimeInterface $createdAt): self
  69. {
  70. $this->createdAt = $createdAt;
  71. return $this;
  72. }
  73. public function getUpdatedAt(): ?\DateTimeInterface
  74. {
  75. return $this->updatedAt;
  76. }
  77. public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  78. {
  79. $this->updatedAt = $updatedAt;
  80. return $this;
  81. }
  82. /**
  83. * @return mixed
  84. */
  85. public function getImageFile()
  86. {
  87. return $this->imageFile;
  88. }
  89. /**
  90. * @param mixed $imageFile
  91. */
  92. public function setImageFile($imageFile): void
  93. {
  94. $this->imageFile = $imageFile;
  95. if($imageFile){
  96. $this->updatedAt = new DateTime();
  97. }
  98. }
  99. public function getRealisation(): ?Realisation
  100. {
  101. return $this->realisation;
  102. }
  103. public function setRealisation(?Realisation $realisation): self
  104. {
  105. $this->realisation = $realisation;
  106. return $this;
  107. }
  108. public function getAltDesc(): ?string
  109. {
  110. return $this->altDesc;
  111. }
  112. public function setAltDesc(?string $altDesc): self
  113. {
  114. $this->altDesc = $altDesc;
  115. return $this;
  116. }
  117. public function getUrl(){
  118. return "/images/upload/" . $this->getImage();
  119. }
  120. public function getAbsoluteImage() : ?string
  121. {
  122. if(!empty($this->image)){
  123. return sprintf("https://%s/images/upload/%s",$_SERVER['HTTP_HOST'],$this->image);
  124. }
  125. return null;
  126. }
  127. }