src/Entity/User.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\Security\Core\User\UserInterface;
  6. /**
  7. * @ORM\Entity(repositoryClass=UserRepository::class)
  8. */
  9. class User implements UserInterface
  10. {
  11. /**
  12. * @ORM\Id()
  13. * @ORM\GeneratedValue()
  14. * @ORM\Column(type="integer")
  15. */
  16. private $id;
  17. /**
  18. * @ORM\Column(type="string", length=180, unique=true)
  19. */
  20. private $email;
  21. /**
  22. * @ORM\Column(type="json")
  23. */
  24. private $roles = [];
  25. /**
  26. * @var string The hashed password
  27. * @ORM\Column(type="string")
  28. */
  29. private $password;
  30. /**
  31. * @ORM\Column(type="string", length=255)
  32. */
  33. private $username;
  34. /**
  35. * @ORM\Column(type="string", length=255, nullable=true)
  36. */
  37. private $logo;
  38. /**
  39. * @ORM\Column(type="string", length=255)
  40. */
  41. private $name;
  42. /**
  43. * @ORM\Column(type="string", length=255)
  44. */
  45. private $lastname;
  46. /**
  47. * @ORM\Column(type="string", length=255)
  48. */
  49. private $idAccess;
  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. * A visual identifier that represents this user.
  65. *
  66. * @see UserInterface
  67. */
  68. public function getUsername(): string
  69. {
  70. return (string) $this->username;
  71. }
  72. /**
  73. * @see UserInterface
  74. */
  75. public function getRoles(): array
  76. {
  77. $roles = $this->roles;
  78. // guarantee every user at least has ROLE_USER
  79. $roles[] = 'ROLE_USER';
  80. return array_unique($roles);
  81. }
  82. public function setRoles(array $roles): self
  83. {
  84. $this->roles = $roles;
  85. return $this;
  86. }
  87. /**
  88. * @see UserInterface
  89. */
  90. public function getPassword(): string
  91. {
  92. return (string) $this->password;
  93. }
  94. public function setPassword(string $password): self
  95. {
  96. $this->password = $password;
  97. return $this;
  98. }
  99. /**
  100. * @see UserInterface
  101. */
  102. public function getSalt()
  103. {
  104. // not needed when using the "bcrypt" algorithm in security.yaml
  105. }
  106. /**
  107. * @see UserInterface
  108. */
  109. public function eraseCredentials()
  110. {
  111. // If you store any temporary, sensitive data on the user, clear it here
  112. // $this->plainPassword = null;
  113. }
  114. public function setUsername(string $username): self
  115. {
  116. $this->username = $username;
  117. return $this;
  118. }
  119. public function getLogo(): ?string
  120. {
  121. return $this->logo;
  122. }
  123. public function setLogo(?string $logo): self
  124. {
  125. $this->logo = $logo;
  126. return $this;
  127. }
  128. public function getName(): ?string
  129. {
  130. return $this->name;
  131. }
  132. public function setName(string $name): self
  133. {
  134. $this->name = $name;
  135. return $this;
  136. }
  137. public function getLastname(): ?string
  138. {
  139. return $this->lastname;
  140. }
  141. public function setLastname(string $lastname): self
  142. {
  143. $this->lastname = $lastname;
  144. return $this;
  145. }
  146. public function getIdAccess(): ?string
  147. {
  148. return $this->idAccess;
  149. }
  150. public function setIdAccess(string $idAccess): self
  151. {
  152. $this->idAccess = $idAccess;
  153. return $this;
  154. }
  155. /**
  156. * Retourne les initiales de l'utilisateur (première lettre du prénom + première lettre du nom)
  157. */
  158. public function getInitiales(): string
  159. {
  160. $initiales = '';
  161. if ($this->name) {
  162. $initiales .= strtoupper(mb_substr($this->name, 0, 1));
  163. }
  164. if ($this->lastname) {
  165. $initiales .= strtoupper(mb_substr($this->lastname, 0, 1));
  166. }
  167. return $initiales ?: '?';
  168. }
  169. /**
  170. * Vérifie si l'utilisateur a une image de profil
  171. */
  172. public function hasAvatar(): bool
  173. {
  174. return !empty($this->logo);
  175. }
  176. /**
  177. * Retourne le nom complet de l'utilisateur
  178. */
  179. public function getFullName(): string
  180. {
  181. return trim($this->name . ' ' . $this->lastname);
  182. }
  183. }