src/Entity/User.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Localisation\CountryInfo;
  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\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use function Symfony\Component\String\u;
  12. /**
  13. * @ORM\Table(name="app_users")
  14. * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  15. * @ORM\HasLifecycleCallbacks()
  16. * @UniqueEntity(
  17. * fields={"email"},
  18. * message="Cet email est déjà enregistré dans notre base de donnée, veuillez vous connecter"
  19. * )
  20. */
  21. class User implements UserInterface, PasswordAuthenticatedUserInterface
  22. {
  23. /**
  24. * @ORM\Id()
  25. * @ORM\GeneratedValue()
  26. * @ORM\Column(type="integer")
  27. */
  28. private $id;
  29. /**
  30. * @ORM\Column(type="string", length=180, unique=true)
  31. * @Assert\NotBlank(message="Merci de renseigner votre email")
  32. * @Assert\Email(message="Merci de renseigner un email valide")
  33. */
  34. private $email;
  35. /**
  36. * @var string The hashed password
  37. * @Assert\NotBlank(message="Merci de renseigner un mot de passe")
  38. * @ORM\Column(type="string")
  39. */
  40. private $password;
  41. /**
  42. * @ORM\Column(type="string", length=255)
  43. * @Assert\NotBlank(message="Merci de renseigner votre prénom")
  44. */
  45. private $firstname;
  46. /**
  47. * @ORM\Column(type="string", length=255)
  48. * @Assert\NotBlank(message="Merci de renseigner votre nom de famille")
  49. */
  50. private $lastname;
  51. /**
  52. * @ORM\Column(type="integer", nullable=true)
  53. */
  54. private $phone;
  55. /**
  56. * @ORM\Column(type="datetime")
  57. */
  58. private $registrationDate;
  59. /**
  60. * @ORM\OneToOne(targetEntity="App\Entity\Teacher", mappedBy="userId", cascade={"persist", "remove"})
  61. */
  62. private $teacher;
  63. /**
  64. * @ORM\OneToMany(targetEntity="App\Entity\Child", mappedBy="parent", orphanRemoval=true)
  65. */
  66. private $children;
  67. /**
  68. * @ORM\ManyToOne(targetEntity="App\Entity\Gender", inversedBy="users")
  69. * @ORM\JoinColumn(nullable=true)
  70. */
  71. private $gender;
  72. /**
  73. * @ORM\Column(type="json")
  74. */
  75. private $roles = [];
  76. /**
  77. * @ORM\OneToMany(targetEntity="SessionOrder", mappedBy="students")
  78. */
  79. private $sessionOrder;
  80. /**
  81. * @ORM\OneToMany(targetEntity="App\Entity\SubscriptionOrder", mappedBy="user")
  82. */
  83. private $subscriptionOrders;
  84. /**
  85. * @ORM\Column(type="string", length=100, nullable=true)
  86. */
  87. private $language;
  88. /**
  89. * @ORM\Column(type="string", length=50, nullable=true)
  90. */
  91. private $pole;
  92. /**
  93. * @ORM\OneToMany(targetEntity="App\Entity\OldUserEmail", mappedBy="user")
  94. */
  95. private $oldUserEmails;
  96. /**
  97. * @ORM\Column(type="string", length=255, nullable=true)
  98. */
  99. private $forumUrl;
  100. /**
  101. * @ORM\Column(type="datetime")
  102. */
  103. private $agreedTermsAt;
  104. /**
  105. * @ORM\Column(type="string", length=255, nullable=true)
  106. */
  107. private $stripeCustomerIdForSubscription;
  108. /**
  109. * @ORM\Column(type="string", length=255, nullable=true)
  110. */
  111. private $stripeCustomerIdForGroupSession
  112. ;
  113. /**
  114. * @ORM\OneToMany(targetEntity="VideoCoursesRegistration", mappedBy="user")
  115. */
  116. private $videoCoursesRegistration;
  117. /**
  118. * @ORM\OneToMany(targetEntity="App\Entity\Notifications", mappedBy="UserAccount")
  119. */
  120. private $notifications;
  121. /**
  122. * @ORM\OneToMany(targetEntity="App\Entity\TicketOrder", mappedBy="user", orphanRemoval=true)
  123. */
  124. private $ticketOrders;
  125. /**
  126. * @ORM\OneToMany(targetEntity=UserPlacementTest::class, mappedBy="user")
  127. */
  128. private $userPlacementTests;
  129. /**
  130. * @ORM\OneToMany(targetEntity=Exam::class, mappedBy="user", orphanRemoval=true)
  131. */
  132. private $exams;
  133. /**
  134. * @ORM\OneToMany(targetEntity=TrainingReport::class, mappedBy="user", orphanRemoval=true)
  135. */
  136. private $trainingReports;
  137. /**
  138. * @ORM\ManyToOne(targetEntity=CountryInfo::class, inversedBy="users")
  139. */
  140. private $country;
  141. public function __construct()
  142. {
  143. $this->children = new ArrayCollection();
  144. $this->sessionOrder = new ArrayCollection();
  145. $this->subscriptionOrders = new ArrayCollection();
  146. $this->oldUserEmails = new ArrayCollection();
  147. $this->videoCoursesRegistration = new ArrayCollection();
  148. $this->notifications = new ArrayCollection();
  149. $this->ticketOrders = new ArrayCollection();
  150. $this->userPlacementTests = new ArrayCollection();
  151. $this->exams = new ArrayCollection();
  152. $this->trainingReports = new ArrayCollection();
  153. }
  154. /**
  155. * @ORM\PrePersist
  156. * @ORM\PreUpdate
  157. */
  158. public function prePersist() {
  159. if(empty($this->registrationDate)) {
  160. $this->registrationDate = new \DateTimeImmutable();
  161. }
  162. }
  163. public function getId(): ?int
  164. {
  165. return $this->id;
  166. }
  167. public function getEmail(): ?string
  168. {
  169. return $this->email;
  170. }
  171. public function setEmail(string $email): self
  172. {
  173. $email = u($email)->lower()->toString();
  174. $this->email = $email;
  175. return $this;
  176. }
  177. /**
  178. * A visual identifier that represents this user.
  179. *
  180. * @see UserInterface
  181. */
  182. public function getUsername(): string
  183. {
  184. return (string) $this->email;
  185. }
  186. /**
  187. * @see UserInterface
  188. public function getRoles(): array
  189. {
  190. return [$this->getRole()];
  191. }
  192. */
  193. /**
  194. * @see UserInterface
  195. */
  196. public function getRoles(): array
  197. {
  198. $roles = $this->roles;
  199. // guarantee every user at least has ROLE_USER
  200. $roles[] = 'ROLE_USER';
  201. return array_unique($roles);
  202. }
  203. public function setRoles(array $roles): self
  204. {
  205. $this->roles = $roles;
  206. return $this;
  207. }
  208. /**
  209. * @see UserInterface
  210. */
  211. public function getPassword(): string
  212. {
  213. return (string) $this->password;
  214. }
  215. public function setPassword(string $password): self
  216. {
  217. $this->password = $password;
  218. return $this;
  219. }
  220. /**
  221. * @see UserInterface
  222. */
  223. public function getSalt()
  224. {
  225. // not needed when using the "bcrypt" algorithm in security.yaml
  226. }
  227. /**
  228. * @see UserInterface
  229. */
  230. public function eraseCredentials()
  231. {
  232. // If you store any temporary, sensitive data on the user, clear it here
  233. // $this->plainPassword = null;
  234. }
  235. public function getFirstname(): ?string
  236. {
  237. return $this->firstname;
  238. }
  239. public function setFirstname(string $firstname): self
  240. {
  241. $this->firstname = $firstname;
  242. return $this;
  243. }
  244. public function getLastname(): ?string
  245. {
  246. return $this->lastname;
  247. }
  248. public function setLastname(string $lastname): self
  249. {
  250. $this->lastname = $lastname;
  251. return $this;
  252. }
  253. public function getFullname(){
  254. return trim($this->getFirstname().' '.$this->getLastname());
  255. }
  256. public function getPhone(): ?int
  257. {
  258. return $this->phone;
  259. }
  260. public function setPhone(?int $phone): self
  261. {
  262. $this->phone = $phone;
  263. return $this;
  264. }
  265. public function getRegistrationDate(): ?\DateTimeInterface
  266. {
  267. return $this->registrationDate;
  268. }
  269. public function setRegistrationDate(\DateTimeInterface $registrationDate): self
  270. {
  271. $this->registrationDate = $registrationDate;
  272. return $this;
  273. }
  274. public function getTeacher(): ?Teacher
  275. {
  276. return $this->teacher;
  277. }
  278. public function setTeacher(Teacher $teacher): self
  279. {
  280. $this->teacher = $teacher;
  281. // set the owning side of the relation if necessary
  282. if ($this !== $teacher->getUserId()) {
  283. $teacher->setUserId($this);
  284. }
  285. return $this;
  286. }
  287. /**
  288. * @ORM\PrePersist()
  289. *
  290. * @return void
  291. */
  292. public function setRegistrationDateOnPersist()
  293. {
  294. $this->registrationDate = new \DateTime();
  295. }
  296. public function getGender(): ?Gender
  297. {
  298. return $this->gender;
  299. }
  300. public function setGender(?Gender $gender): self
  301. {
  302. $this->gender = $gender;
  303. return $this;
  304. }
  305. /**
  306. * @return Collection|Child[]
  307. */
  308. public function getChildren(): Collection
  309. {
  310. return $this->children;
  311. }
  312. public function addChild(Child $child): self
  313. {
  314. if (!$this->children->contains($child)) {
  315. $this->children[] = $child;
  316. $child->setParent($this);
  317. }
  318. return $this;
  319. }
  320. public function removeChild(Child $child): self
  321. {
  322. if ($this->children->contains($child)) {
  323. $this->children->removeElement($child);
  324. // set the owning side to null (unless already changed)
  325. if ($child->getParent() === $this) {
  326. $child->setParent(null);
  327. }
  328. }
  329. return $this;
  330. }
  331. /**
  332. * @return Collection|SessionOrder[]
  333. */
  334. public function getSessionOrder(): Collection
  335. {
  336. return $this->sessionOrder;
  337. }
  338. public function addSessionOrder(SessionOrder $sessionOrder): self
  339. {
  340. if (!$this->sessionOrder->contains($sessionOrder)) {
  341. $this->sessionOrder[] = $sessionOrder;
  342. $sessionOrder->setStudents($this);
  343. }
  344. return $this;
  345. }
  346. public function removeSessionOrder(SessionOrder $sessionOrder): self
  347. {
  348. if ($this->sessionOrder->contains($sessionOrder)) {
  349. $this->sessionOrder->removeElement($sessionOrder);
  350. // set the owning side to null (unless already changed)
  351. if ($sessionOrder->getStudents() === $this) {
  352. $sessionOrder->setStudents(null);
  353. }
  354. }
  355. return $this;
  356. }
  357. public function __toString()
  358. {
  359. return $this->getFullname();
  360. }
  361. /**
  362. * @return Collection|SubscriptionOrder[]
  363. */
  364. public function getSubscriptionOrders(): Collection
  365. {
  366. return $this->subscriptionOrders;
  367. }
  368. public function addSubscriptionOrder(SubscriptionOrder $subscriptionOrder): self
  369. {
  370. if (!$this->subscriptionOrders->contains($subscriptionOrder)) {
  371. $this->subscriptionOrders[] = $subscriptionOrder;
  372. $subscriptionOrder->setUser($this);
  373. }
  374. return $this;
  375. }
  376. public function removeSubscriptionOrder(SubscriptionOrder $subscriptionOrder): self
  377. {
  378. if ($this->subscriptionOrders->contains($subscriptionOrder)) {
  379. $this->subscriptionOrders->removeElement($subscriptionOrder);
  380. // set the owning side to null (unless already changed)
  381. if ($subscriptionOrder->getUser() === $this) {
  382. $subscriptionOrder->setUser(null);
  383. }
  384. }
  385. return $this;
  386. }
  387. public function getLanguage(): ?string
  388. {
  389. return $this->language;
  390. }
  391. public function setLanguage(?string $language): self
  392. {
  393. $this->language = $language;
  394. return $this;
  395. }
  396. public function getPole(): ?string
  397. {
  398. return $this->pole;
  399. }
  400. public function setPole(?string $pole): self
  401. {
  402. $this->pole = $pole;
  403. return $this;
  404. }
  405. /**
  406. * @return Collection|OldUserEmail[]
  407. */
  408. public function getOldUserEmails(): Collection
  409. {
  410. return $this->oldUserEmails;
  411. }
  412. public function addOldUserEmail(OldUserEmail $oldUserEmail): self
  413. {
  414. if (!$this->oldUserEmails->contains($oldUserEmail)) {
  415. $this->oldUserEmails[] = $oldUserEmail;
  416. $oldUserEmail->setUser($this);
  417. }
  418. return $this;
  419. }
  420. public function removeOldUserEmail(OldUserEmail $oldUserEmail): self
  421. {
  422. if ($this->oldUserEmails->contains($oldUserEmail)) {
  423. $this->oldUserEmails->removeElement($oldUserEmail);
  424. // set the owning side to null (unless already changed)
  425. if ($oldUserEmail->getUser() === $this) {
  426. $oldUserEmail->setUser(null);
  427. }
  428. }
  429. return $this;
  430. }
  431. public function getForumUrl(): ?string
  432. {
  433. return $this->forumUrl;
  434. }
  435. public function setForumUrl(?string $forumUrl): self
  436. {
  437. $this->forumUrl = $forumUrl;
  438. return $this;
  439. }
  440. public function getAgreedTermsAt(): ?\DateTimeInterface
  441. {
  442. return $this->agreedTermsAt;
  443. }
  444. public function agreedTerms(): self
  445. {
  446. $this->agreedTermsAt = new \DateTime();
  447. return $this;
  448. }
  449. public function getStripeCustomerIdForSubscription(): ?string
  450. {
  451. return $this->stripeCustomerIdForSubscription;
  452. }
  453. public function setStripeCustomerIdForSubscription(?string $stripeCustomerIdForSubscription): self
  454. {
  455. $this->stripeCustomerIdForSubscription = $stripeCustomerIdForSubscription;
  456. return $this;
  457. }
  458. public function getStripeCustomerIdForGroupSession(): ?string
  459. {
  460. return $this->stripeCustomerIdForGroupSession;
  461. }
  462. public function setStripeCustomerIdForGroupSession(?string $stripeCustomerIdForGroupSession): self
  463. {
  464. $this->stripeCustomerIdForGroupSession = $stripeCustomerIdForGroupSession;
  465. return $this;
  466. }
  467. /**
  468. * @return Collection|VideoCoursesRegistration[]
  469. */
  470. public function getVideoCoursesRegistration(): Collection
  471. {
  472. return $this->videoCoursesRegistration;
  473. }
  474. public function addVideoCoursesStudent(VideoCoursesRegistration $videoCoursesRegistration): self
  475. {
  476. if (!$this->videoCoursesRegistration->contains($videoCoursesRegistration)) {
  477. $this->videoCoursesRegistration[] = $videoCoursesRegistration;
  478. $videoCoursesRegistration->setUser($this);
  479. }
  480. return $this;
  481. }
  482. public function removeVideoCoursesStudent(VideoCoursesRegistration $videoCoursesRegistration): self
  483. {
  484. if ($this->videoCoursesRegistration->contains($videoCoursesRegistration)) {
  485. $this->videoCoursesRegistration->removeElement($videoCoursesRegistration);
  486. // set the owning side to null (unless already changed)
  487. if ($videoCoursesRegistration->getUser() === $this) {
  488. $videoCoursesRegistration->setUser(null);
  489. }
  490. }
  491. return $this;
  492. }
  493. /**
  494. * @return Collection|Notifications[]
  495. */
  496. public function getNotifications(): Collection
  497. {
  498. return $this->notifications;
  499. }
  500. public function addNotification(Notifications $notification): self
  501. {
  502. if (!$this->notifications->contains($notification)) {
  503. $this->notifications[] = $notification;
  504. $notification->setUserAccount($this);
  505. }
  506. return $this;
  507. }
  508. public function removeNotification(Notifications $notification): self
  509. {
  510. if ($this->notifications->contains($notification)) {
  511. $this->notifications->removeElement($notification);
  512. // set the owning side to null (unless already changed)
  513. if ($notification->getUserAccount() === $this) {
  514. $notification->setUserAccount(null);
  515. }
  516. }
  517. return $this;
  518. }
  519. /**
  520. * @return Collection|TicketOrder[]
  521. */
  522. public function getTicketOrders(): Collection
  523. {
  524. return $this->ticketOrders;
  525. }
  526. public function addTicketOrder(TicketOrder $ticketOrder): self
  527. {
  528. if (!$this->ticketOrders->contains($ticketOrder)) {
  529. $this->ticketOrders[] = $ticketOrder;
  530. $ticketOrder->setUser($this);
  531. }
  532. return $this;
  533. }
  534. public function removeTicketOrder(TicketOrder $ticketOrder): self
  535. {
  536. if ($this->ticketOrders->contains($ticketOrder)) {
  537. $this->ticketOrders->removeElement($ticketOrder);
  538. // set the owning side to null (unless already changed)
  539. if ($ticketOrder->getUser() === $this) {
  540. $ticketOrder->setUser(null);
  541. }
  542. }
  543. return $this;
  544. }
  545. /**
  546. * @return Collection|UserPlacementTest[]
  547. */
  548. public function getUserPlacementTests(): Collection
  549. {
  550. return $this->userPlacementTests;
  551. }
  552. public function addUserPlacementTest(UserPlacementTest $userPlacementTest): self
  553. {
  554. if (!$this->userPlacementTests->contains($userPlacementTest)) {
  555. $this->userPlacementTests[] = $userPlacementTest;
  556. $userPlacementTest->setUser($this);
  557. }
  558. return $this;
  559. }
  560. public function removeUserPlacementTest(UserPlacementTest $userPlacementTest): self
  561. {
  562. if ($this->userPlacementTests->removeElement($userPlacementTest)) {
  563. // set the owning side to null (unless already changed)
  564. if ($userPlacementTest->getUser() === $this) {
  565. $userPlacementTest->setUser(null);
  566. }
  567. }
  568. return $this;
  569. }
  570. /**
  571. * @return Collection|Exam[]
  572. */
  573. public function getExams(): Collection
  574. {
  575. return $this->exams;
  576. }
  577. public function addExam(Exam $exam): self
  578. {
  579. if (!$this->exams->contains($exam)) {
  580. $this->exams[] = $exam;
  581. $exam->setUser($this);
  582. }
  583. return $this;
  584. }
  585. public function removeExam(Exam $exam): self
  586. {
  587. if ($this->exams->removeElement($exam)) {
  588. // set the owning side to null (unless already changed)
  589. if ($exam->getUser() === $this) {
  590. $exam->setUser(null);
  591. }
  592. }
  593. return $this;
  594. }
  595. /**
  596. * @return Collection|TrainingReport[]
  597. */
  598. public function getTrainingReports(): Collection
  599. {
  600. return $this->trainingReports;
  601. }
  602. public function addTrainingReport(TrainingReport $trainingReport): self
  603. {
  604. if (!$this->trainingReports->contains($trainingReport)) {
  605. $this->trainingReports[] = $trainingReport;
  606. $trainingReport->setUser($this);
  607. }
  608. return $this;
  609. }
  610. public function removeTrainingReport(TrainingReport $trainingReport): self
  611. {
  612. if ($this->trainingReports->removeElement($trainingReport)) {
  613. // set the owning side to null (unless already changed)
  614. if ($trainingReport->getUser() === $this) {
  615. $trainingReport->setUser(null);
  616. }
  617. }
  618. return $this;
  619. }
  620. public function getCountry(): ?CountryInfo
  621. {
  622. return $this->country;
  623. }
  624. public function setCountry(?CountryInfo $country): self
  625. {
  626. $this->country = $country;
  627. return $this;
  628. }
  629. }