src/Entity/EasterEgg.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\EasterEggRepository;
  4. use App\Traits\DateTrait;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. use JMS\Serializer\Annotation\Groups;
  11. /**
  12. * @ORM\Entity(repositoryClass=EasterEggRepository::class)
  13. * @ORM\HasLifecycleCallbacks
  14. * @Vich\Uploadable
  15. *
  16. * @UniqueEntity(
  17. * fields={"slug"},
  18. * message="Ce slug existe déjà."
  19. * )
  20. */
  21. class EasterEgg
  22. {
  23. /**
  24. * @ORM\Id
  25. * @ORM\GeneratedValue
  26. * @ORM\Column(type="integer")
  27. *
  28. * @Groups({
  29. * "easter_egg",
  30. * })
  31. */
  32. private $id;
  33. /**
  34. * @ORM\Column(type="string", length=255)
  35. *
  36. * @Groups({
  37. * "easter_egg",
  38. * })
  39. */
  40. private $label;
  41. /**
  42. * @ORM\Column(type="string", length=255)
  43. *
  44. * @Assert\NotBlank(message="Le slug ne peut pas être vide.")
  45. *
  46. * @Assert\Regex(
  47. * pattern="/^[a-z0-9]+(?:-[a-z0-9]+)*$/",
  48. * message="Le slug doit contenir uniquement des lettres minuscules, chiffres et tirets."
  49. * )
  50. *
  51. * @Groups({
  52. * "easter_egg",
  53. * })
  54. */
  55. private $slug;
  56. /**
  57. * @ORM\Column(type="string", length=255, nullable=true)
  58. *
  59. * @Groups({
  60. * "easter_egg",
  61. * })
  62. */
  63. private $image;
  64. // Vich Uploader
  65. /**
  66. * @Vich\UploadableField(mapping="easter_egg_images", fileNameProperty="image")
  67. * @var File|null
  68. * @Assert\File(
  69. * mimeTypes={"image/jpeg", "image/png", "image/gif"},
  70. * mimeTypesMessage="Veuillez uploader une image JPEG, PNG ou GIF."
  71. * )
  72. */
  73. private ?File $imageFile = null;
  74. /**
  75. * @ORM\Column(type="integer", nullable=true)
  76. *
  77. * @Groups({
  78. * "easter_egg",
  79. * })
  80. */
  81. private ?int $value = null;
  82. /**
  83. * @ORM\Column(type="datetime", nullable=true)
  84. *
  85. * @Groups({
  86. * "easter_egg",
  87. * })
  88. */
  89. private ?\DateTime $dateStart;
  90. /**
  91. * @ORM\Column(type="datetime", nullable=true)
  92. *
  93. * @Groups({
  94. * "easter_egg",
  95. * })
  96. */
  97. private ?\DateTime $dateEnd;
  98. /**
  99. * @ORM\Column(type="string", length=255)
  100. *
  101. * @Groups({
  102. * "easter_egg",
  103. * })
  104. */
  105. private $location;
  106. use DateTrait;
  107. public function getId(): ?int
  108. {
  109. return $this->id;
  110. }
  111. public function getLabel(): ?string
  112. {
  113. return $this->label;
  114. }
  115. public function setLabel(string $label): self
  116. {
  117. $this->label = $label;
  118. return $this;
  119. }
  120. public function getSlug(): ?string
  121. {
  122. return $this->slug;
  123. }
  124. public function setSlug(string $slug): self
  125. {
  126. $this->slug = $slug;
  127. return $this;
  128. }
  129. public function getImage(): ?string
  130. {
  131. return $this->image;
  132. }
  133. public function setImage( ?string $image ): self
  134. {
  135. $this->image = $image;
  136. return $this;
  137. }
  138. public function getImageFile(): ?File
  139. {
  140. return $this->imageFile;
  141. }
  142. /**
  143. * @param File $imageFile
  144. *
  145. * @return void
  146. */
  147. public function setImageFile( File $imageFile ): void
  148. {
  149. $this->imageFile = $imageFile;
  150. if ( NULL !== $imageFile ) {
  151. // It is required that at least one field changes if you are using doctrine
  152. // otherwise the event listeners won't be called and the file is lost
  153. $this->updatedAt = new \DateTime();
  154. }
  155. }
  156. public function getValue(): ?int
  157. {
  158. return $this->value;
  159. }
  160. public function setValue(?int $value): self
  161. {
  162. $this->value = $value;
  163. return $this;
  164. }
  165. public function getDateStart(): ?\DateTime
  166. {
  167. return $this->dateStart;
  168. }
  169. public function setDateStart(?\DateTime $dateStart): self
  170. {
  171. $this->dateStart = $dateStart;
  172. return $this;
  173. }
  174. public function getDateEnd(): ?\DateTime
  175. {
  176. return $this->dateEnd;
  177. }
  178. public function setDateEnd(?\DateTime $dateEnd): self
  179. {
  180. $this->dateEnd = $dateEnd;
  181. return $this;
  182. }
  183. public function getLocation(): ?string
  184. {
  185. return $this->location;
  186. }
  187. public function setLocation(string $location): self
  188. {
  189. $this->location = $location;
  190. return $this;
  191. }
  192. }