src/Entity/Core/Users.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Core;
  3. use App\Entity\Cvs\Candidates;
  4. use App\Repository\Core\UsersRepository;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  11. use Symfony\Component\HttpFoundation\File\File;
  12. use Symfony\Component\HttpFoundation\File\UploadedFile;
  13. use Vich\UploaderBundle\Entity\File as EmbeddedFile;
  14. use ApiPlatform\Core\Annotation\ApiResource;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. use Symfony\Component\Serializer\Annotation\SerializedName;
  17. use Serializable;
  18. use DateTimeImmutable;
  19. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  20. use Vich\UploaderBundle\Templating\Helper\UploaderHelper;
  21. /**
  22. * @ORM\Entity(repositoryClass=UsersRepository::class)
  23. * @ORM\Table(name="users")
  24. * @ORM\HasLifecycleCallbacks()
  25. * @Vich\Uploadable
  26. *
  27. * @ApiResource(
  28. * normalizationContext={"groups"={"user:read"}},
  29. * denormalizationContext={"groups"={"user:write"}}
  30. * )
  31. */
  32. class Users implements UserInterface, PasswordAuthenticatedUserInterface, \Serializable
  33. {
  34. /**
  35. * @ORM\Id
  36. * @ORM\GeneratedValue
  37. * @ORM\Column(type="integer")
  38. *
  39. * @Groups("user:read")
  40. */
  41. private $id;
  42. /**
  43. * @var datetime
  44. *
  45. * @ORM\Column(name="createdAt", type="datetime", nullable=true)
  46. *
  47. * @Groups("user:read")
  48. */
  49. private $createdAt;
  50. /**
  51. * @var datetime
  52. *
  53. * @ORM\Column(name="updatedAt", type="datetime", nullable=true)
  54. */
  55. private $updatedAt;
  56. /**
  57. * @var datetime
  58. *
  59. * @ORM\Column(name="last_login", type="datetime", nullable=true)
  60. */
  61. private $lastLogin;
  62. /**
  63. * @ORM\Column(type="string", length=180, unique=true)
  64. * @Groups("user:read")
  65. */
  66. private $email;
  67. /**
  68. * @ORM\Column(type="string", length=180, nullable=true)
  69. * @Groups("user:read")
  70. */
  71. private $name;
  72. /**
  73. * @ORM\Column(type="string", length=180, nullable=true)
  74. * @Groups("user:read")
  75. */
  76. private $lastname;
  77. /**
  78. * @ORM\Column(type="json")
  79. */
  80. private $roles = [];
  81. /**
  82. * @var string The hashed password
  83. * @ORM\Column(type="string")
  84. */
  85. private $password;
  86. /**
  87. * @ORM\Column(type="string", length=180, nullable=true)
  88. */
  89. private $username;
  90. /**
  91. * @ORM\Column(type="boolean", length=180, nullable=true)
  92. */
  93. private $first;
  94. /**
  95. * @ORM\Column(type="boolean", length=180, nullable=true)
  96. */
  97. private $enabled;
  98. /**
  99. * @ORM\Column(type="boolean", length=11, nullable=true)
  100. */
  101. private $verification;
  102. /**
  103. * @var string
  104. *
  105. * @ORM\Column(name="premium", type="boolean", nullable=false)
  106. */
  107. private $premium;
  108. /**
  109. * NOTE: This is not a mapped field of entity metadata, just a simple property.
  110. *
  111. * @Vich\UploadableField(mapping="avatars_files", fileNameProperty="image.name", size="image.size", mimeType="image.mimeType", originalName="image.originalName", dimensions="image.dimensions")
  112. *
  113. * @var File|null
  114. */
  115. private $imageFile;
  116. /**
  117. * @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
  118. *
  119. * @var EmbeddedFile
  120. */
  121. private $image;
  122. /**
  123. * @var \Agencies
  124. *
  125. * @ORM\ManyToOne(targetEntity="App\Entity\Core\Agencies")
  126. * @ORM\JoinColumns({
  127. * @ORM\JoinColumn(name="current_agency_id", referencedColumnName="id", nullable=true)
  128. * })
  129. */
  130. protected $currentAgency;
  131. /**
  132. * @ORM\Column(name="password_forgotten", type="string", length=180, nullable=true)
  133. */
  134. private $passwordForgotten;
  135. /**
  136. * @var datetime
  137. *
  138. * @ORM\Column(name="password_forgotten_last_date", type="datetime", nullable=true)
  139. */
  140. private $passwordForgottenLastDate;
  141. /**
  142. * @var string
  143. *
  144. * @ORM\Column(name="partenariat", type="boolean", nullable=true)
  145. */
  146. private $partenariat;
  147. /**
  148. * @ORM\Column(name="description", type="text", nullable=true)
  149. */
  150. private $description;
  151. /**
  152. * @var string
  153. *
  154. * @ORM\Column(name="notifications_messages", type="boolean", nullable=true)
  155. */
  156. private $notificationsMessages;
  157. /**
  158. * @var string
  159. *
  160. * @ORM\Column(name="notifications_suivis", type="boolean", nullable=true)
  161. */
  162. private $notificationsSuivis;
  163. /**
  164. * @var string
  165. *
  166. * @ORM\Column(name="user_commission_unit", type="float", length=11, nullable=true)
  167. */
  168. private $userCommissionUnit;
  169. /**
  170. * @var string
  171. *
  172. * @ORM\Column(name="user_commission_pourcent", type="float", length=11, nullable=true)
  173. */
  174. private $userCommissionPourcent;
  175. /**
  176. * @var string
  177. *
  178. * @ORM\Column(name="type_account", type="string", length=255, nullable=true)
  179. */
  180. private $typeAccount;
  181. /**
  182. * @var \Candidates
  183. *
  184. * @ORM\ManyToOne(targetEntity="App\Entity\Cvs\Candidates")
  185. * @ORM\JoinColumns({
  186. * @ORM\JoinColumn(name="candidate_id", referencedColumnName="id", nullable=true)
  187. * })
  188. */
  189. protected $candidate;
  190. /**
  191. * @var string
  192. *
  193. * @ORM\Column(name="subscription_customer_stripe", type="string", length=255, nullable=true)
  194. */
  195. private $subscriptionCustomerStripe;
  196. /**
  197. * @ORM\Column(type="string", length=255, nullable=true)
  198. */
  199. private $verificationToken;
  200. /**
  201. * @ORM\Column(type="datetime", nullable=true)
  202. */
  203. private $tokenExpiration;
  204. /**
  205. * @ORM\Column(name="language", type="text", nullable=true)
  206. */
  207. private $language;
  208. /**
  209. * @ORM\Column(name="motif_verification", type="text", nullable=true)
  210. */
  211. private $motif;
  212. public function __construct()
  213. {
  214. $this->image = new \Vich\UploaderBundle\Entity\File();
  215. }
  216. /**
  217. * @ORM\PrePersist
  218. */
  219. public function setCreatedAtValue(): void
  220. {
  221. $this->setCreatedAt( new \DateTime("now"));
  222. $this->setUpdatedAt( new \DateTime("now"));
  223. $this->setPremium(false);
  224. }
  225. /**
  226. * @ORM\PreUpdate
  227. */
  228. public function setUpdatedAtValue(): void
  229. {
  230. $this->setUpdatedAt( new \DateTime("now"));
  231. }
  232. public function __toString()
  233. {
  234. return "#".$this->id." ".$this->getName()." ".$this->getLastname().' ('.$this->getEmail().')';
  235. }
  236. public function getTitlePartner(): ?string
  237. {
  238. return "#".$this->id." ".$this->getName()." ".$this->getLastname();
  239. }
  240. public function serialize(): string
  241. {
  242. return serialize([
  243. $this->id,
  244. $this->email,
  245. $this->password,
  246. // autres propriétés que vous souhaitez sérialiser, sauf $imageFile
  247. ]);
  248. }
  249. public function unserialize($serialized): void
  250. {
  251. list(
  252. $this->id,
  253. $this->email,
  254. $this->password,
  255. // autres propriétés que vous souhaitez désérialiser, sauf $imageFile
  256. ) = unserialize($serialized);
  257. }
  258. public function getId(): ?int
  259. {
  260. return $this->id;
  261. }
  262. /**
  263. * Retourne l'identifiant unique de l'utilisateur pour Symfony 5.3+
  264. * On utilise l'email comme identifiant
  265. */
  266. public function getUserIdentifier(): string
  267. {
  268. return (string) $this->email;
  269. }
  270. public function getEmail(): ?string
  271. {
  272. return $this->email;
  273. }
  274. public function setEmail(string $email): self
  275. {
  276. $this->email = $email;
  277. return $this;
  278. }
  279. /**
  280. * @see UserInterface
  281. */
  282. public function getRoles(): array
  283. {
  284. $roles = $this->roles;
  285. // guarantee every user at least has ROLE_USER
  286. $roles[] = 'ROLE_USER';
  287. return array_unique($roles);
  288. }
  289. public function setRoles(array $roles): self
  290. {
  291. $this->roles = $roles;
  292. return $this;
  293. }
  294. /**
  295. * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  296. * of 'UploadedFile' is injected into this setter to trigger the update. If this
  297. * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  298. * must be able to accept an instance of 'File' as the bundle will inject one here
  299. * during Doctrine hydration.
  300. *
  301. * @param File|UploadedFile|null $imageFile
  302. */
  303. public function setImageFile(?File $imageFile = null)
  304. {
  305. $this->imageFile = $imageFile;
  306. if (null !== $imageFile) {
  307. // It is required that at least one field changes if you are using doctrine
  308. // otherwise the event listeners won't be called and the file is lost
  309. $this->setUpdatedAt(new \DateTime("now"));
  310. }
  311. }
  312. public function getImageFile(): ?File
  313. {
  314. return $this->imageFile;
  315. }
  316. public function getImageBase64(): ?string
  317. {
  318. if (!$this->image || !$this->image->getName()) {
  319. return null;
  320. }
  321. // Utiliser $_SERVER['DOCUMENT_ROOT'] qui pointe vers /public
  322. $filePath = $_SERVER['DOCUMENT_ROOT'] . '/uploads/avatars/' . $this->image->getName();
  323. if (!file_exists($filePath)) {
  324. // Debug : retourner le chemin pour voir ce qui cloche
  325. return null; // ou "Path: " . $filePath pour debugger
  326. }
  327. $imageData = file_get_contents($filePath);
  328. $mimeType = $this->image->getMimeType() ?? mime_content_type($filePath);
  329. return 'data:' . $mimeType . ';base64,' . base64_encode($imageData);
  330. }
  331. public function setImage(EmbeddedFile $image): void
  332. {
  333. $this->image = $image;
  334. }
  335. public function getImage(): ?EmbeddedFile
  336. {
  337. return $this->image;
  338. }
  339. /**
  340. * @see UserInterface
  341. */
  342. public function getPassword(): string
  343. {
  344. return (string) $this->password;
  345. }
  346. /**
  347. * @see UserInterface
  348. */
  349. public function getUsername(): string
  350. {
  351. return (string) $this->username;
  352. }
  353. public function setPassword(string $password): self
  354. {
  355. $this->password = $password;
  356. return $this;
  357. }
  358. /**
  359. * @see UserInterface
  360. */
  361. public function getSalt()
  362. {
  363. // not needed when using the "bcrypt" algorithm in security.yaml
  364. }
  365. /**
  366. * @see UserInterface
  367. */
  368. public function eraseCredentials()
  369. {
  370. // If you store any temporary, sensitive data on the user, clear it here
  371. // $this->plainPassword = null;
  372. }
  373. public function getCreatedAt(): ?\DateTimeInterface
  374. {
  375. return $this->createdAt;
  376. }
  377. public function setCreatedAt(?\DateTimeInterface $createdAt): self
  378. {
  379. $this->createdAt = $createdAt;
  380. return $this;
  381. }
  382. public function getUpdatedAt(): ?\DateTimeInterface
  383. {
  384. return $this->updatedAt;
  385. }
  386. public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  387. {
  388. $this->updatedAt = $updatedAt;
  389. return $this;
  390. }
  391. public function getLastLogin(): ?\DateTimeInterface
  392. {
  393. return $this->lastLogin;
  394. }
  395. public function setLastLogin(?\DateTimeInterface $lastLogin): self
  396. {
  397. $this->lastLogin = $lastLogin;
  398. return $this;
  399. }
  400. public function getName(): ?string
  401. {
  402. return $this->name;
  403. }
  404. public function setName(?string $name): self
  405. {
  406. $this->name = $name;
  407. return $this;
  408. }
  409. public function getLastname(): ?string
  410. {
  411. return $this->lastname;
  412. }
  413. public function setLastname(?string $lastname): self
  414. {
  415. $this->lastname = $lastname;
  416. return $this;
  417. }
  418. public function setUsername(?string $username): self
  419. {
  420. $this->username = $username;
  421. return $this;
  422. }
  423. public function getFirst(): ?bool
  424. {
  425. return $this->first;
  426. }
  427. public function setFirst(?bool $first): self
  428. {
  429. $this->first = $first;
  430. return $this;
  431. }
  432. public function getEnabled(): ?bool
  433. {
  434. return $this->enabled;
  435. }
  436. public function setEnabled(?bool $enabled): self
  437. {
  438. $this->enabled = $enabled;
  439. return $this;
  440. }
  441. public function getPremium(): ?bool
  442. {
  443. return $this->premium;
  444. }
  445. public function setPremium(bool $premium): self
  446. {
  447. $this->premium = $premium;
  448. return $this;
  449. }
  450. public function getPasswordForgotten(): ?string
  451. {
  452. return $this->passwordForgotten;
  453. }
  454. public function setPasswordForgotten(?string $passwordForgotten): self
  455. {
  456. $this->passwordForgotten = $passwordForgotten;
  457. return $this;
  458. }
  459. public function getPasswordForgottenLastDate(): ?\DateTimeInterface
  460. {
  461. return $this->passwordForgottenLastDate;
  462. }
  463. public function setPasswordForgottenLastDate(?\DateTimeInterface $passwordForgottenLastDate): self
  464. {
  465. $this->passwordForgottenLastDate = $passwordForgottenLastDate;
  466. return $this;
  467. }
  468. public function getPartenariat(): ?bool
  469. {
  470. return $this->partenariat;
  471. }
  472. public function setPartenariat(?bool $partenariat): self
  473. {
  474. $this->partenariat = $partenariat;
  475. return $this;
  476. }
  477. public function getDescription(): ?string
  478. {
  479. return $this->description;
  480. }
  481. public function setDescription(?string $description): self
  482. {
  483. $this->description = $description;
  484. return $this;
  485. }
  486. public function getNotificationsMessages(): ?bool
  487. {
  488. return $this->notificationsMessages;
  489. }
  490. public function setNotificationsMessages(?bool $notificationsMessages): self
  491. {
  492. $this->notificationsMessages = $notificationsMessages;
  493. return $this;
  494. }
  495. public function getNotificationsSuivis(): ?bool
  496. {
  497. return $this->notificationsSuivis;
  498. }
  499. public function setNotificationsSuivis(?bool $notificationsSuivis): self
  500. {
  501. $this->notificationsSuivis = $notificationsSuivis;
  502. return $this;
  503. }
  504. public function getUserCommissionUnit(): ?float
  505. {
  506. return $this->userCommissionUnit;
  507. }
  508. public function setUserCommissionUnit(?float $userCommissionUnit): self
  509. {
  510. $this->userCommissionUnit = $userCommissionUnit;
  511. return $this;
  512. }
  513. public function getUserCommissionPourcent(): ?float
  514. {
  515. return $this->userCommissionPourcent;
  516. }
  517. public function setUserCommissionPourcent(?float $userCommissionPourcent): self
  518. {
  519. $this->userCommissionPourcent = $userCommissionPourcent;
  520. return $this;
  521. }
  522. public function getCurrentAgency(): ?Agencies
  523. {
  524. return $this->currentAgency;
  525. }
  526. public function setCurrentAgency(?Agencies $currentAgency): self
  527. {
  528. $this->currentAgency = $currentAgency;
  529. return $this;
  530. }
  531. public function isFirst(): ?bool
  532. {
  533. return $this->first;
  534. }
  535. public function isEnabled(): ?bool
  536. {
  537. return $this->enabled;
  538. }
  539. public function isPremium(): ?bool
  540. {
  541. return $this->premium;
  542. }
  543. public function isPartenariat(): ?bool
  544. {
  545. return $this->partenariat;
  546. }
  547. public function isNotificationsMessages(): ?bool
  548. {
  549. return $this->notificationsMessages;
  550. }
  551. public function isNotificationsSuivis(): ?bool
  552. {
  553. return $this->notificationsSuivis;
  554. }
  555. public function getTypeAccount(): ?string
  556. {
  557. return $this->typeAccount;
  558. }
  559. public function setTypeAccount(?string $description): self
  560. {
  561. $this->typeAccount = $description;
  562. return $this;
  563. }
  564. public function getCandidate(): ?Candidates
  565. {
  566. return $this->candidate;
  567. }
  568. public function setCandidate(?Candidates $candidate): static
  569. {
  570. $this->candidate = $candidate;
  571. return $this;
  572. }
  573. public function getSubscriptionCustomerStripe(): ?string
  574. {
  575. return $this->subscriptionCustomerStripe;
  576. }
  577. public function setSubscriptionCustomerStripe(?string $subscriptionCustomerStripe): static
  578. {
  579. $this->subscriptionCustomerStripe = $subscriptionCustomerStripe;
  580. return $this;
  581. }
  582. public function getVerificationToken(): ?string
  583. {
  584. return $this->verificationToken;
  585. }
  586. public function setVerificationToken(?string $verificationToken): self
  587. {
  588. $this->verificationToken = $verificationToken;
  589. return $this;
  590. }
  591. public function getTokenExpiration(): ?\DateTimeInterface
  592. {
  593. return $this->tokenExpiration;
  594. }
  595. public function setTokenExpiration(?\DateTimeInterface $tokenExpiration): self
  596. {
  597. $this->tokenExpiration = $tokenExpiration;
  598. return $this;
  599. }
  600. public function getLanguage(): ?string
  601. {
  602. return $this->language;
  603. }
  604. public function setLanguage(?string $description): self
  605. {
  606. $this->language = $description;
  607. return $this;
  608. }
  609. public function isVerification(): ?bool
  610. {
  611. return $this->verification;
  612. }
  613. public function setVerification(?bool $verification): self
  614. {
  615. $this->verification = $verification;
  616. return $this;
  617. }
  618. public function getMotif(): ?string
  619. {
  620. return $this->motif;
  621. }
  622. public function setMotif(?string $motif): self
  623. {
  624. $this->motif = $motif;
  625. return $this;
  626. }
  627. }