src/Entity/User.php line 13

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\PasswordAuthenticatedUserInterface;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
  8. #[ORM\Entity(repositoryClass: UserRepository::class)]
  9. #[ORM\Table(name: 'mstopeuser')]
  10. class User implements UserInterface, PasswordAuthenticatedUserInterface
  11. {
  12. #[ORM\Id]
  13. #[ORM\GeneratedValue]
  14. #[ORM\Column(type: 'integer')]
  15. protected ?int $id = null;
  16. #[ORM\Column(name: 'passwordChangedAt',type: 'datetime', nullable: true)]
  17. private ?\DateTimeInterface $passwordChangedAt = null;
  18. // --- Champs de base FOSUserBundle (conservés pour la migration) ---
  19. #[ORM\Column(length: 180, unique: true)]
  20. protected ?string $username = null;
  21. #[ORM\Column(length: 180, unique: true)]
  22. protected ?string $usernameCanonical = null;
  23. #[ORM\Column(length: 180, unique: true)]
  24. protected ?string $email = null;
  25. #[ORM\Column(length: 180, unique: true)]
  26. protected ?string $emailCanonical = null;
  27. #[ORM\Column(type: 'boolean')]
  28. protected ?bool $enabled = null;
  29. #[ORM\Column(length: 255)]
  30. protected ?string $salt = null;
  31. #[ORM\Column(length: 255)]
  32. protected ?string $password = null;
  33. #[ORM\Column(type: 'datetime', nullable: true)]
  34. protected ?\DateTimeInterface $lastLogin = null;
  35. #[ORM\Column(length: 255, nullable: true)]
  36. protected ?string $confirmationToken = null;
  37. #[ORM\Column(type: 'datetime', nullable: true)]
  38. protected ?\DateTimeInterface $passwordRequestedAt = null;
  39. #[ORM\Column(type: 'boolean')]
  40. protected ?bool $locked = null;
  41. #[ORM\Column(type: 'boolean')]
  42. protected ?bool $expired = null;
  43. #[ORM\Column(type: 'datetime', nullable: true)]
  44. protected ?\DateTimeInterface $expiresAt = null;
  45. #[ORM\Column(type: 'json')]
  46. protected array $roles = [];
  47. #[ORM\Column(type: 'boolean')]
  48. protected ?bool $credentialsExpired = null;
  49. #[ORM\Column(type: 'datetime', nullable: true)]
  50. protected ?\DateTimeInterface $credentialsExpireAt = null;
  51. // --- Tes champs personnalisés ---
  52. #[ORM\ManyToOne(targetEntity: SupH::class)]
  53. #[ORM\JoinColumn(name: 'supH_id',nullable: true)]
  54. private ?SupH $supH = null;
  55. #[ORM\OneToOne(targetEntity: ImageS::class, cascade: ['persist', 'remove'])]
  56. #[ORM\JoinColumn(name: 'images_id',nullable: true)]
  57. private ?ImageS $images = null;
  58. #[ORM\ManyToOne(targetEntity: ReviewTec::class)]
  59. #[ORM\JoinColumn(name: 'reviewtec_id',nullable: true)]
  60. private ?ReviewTec $reviewtec = null;
  61. #[ORM\ManyToOne(targetEntity: Approb::class)]
  62. #[ORM\JoinColumn(name: 'approb_id',nullable: true)]
  63. private ?Approb $approb = null;
  64. #[ORM\Column(name: 'nom', length: 255)]
  65. private ?string $nom = null;
  66. #[ORM\Column(name: 'idsup', type: 'integer')]
  67. private ?int $idsup = null;
  68. #[ORM\Column(name: 'equipe', length: 255, nullable: true)]
  69. private ?string $equipe = null;
  70. #[ORM\Column(name: 'prenom', length: 255)]
  71. private ?string $prenom = null;
  72. #[ORM\Column(name: 'poste', length: 255, nullable: true)]
  73. private ?string $poste = null;
  74. #[ORM\Column(name: 'service', length: 255, nullable: true)]
  75. private ?string $service = null;
  76. #[ORM\Column(name: 'tel', nullable: true)]
  77. private ?string $tel = null;
  78. #[ORM\Column(name: 'zone', length: 50, nullable: true)]
  79. private ?string $zone = null;
  80. // --- Constructeur ---
  81. public function __construct()
  82. {
  83. $this->enabled = false;
  84. $this->locked = false;
  85. $this->expired = false;
  86. $this->roles = [];
  87. $this->credentialsExpired = false;
  88. $this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
  89. $this->roles = ['ROLE_USER'];
  90. }
  91. // --- Getters et setters ---
  92. public function getId(): ?int
  93. {
  94. return $this->id;
  95. }
  96. public function getUsername(): ?string
  97. {
  98. return $this->username;
  99. }
  100. public function setUsername(string $username): self
  101. {
  102. $this->username = $username;
  103. return $this;
  104. }
  105. public function getUserIdentifier(): string
  106. {
  107. return (string) $this->username;
  108. }
  109. public function getUsernameCanonical(): ?string
  110. {
  111. return $this->usernameCanonical;
  112. }
  113. public function setUsernameCanonical(string $usernameCanonical): self
  114. {
  115. $this->usernameCanonical = $usernameCanonical;
  116. return $this;
  117. }
  118. public function getEmail(): ?string
  119. {
  120. return $this->email;
  121. }
  122. public function setEmail(string $email): self
  123. {
  124. $this->email = $email;
  125. return $this;
  126. }
  127. public function getEmailCanonical(): ?string
  128. {
  129. return $this->emailCanonical;
  130. }
  131. public function setEmailCanonical(string $emailCanonical): self
  132. {
  133. $this->emailCanonical = $emailCanonical;
  134. return $this;
  135. }
  136. public function isEnabled(): ?bool
  137. {
  138. return $this->enabled;
  139. }
  140. public function setEnabled(bool $enabled): self
  141. {
  142. $this->enabled = $enabled;
  143. return $this;
  144. }
  145. public function getSalt(): ?string
  146. {
  147. return $this->salt;
  148. }
  149. public function setSalt(string $salt): self
  150. {
  151. $this->salt = $salt;
  152. return $this;
  153. }
  154. public function getPassword(): string
  155. {
  156. return $this->password;
  157. }
  158. public function setPassword(string $password): self
  159. {
  160. $this->password = $password;
  161. return $this;
  162. }
  163. public function getLastLogin(): ?\DateTimeInterface
  164. {
  165. return $this->lastLogin;
  166. }
  167. public function setLastLogin(?\DateTimeInterface $lastLogin): self
  168. {
  169. $this->lastLogin = $lastLogin;
  170. return $this;
  171. }
  172. public function getConfirmationToken(): ?string
  173. {
  174. return $this->confirmationToken;
  175. }
  176. public function setConfirmationToken(?string $confirmationToken): self
  177. {
  178. $this->confirmationToken = $confirmationToken;
  179. return $this;
  180. }
  181. public function getPasswordRequestedAt(): ?\DateTimeInterface
  182. {
  183. return $this->passwordRequestedAt;
  184. }
  185. public function setPasswordRequestedAt(?\DateTimeInterface $passwordRequestedAt): self
  186. {
  187. $this->passwordRequestedAt = $passwordRequestedAt;
  188. return $this;
  189. }
  190. public function isLocked(): ?bool
  191. {
  192. return $this->locked;
  193. }
  194. public function setLocked(bool $locked): self
  195. {
  196. $this->locked = $locked;
  197. return $this;
  198. }
  199. public function isExpired(): ?bool
  200. {
  201. return $this->expired;
  202. }
  203. public function setExpired(bool $expired): self
  204. {
  205. $this->expired = $expired;
  206. return $this;
  207. }
  208. public function getExpiresAt(): ?\DateTimeInterface
  209. {
  210. return $this->expiresAt;
  211. }
  212. public function setExpiresAt(?\DateTimeInterface $expiresAt): self
  213. {
  214. $this->expiresAt = $expiresAt;
  215. return $this;
  216. }
  217. public function getRoles(): array
  218. {
  219. return array_unique(array_merge($this->roles, ['ROLE_USER']));
  220. }
  221. public function setRoles(array $roles): self
  222. {
  223. $this->roles = $roles;
  224. return $this;
  225. }
  226. public function isCredentialsExpired(): ?bool
  227. {
  228. return $this->credentialsExpired;
  229. }
  230. public function setCredentialsExpired(bool $credentialsExpired): self
  231. {
  232. $this->credentialsExpired = $credentialsExpired;
  233. return $this;
  234. }
  235. public function getCredentialsExpireAt(): ?\DateTimeInterface
  236. {
  237. return $this->credentialsExpireAt;
  238. }
  239. public function setCredentialsExpireAt(?\DateTimeInterface $credentialsExpireAt): self
  240. {
  241. $this->credentialsExpireAt = $credentialsExpireAt;
  242. return $this;
  243. }
  244. public function getSupH(): ?SupH
  245. {
  246. return $this->supH;
  247. }
  248. public function setSupH(?SupH $supH): self
  249. {
  250. $this->supH = $supH;
  251. return $this;
  252. }
  253. public function getImages(): ?ImageS
  254. {
  255. return $this->images;
  256. }
  257. public function setImages(?ImageS $images): self
  258. {
  259. $this->images = $images;
  260. return $this;
  261. }
  262. public function getReviewtec(): ?ReviewTec
  263. {
  264. return $this->reviewtec;
  265. }
  266. public function setReviewtec(?ReviewTec $reviewtec): self
  267. {
  268. $this->reviewtec = $reviewtec;
  269. return $this;
  270. }
  271. public function getApprob(): ?Approb
  272. {
  273. return $this->approb;
  274. }
  275. public function setApprob(?Approb $approb): self
  276. {
  277. $this->approb = $approb;
  278. return $this;
  279. }
  280. public function getNom(): ?string
  281. {
  282. return $this->nom;
  283. }
  284. public function setNom(string $nom): self
  285. {
  286. $this->nom = $nom;
  287. return $this;
  288. }
  289. public function getIdsup(): ?int
  290. {
  291. return $this->idsup;
  292. }
  293. public function setIdsup(int $idsup): self
  294. {
  295. $this->idsup = $idsup;
  296. return $this;
  297. }
  298. public function getEquipe(): ?string
  299. {
  300. return $this->equipe;
  301. }
  302. public function setEquipe(?string $equipe): self
  303. {
  304. $this->equipe = $equipe;
  305. return $this;
  306. }
  307. public function getPrenom(): ?string
  308. {
  309. return $this->prenom;
  310. }
  311. public function setPrenom(string $prenom): self
  312. {
  313. $this->prenom = $prenom;
  314. return $this;
  315. }
  316. public function getPoste(): ?string
  317. {
  318. return $this->poste;
  319. }
  320. public function setPoste(?string $poste): self
  321. {
  322. $this->poste = $poste;
  323. return $this;
  324. }
  325. public function getService(): ?string
  326. {
  327. return $this->service;
  328. }
  329. public function setService(?string $service): self
  330. {
  331. $this->service = $service;
  332. return $this;
  333. }
  334. public function getTel(): ?string
  335. {
  336. return $this->tel;
  337. }
  338. public function setTel(?string $tel): self
  339. {
  340. $this->tel = $tel;
  341. return $this;
  342. }
  343. public function getZone(): ?string
  344. {
  345. return $this->zone;
  346. }
  347. public function setZone(?string $zone): self
  348. {
  349. $this->zone = $zone;
  350. return $this;
  351. }
  352. public function eraseCredentials()
  353. {
  354. // ...
  355. }
  356. public function getPasswordChangedAt(): ?\DateTimeInterface
  357. {
  358. return $this->passwordChangedAt;
  359. }
  360. public function setPasswordChangedAt(\DateTimeInterface $date): self
  361. {
  362. $this->passwordChangedAt = $date;
  363. return $this;
  364. }
  365. #[ORM\Column(type: 'string', length: 5, nullable: true)]
  366. private ?string $locale = 'fr';
  367. public function getLocale(): ?string
  368. {
  369. return $this->locale;
  370. }
  371. public function setLocale(?string $locale): self
  372. {
  373. $this->locale = $locale;
  374. return $this;
  375. }
  376. /**
  377. * @param string $role
  378. * @param RoleHierarchyInterface|null $roleHierarchy
  379. * @return bool
  380. */
  381. public function hasRole(string $role, ?RoleHierarchyInterface $roleHierarchy = null): bool
  382. {
  383. $grantedRoles = $this->getRoles();
  384. if ($roleHierarchy) {
  385. $grantedRoles = $roleHierarchy->getReachableRoles($grantedRoles);
  386. }
  387. return in_array($role, $grantedRoles, true);
  388. }
  389. public function removeRole(string $role): self
  390. {
  391. $this->roles = array_values(array_filter(
  392. $this->roles,
  393. fn($r) => $r !== $role
  394. ));
  395. return $this;
  396. }
  397. public function __toString(): string
  398. {
  399. return $this->prenom . ' ' . $this->nom;
  400. }
  401. }