src/Entity/User.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use Symfony\Component\Serializer\Annotation\Ignore;
  12. /**
  13. * @ORM\Entity(repositoryClass=UserRepository::class)
  14. * @UniqueEntity(fields={"email"}, message="Il existe déjà un utilisateur avec cet email")
  15. *
  16. */
  17. class User implements UserInterface, PasswordAuthenticatedUserInterface
  18. {
  19. const ROLE_ADMIN = "ROLE_ADMIN";
  20. const ROLE_DIRECTEUR = "ROLE_DIRECTEUR";
  21. const ROLE_DIRECTEUR_ADMIN = "ROLE_DIRECTEUR_ADMIN";
  22. const ROLE_PARENT = "ROLE_PARENT";
  23. const ROLE_CANDIDAT = "ROLE_CANDIDAT";
  24. const ROLE_COMPTA = "ROLE_COMPTA";
  25. const ROLE_HR = "ROLE_HR";
  26. const ROLE_CE = "ROLE_CE";
  27. const ROLE_SEO = "ROLE_SEO";
  28. /**
  29. * @ORM\Id
  30. * @ORM\GeneratedValue
  31. * @ORM\Column(type="integer")
  32. */
  33. private $id;
  34. /**
  35. * @ORM\Column(type="string", length=180, unique=true)
  36. * @Assert\Email
  37. */
  38. private $email;
  39. /**
  40. * @ORM\Column(type="json")
  41. */
  42. private $roles = [];
  43. /**
  44. * @var string The hashed password
  45. * @ORM\Column(type="string")
  46. */
  47. private $password;
  48. /**
  49. * @ORM\Column(type="boolean")
  50. */
  51. private $isVerified = false;
  52. /**
  53. * @ORM\OneToOne(targetEntity=Contact::class, inversedBy="user", cascade={"persist", "remove"})
  54. * @ORM\JoinColumn(nullable=true)
  55. * @Ignore()
  56. */
  57. private $contact;
  58. /**
  59. * @ORM\OneToMany(targetEntity=ConnexionLog::class, mappedBy="user")
  60. */
  61. private $connexionLogs;
  62. /**
  63. * @ORM\Column(type="boolean", nullable=true)
  64. */
  65. private $isActive;
  66. /**
  67. * @ORM\Column(type="boolean", nullable=true)
  68. */
  69. private $hasOptin;
  70. /**
  71. * @ORM\Column(type="integer")
  72. */
  73. private $count;
  74. public function __construct()
  75. {
  76. $this->connexionLogs = new ArrayCollection();
  77. $this->count = 0;
  78. }
  79. public function getId(): ?int
  80. {
  81. return $this->id;
  82. }
  83. public function getEmail(): ?string
  84. {
  85. return $this->email;
  86. }
  87. public function setEmail(string $email): self
  88. {
  89. $this->email = $email;
  90. return $this;
  91. }
  92. /**
  93. * A visual identifier that represents this user.
  94. *
  95. * @see UserInterface
  96. */
  97. public function getUserIdentifier(): string
  98. {
  99. return (string) $this->email;
  100. }
  101. /**
  102. * @deprecated since Symfony 5.3, use getUserIdentifier instead
  103. */
  104. public function getUsername(): string
  105. {
  106. return (string) $this->email;
  107. }
  108. /**
  109. * @see UserInterface
  110. */
  111. public function getRoles(): array
  112. {
  113. $roles = $this->roles;
  114. // guarantee every user at least has ROLE_USER
  115. $roles[] = 'ROLE_USER';
  116. return array_unique($roles);
  117. }
  118. public function setRoles(array $roles): self
  119. {
  120. $this->roles = $roles;
  121. return $this;
  122. }
  123. public function addRole(string $role):self
  124. {
  125. $this->roles[] = $role;
  126. return $this;
  127. }
  128. /**
  129. * @see PasswordAuthenticatedUserInterface
  130. */
  131. public function getPassword(): string
  132. {
  133. return $this->password;
  134. }
  135. public function setPassword(string $password): self
  136. {
  137. $this->password = $password;
  138. return $this;
  139. }
  140. /**
  141. * Returning a salt is only needed, if you are not using a modern
  142. * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  143. *
  144. * @see UserInterface
  145. */
  146. public function getSalt(): ?string
  147. {
  148. return null;
  149. }
  150. /**
  151. * @see UserInterface
  152. */
  153. public function eraseCredentials()
  154. {
  155. // If you store any temporary, sensitive data on the user, clear it here
  156. // $this->plainPassword = null;
  157. }
  158. public function isVerified(): bool
  159. {
  160. return $this->isVerified;
  161. }
  162. public function setIsVerified(bool $isVerified): self
  163. {
  164. $this->isVerified = $isVerified;
  165. return $this;
  166. }
  167. public function getContact(): ?Contact
  168. {
  169. return $this->contact;
  170. }
  171. public function setContact(Contact $contact): self
  172. {
  173. $this->contact = $contact;
  174. return $this;
  175. }
  176. /**
  177. * @return Collection|ConnexionLog[]
  178. */
  179. public function getConnexionLogs(): Collection
  180. {
  181. return $this->connexionLogs;
  182. }
  183. public function addConnexionLog(ConnexionLog $connexionLog): self
  184. {
  185. if (!$this->connexionLogs->contains($connexionLog)) {
  186. $this->connexionLogs[] = $connexionLog;
  187. $connexionLog->setUser($this);
  188. }
  189. return $this;
  190. }
  191. public function removeConnexionLog(ConnexionLog $connexionLog): self
  192. {
  193. if ($this->connexionLogs->removeElement($connexionLog)) {
  194. // set the owning side to null (unless already changed)
  195. if ($connexionLog->getUser() === $this) {
  196. $connexionLog->setUser(null);
  197. }
  198. }
  199. return $this;
  200. }
  201. public function getIsActive(): ?bool
  202. {
  203. return $this->isActive;
  204. }
  205. public function setIsActive(?bool $isActive): self
  206. {
  207. $this->isActive = $isActive;
  208. return $this;
  209. }
  210. public function getHasOptin(): ?bool
  211. {
  212. return $this->hasOptin;
  213. }
  214. public function setHasOptin(?bool $isActive): self
  215. {
  216. $this->hasOptin = $isActive;
  217. return $this;
  218. }
  219. /**
  220. * Return only the security relevant data
  221. *
  222. * @return array
  223. */
  224. public function __serialize(): array
  225. {
  226. return [
  227. 'id' => $this->id,
  228. 'email' => $this->email,
  229. 'password' => $this->password,
  230. ];
  231. }
  232. /**
  233. * Restore security relevant data
  234. *
  235. * @param array $data
  236. */
  237. public function __unserialize(array $data): void
  238. {
  239. $this->id = $data['id'];
  240. $this->email = $data['email'];
  241. $this->password = $data['password'];
  242. }
  243. public function getCount(): ?int
  244. {
  245. return $this->count;
  246. }
  247. public function setCount(int $count): self
  248. {
  249. $this->count = $count;
  250. return $this;
  251. }
  252. }