src/Entity/User.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\UserRepository;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. #[ORM\Entity(repositoryClass: UserRepository::class)]
  11. #[UniqueEntity(fields: ['email'], message: 'Adresse email invalide')]
  12. class User implements UserInterface, PasswordAuthenticatedUserInterface
  13. {
  14. #[ORM\Id]
  15. #[ORM\GeneratedValue]
  16. #[ORM\Column(type: 'integer')]
  17. private $id;
  18. #[ORM\Column(type: 'string', length: 180, unique: true)]
  19. private $email;
  20. #[ORM\Column(type: 'json')]
  21. private $roles = [];
  22. #[ORM\Column(type: 'string', nullable: false)]
  23. private $password;
  24. #[ORM\Column(type: 'boolean')]
  25. private $isVerified = false;
  26. #[ORM\Column(type: 'string', length: 180, nullable: true)]
  27. private $firstName;
  28. #[ORM\Column(type: 'string', length: 180, nullable: true)]
  29. private $lastName;
  30. #[ORM\Column(type: 'string', length: 180, nullable: true)]
  31. private $phoneNumber;
  32. #[ORM\OneToMany(mappedBy: 'user', targetEntity: Commande::class, orphanRemoval: true)]
  33. private $commandes;
  34. #[ORM\ManyToMany(targetEntity: Foodtruck::class, mappedBy: 'users')]
  35. private $foodtrucks;
  36. #[ORM\Column(nullable: true)]
  37. private ?\DateTimeImmutable $createdAt = null;
  38. #[ORM\OneToMany(mappedBy: 'user', targetEntity: AccesEmplacement::class, orphanRemoval: true)]
  39. private Collection $accesEmplacements;
  40. #[ORM\OneToMany(mappedBy: 'createur', targetEntity: Emplacement::class)]
  41. private Collection $emplacements;
  42. public function __construct()
  43. {
  44. $this->commandes = new ArrayCollection();
  45. $this->foodtrucks = new ArrayCollection();
  46. $this->createdAt = new \DateTimeImmutable('now', new \DateTimeZone('Europe/Paris'));
  47. $this->accesEmplacements = new ArrayCollection();
  48. $this->emplacements = new ArrayCollection();
  49. }
  50. public function getId(): ?int
  51. {
  52. return $this->id;
  53. }
  54. public function getEmail(): ?string
  55. {
  56. return $this->email;
  57. }
  58. public function setEmail(string $email): self
  59. {
  60. $this->email = $email;
  61. return $this;
  62. }
  63. /**
  64. * The public representation of the user (e.g. a username, an email address, etc.)
  65. *
  66. * @see UserInterface
  67. */
  68. public function getUserIdentifier(): string
  69. {
  70. return (string) $this->email;
  71. }
  72. /**
  73. * @deprecated since Symfony 5.3
  74. */
  75. public function getUsername(): string
  76. {
  77. return (string) $this->email;
  78. }
  79. /**
  80. * @see UserInterface
  81. */
  82. public function getRoles(): array
  83. {
  84. $roles = $this->roles;
  85. // guarantee every user at least has ROLE_USER
  86. $roles[] = 'ROLE_USER';
  87. return array_unique($roles);
  88. }
  89. public function setRoles(array $roles): self
  90. {
  91. $this->roles = $roles;
  92. return $this;
  93. }
  94. /**
  95. * @see PasswordAuthenticatedUserInterface
  96. */
  97. public function getPassword(): string
  98. {
  99. return $this->password;
  100. }
  101. public function setPassword(string $password): self
  102. {
  103. $this->password = $password;
  104. return $this;
  105. }
  106. /**
  107. * Returning a salt is only needed, if you are not using a modern
  108. * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  109. *
  110. * @see UserInterface
  111. */
  112. public function getSalt(): ?string
  113. {
  114. return null;
  115. }
  116. /**
  117. * @see UserInterface
  118. */
  119. public function eraseCredentials()
  120. {
  121. // If you store any temporary, sensitive data on the user, clear it here
  122. // $this->plainPassword = null;
  123. }
  124. public function isVerified(): bool
  125. {
  126. return $this->isVerified;
  127. }
  128. public function setIsVerified(bool $isVerified): self
  129. {
  130. $this->isVerified = $isVerified;
  131. return $this;
  132. }
  133. public function getFirstName(): ?string
  134. {
  135. return $this->firstName;
  136. }
  137. public function setFirstName(?string $firstName): self
  138. {
  139. $this->firstName = $firstName;
  140. return $this;
  141. }
  142. public function getLastName(): ?string
  143. {
  144. return $this->lastName;
  145. }
  146. public function setLastName(?string $lastName): self
  147. {
  148. $this->lastName = $lastName;
  149. return $this;
  150. }
  151. public function getPhoneNumber(): ?string
  152. {
  153. return $this->phoneNumber;
  154. }
  155. public function setPhoneNumber(?string $phoneNumber): self
  156. {
  157. $this->phoneNumber = $phoneNumber;
  158. return $this;
  159. }
  160. /**
  161. * @return Collection|Commande[]
  162. */
  163. public function getCommandes(): Collection
  164. {
  165. return $this->commandes;
  166. }
  167. public function addCommande(Commande $commande): self
  168. {
  169. if (!$this->commandes->contains($commande)) {
  170. $this->commandes[] = $commande;
  171. $commande->setUser($this);
  172. }
  173. return $this;
  174. }
  175. public function removeCommande(Commande $commande): self
  176. {
  177. if ($this->commandes->removeElement($commande)) {
  178. // set the owning side to null (unless already changed)
  179. if ($commande->getUser() === $this) {
  180. $commande->setUser(null);
  181. }
  182. }
  183. return $this;
  184. }
  185. /**
  186. * @return Collection<int, Foodtruck>
  187. */
  188. public function getFoodtrucks(): Collection
  189. {
  190. return $this->foodtrucks;
  191. }
  192. public function addFoodtruck(Foodtruck $foodtruck): self
  193. {
  194. if (!$this->foodtrucks->contains($foodtruck)) {
  195. $this->foodtrucks->add($foodtruck);
  196. $foodtruck->addUser($this);
  197. }
  198. return $this;
  199. }
  200. public function removeFoodtruck(Foodtruck $foodtruck): self
  201. {
  202. if ($this->foodtrucks->removeElement($foodtruck)) {
  203. $foodtruck->removeUser($this);
  204. }
  205. return $this;
  206. }
  207. public function getCreatedAt(): ?\DateTimeImmutable
  208. {
  209. return $this->createdAt;
  210. }
  211. public function setCreatedAt(?\DateTimeImmutable $createdAt): self
  212. {
  213. $this->createdAt = $createdAt;
  214. return $this;
  215. }
  216. /**
  217. * @return Collection<int, AccesEmplacement>
  218. */
  219. public function getAccesEmplacements(): Collection
  220. {
  221. return $this->accesEmplacements;
  222. }
  223. public function addAccesEmplacement(AccesEmplacement $accesEmplacement): self
  224. {
  225. if (!$this->accesEmplacements->contains($accesEmplacement)) {
  226. $this->accesEmplacements->add($accesEmplacement);
  227. $accesEmplacement->setUser($this);
  228. }
  229. return $this;
  230. }
  231. public function removeAccesEmplacement(AccesEmplacement $accesEmplacement): self
  232. {
  233. if ($this->accesEmplacements->removeElement($accesEmplacement)) {
  234. // set the owning side to null (unless already changed)
  235. if ($accesEmplacement->getUser() === $this) {
  236. $accesEmplacement->setUser(null);
  237. }
  238. }
  239. return $this;
  240. }
  241. /**
  242. * @return Collection<int, Emplacement>
  243. */
  244. public function getEmplacements(): Collection
  245. {
  246. return $this->emplacements;
  247. }
  248. public function addEmplacement(Emplacement $emplacement): static
  249. {
  250. if (!$this->emplacements->contains($emplacement)) {
  251. $this->emplacements->add($emplacement);
  252. $emplacement->setCreateur($this);
  253. }
  254. return $this;
  255. }
  256. public function removeEmplacement(Emplacement $emplacement): static
  257. {
  258. if ($this->emplacements->removeElement($emplacement)) {
  259. // set the owning side to null (unless already changed)
  260. if ($emplacement->getCreateur() === $this) {
  261. $emplacement->setCreateur(null);
  262. }
  263. }
  264. return $this;
  265. }
  266. }