src\Entity\Utilisateur.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Doctrine\Common\Collections\Collection;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use App\Repository\UtilisateurRepository;
  9. #[ORM\Entity(repositoryClass: UtilisateurRepository::class)]
  10. #[ORM\Table(name: '`utilisateur`')]
  11. #[UniqueEntity(fields: ['email'], message: 'Cette adresse email est déjà utilisée.')]
  12. class Utilisateur implements UserInterface,PasswordAuthenticatedUserInterface
  13. {
  14. #[ORM\Id]
  15. #[ORM\GeneratedValue]
  16. #[ORM\Column]
  17. private ?int $utilisateur_id = null;
  18. #[ORM\Column(length: 50, unique: true, nullable: false)]
  19. private ?string $email;
  20. /**
  21. * @var string The hashed password
  22. */
  23. #[ORM\Column(type:"string", nullable: false)]
  24. private ?string $password = null;
  25. #[ORM\Column(type:"string",length:50, nullable: false)]
  26. private ?string $prenom = null;
  27. #[ORM\Column(type:"string",length:50, nullable: false)]
  28. private ?string $nom = null;
  29. #[ORM\Column(type:"string", length:50, nullable: true)]
  30. private ?string $telephone = null;
  31. #[ORM\Column(type:"string", length:50, nullable: true)]
  32. private ?string $ville = null;
  33. #[ORM\Column(type:"string", length:50, nullable: true)]
  34. private ?string $pays = null;
  35. #[ORM\Column(type:"string",length:50, nullable: true)]
  36. private ?string $adresse_postal = null;
  37. #[ORM\OneToOne(targetEntity: Possede::class, mappedBy: 'utilisateur_id', orphanRemoval: true, cascade: ['persist'])]
  38. private ?Possede $possede= null;
  39. #[ORM\OneToOne(targetEntity: Publie::class, mappedBy: 'utilisateur_id', orphanRemoval: true, cascade: ['persist'])]
  40. private ?Publie $publie= null;
  41. #[ORM\OneToMany(targetEntity: Commande::class, mappedBy: 'utilisateur_id', orphanRemoval: true, cascade: ['persist'])]
  42. private Collection $commande;
  43. private ?array $roles = null;
  44. public function getUtilisateurId(): ?int
  45. {
  46. return $this->utilisateur_id;
  47. }
  48. public function getEmail(): ?string
  49. {
  50. return $this->email;
  51. }
  52. public function setEmail(string $email): static
  53. {
  54. $this->email = $email;
  55. return $this;
  56. }
  57. /**
  58. * @see PasswordAuthenticatedUserInterface
  59. */
  60. public function getPassword(): ?string
  61. {
  62. return $this->password;
  63. }
  64. public function setPassword(?string $password): static
  65. {
  66. $this->password = $password;
  67. return $this;
  68. }
  69. public function getPrenom(): ?string
  70. {
  71. return $this->prenom;
  72. }
  73. public function setPrenom(string $prenom): static
  74. {
  75. $this->prenom = $prenom;
  76. return $this;
  77. }
  78. public function getNom(): ?string
  79. {
  80. return $this->nom;
  81. }
  82. public function setNom(string $nom): static
  83. {
  84. $this->nom = $nom;
  85. return $this;
  86. }
  87. public function getTelephone(): ?string
  88. {
  89. return $this->telephone;
  90. }
  91. public function setTelephone(?string $telephone): static
  92. {
  93. $this->telephone = $telephone;
  94. return $this;
  95. }
  96. public function getVille(): ?string
  97. {
  98. return $this->ville;
  99. }
  100. public function setVille(?string $ville): static
  101. {
  102. $this->ville = $ville;
  103. return $this;
  104. }
  105. public function getPays(): ?string
  106. {
  107. return $this->pays;
  108. }
  109. public function setPays(?string $pays): static
  110. {
  111. $this->pays = $pays;
  112. return $this;
  113. }
  114. public function getAdressePostal(): ?string
  115. {
  116. return $this->adresse_postal;
  117. }
  118. public function setAdressePostal(?string $adresse_postal): static
  119. {
  120. $this->adresse_postal = $adresse_postal;
  121. return $this;
  122. }
  123. /**
  124. * A visual identifier that represents this user.
  125. *
  126. * @see UserInterface
  127. */
  128. public function getUserIdentifier(): string
  129. {
  130. return (string) $this->email;
  131. }
  132. /**
  133. * @deprecated since Symfony 5.3, use getUserIdentifier instead
  134. */
  135. public function getUsername(): string
  136. {
  137. return (string) $this->email;
  138. }
  139. public function setUsername(string $email): static
  140. {
  141. $this->email = $email;
  142. return $this;
  143. }
  144. /**
  145. * @see UserInterface
  146. */
  147. public function getRoles(): array
  148. {
  149. $this->roles = [];
  150. if($this->possede && $this->possede->getRoleId()) {
  151. $this->roles[] = $this->possede->getRoleId()->getLibelle();
  152. }
  153. return $this->roles;
  154. }
  155. public function setRoles(array $roles): static
  156. {
  157. $this->roles = $roles;
  158. return $this;
  159. }
  160. /**
  161. * @return Possede<int, Possede>
  162. */
  163. public function getPossede(): Possede
  164. {
  165. if (!$this->possede) {
  166. $this->possede = new Possede();
  167. $this->possede->setUtilisateurId($this);
  168. }
  169. return $this->possede;
  170. }
  171. public function addPossede(Possede $possede): static
  172. {
  173. if ($this->possede !== $possede) {
  174. $this->possede = $possede;
  175. $possede->setUtilisateurId($this);
  176. }
  177. return $this;
  178. }
  179. public function removePossede(Possede $possede): static
  180. {
  181. if ($this->possede === $possede) {
  182. $this->possede = null;
  183. // set the owning side to null (unless already changed)
  184. if ($possede->getUtilisateurId() === $this) {
  185. $possede->setUtilisateurId(null);
  186. }
  187. }
  188. return $this;
  189. }
  190. /**
  191. * @return Publie<int, Publie>
  192. */
  193. public function getPublie(): ?Publie
  194. {
  195. return $this->publie;
  196. }
  197. public function addPublie(Publie $publie): static
  198. {
  199. if ($this->publie !== $publie) {
  200. $this->publie = $publie;
  201. $publie->setUtilisateurId($this);
  202. }
  203. return $this;
  204. }
  205. public function removePublie(Publie $publie): static
  206. {
  207. if ($this->publie === $publie) {
  208. $this->publie = null;
  209. // set the owning side to null (unless already changed)
  210. if ($publie->getUtilisateurId() === $this) {
  211. $publie->setUtilisateurId(null);
  212. }
  213. }
  214. return $this;
  215. }
  216. public function getCommandes(): Collection
  217. {
  218. return $this->commande;
  219. }
  220. public function addCommande(Commande $commande): static
  221. {
  222. if (!$this->commande->contains($commande)) {
  223. $this->commande->add($commande);
  224. $commande->setUtilisateurId($this);
  225. }
  226. return $this;
  227. }
  228. public function removeCommande(Commande $commande): static
  229. {
  230. if ($this->commande->removeElement($commande)) {
  231. // set the owning side to null (unless already changed)
  232. if ($commande->getUtilisateurId() === $this) {
  233. $commande->setUtilisateurId(null);
  234. }
  235. }
  236. return $this;
  237. }
  238. /**
  239. * Returning a salt is only needed, if you are not using a modern
  240. * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  241. *
  242. * @see UserInterface
  243. */
  244. public function getSalt(): ?string
  245. {
  246. return null;
  247. }
  248. /**
  249. * @see UserInterface
  250. */
  251. public function eraseCredentials(): void
  252. {
  253. // If you store any temporary, sensitive data on the user, clear it here
  254. // $this->plainPassword = null;
  255. }
  256. }