src\Entity\Utilisateur.php line 16

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