src/Entity/User.php line 267

Open in your IDE?
  1. <?php
  2. /*
  3. * Ce fichier est la propriété de l'association (c) Projets Métiers
  4. *
  5. * (c) crée par Jean-Marc CATALA <jeanmmarccatala@gmail.com>
  6. *
  7. */
  8. namespace App\Entity;
  9. use App\Repository\UserRepository;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use phpDocumentor\Reflection\Types\Boolean;
  14. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  15. use Symfony\Component\Security\Core\User\UserInterface;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use function in_array;
  18. /**
  19. * @ORM\Entity(repositoryClass=UserRepository::class)
  20. * @UniqueEntity(fields={"email"}, message="Il y a déjà un compte avec cette adresse mail.")
  21. * @method string getUserIdentifier()
  22. */
  23. class User implements UserInterface
  24. {
  25. const ROLE_COLLEGE = "ROLE_COLLEGE";
  26. const ROLE_LYCEE = "ROLE_LYCEE";
  27. const ROLE_ADULTE = "ROLE_ADULTE";
  28. const ROLE_PARENT = "ROLE_PARENT";
  29. const ROLE_PROF = "ROLE_PROF";
  30. const ROLE_CONSEILLER = "ROLE_CONSEILLER";
  31. const ROLE_MENTOR = "ROLE_MENTOR";
  32. const ROLE_EXPERT = "ROLE_EXPERT";
  33. const ROLE_ADMIN = "ROLE_ADMIN";
  34. const STATUS_ACTIF = 1;
  35. const STATUS_UNVERIFIED = 2;
  36. CONST STATUS_DELETED = 3;
  37. /**
  38. * @ORM\Id()
  39. * @ORM\GeneratedValue()
  40. * @ORM\Column(type="integer")
  41. */
  42. private $id;
  43. /**
  44. * @ORM\Column(type="string", length=180, unique=true)
  45. */
  46. private $email;
  47. /**
  48. * @ORM\Column(type="json")
  49. */
  50. private $roles = [];
  51. /**
  52. * @ORM\Column(type="string", length=255)
  53. */
  54. private $firstName;
  55. /**
  56. * @ORM\Column(type="string", length=255, nullable=true)
  57. * @Groups("main")
  58. */
  59. private $twitterUsername;
  60. /**
  61. * @ORM\Column(type="string", length=255)
  62. */
  63. private $password;
  64. /**
  65. * @ORM\Column(type="boolean")
  66. */
  67. private $isVerified = false;
  68. /**
  69. * @ORM\ManyToOne(targetEntity=Step::class, inversedBy="users")
  70. */
  71. private $step;
  72. /**
  73. * @ORM\ManyToOne(targetEntity=Question::class, inversedBy="users")
  74. */
  75. private $question;
  76. /**
  77. * @ORM\OneToMany(targetEntity=UserAnswer::class, mappedBy="user")
  78. */
  79. private $answers;
  80. /**
  81. * @ORM\Column(type="string", length=255, nullable=true)
  82. */
  83. private $name;
  84. /**
  85. * @ORM\OneToMany(targetEntity=UserAnswerAdd::class, mappedBy="user")
  86. */
  87. private $userAnswerAdds;
  88. /**
  89. * @ORM\Column(type="smallint")
  90. */
  91. private $status = self::STATUS_UNVERIFIED;
  92. /**
  93. * @ORM\Column(type="string", length=255, nullable=true)
  94. */
  95. private $token;
  96. /**
  97. * @ORM\Column(type="string", length=255, nullable=true)
  98. */
  99. private $emailParent1;
  100. /**
  101. * @ORM\Column(type="string", length=255, nullable=true)
  102. */
  103. private $emailParent2;
  104. /**
  105. * @ORM\ManyToMany(targetEntity=User::class, inversedBy="parents")
  106. */
  107. private $enfants;
  108. /**
  109. * @ORM\ManyToMany(targetEntity=User::class, mappedBy="enfants")
  110. */
  111. private $parents;
  112. /**
  113. * @ORM\ManyToOne(targetEntity=User::class, inversedBy="eleves")
  114. */
  115. private $profPrincipal;
  116. /**
  117. * @ORM\OneToMany(targetEntity=User::class, mappedBy="profPrincipal")
  118. */
  119. private $eleves;
  120. /**
  121. * @ORM\ManyToOne(targetEntity=User::class, inversedBy="mentored")
  122. */
  123. private $mentor;
  124. /**
  125. * @ORM\OneToMany(targetEntity=User::class, mappedBy="mentor")
  126. */
  127. private $mentored;
  128. /**
  129. * @ORM\ManyToOne(targetEntity=User::class, inversedBy="adultes")
  130. */
  131. private $conseille;
  132. /**
  133. * @ORM\OneToMany(targetEntity=User::class, mappedBy="conseille")
  134. */
  135. private $adultes;
  136. /**
  137. * @ORM\Column(type="string", length=255, nullable=true)
  138. */
  139. private $classe;
  140. /**
  141. * @ORM\Column(type="string", length=255, nullable=true)
  142. */
  143. /**
  144. * @ORM\ManyToMany(targetEntity=Institution::class, inversedBy="listUsers")
  145. */
  146. private $listInstitutions;
  147. /**
  148. * @ORM\Column(type="integer", nullable=true)
  149. */
  150. private $bilanStepProf;
  151. /**
  152. * @ORM\Column(type="datetime", nullable=true)
  153. */
  154. private $createdAt;
  155. /**
  156. * @ORM\Column(type="datetime", nullable=true)
  157. */
  158. private $updatedAt;
  159. /**
  160. * @ORM\Column(type="string", length=255, nullable=true)
  161. */
  162. private $role;
  163. /**
  164. * @ORM\OneToOne(targetEntity=Survey::class, inversedBy="user", cascade={"persist", "remove"})
  165. * @ORM\JoinColumn(nullable=true)
  166. */
  167. private $survey;
  168. /**
  169. * @ORM\Column(type="string", length=255, nullable=true)
  170. */
  171. private $metier;
  172. /**
  173. * @ORM\Column(type="boolean", nullable=true)
  174. */
  175. private $mustBeMentored;
  176. /**
  177. * @ORM\Column(type="boolean", nullable=true)
  178. */
  179. private $hasMentor;
  180. /**
  181. * @ORM\Column(type="string", length=255, nullable=true)
  182. */
  183. private $reset_token;
  184. /**
  185. * @ORM\Column(type="string", length=255, nullable=true)
  186. */
  187. private $codePostal;
  188. /**
  189. * @ORM\ManyToOne(targetEntity=Institution::class, inversedBy="users")
  190. */
  191. private $institution;
  192. /**
  193. * @ORM\OneToMany(targetEntity=Institution::class, mappedBy="exp")
  194. */
  195. private $exp;
  196. public function __construct()
  197. {
  198. $this->answers = new ArrayCollection();
  199. $this->userAnswerAdds = new ArrayCollection();
  200. $this->enfants = new ArrayCollection();
  201. $this->parents = new ArrayCollection();
  202. $this->eleves = new ArrayCollection();
  203. $this->adultes = new ArrayCollection();
  204. $this->listInstitutions = new ArrayCollection();
  205. $this->createdAt = new \DateTime();
  206. $this->setHasMentor(0);
  207. $this->expert = new ArrayCollection();
  208. $this->expertMetier = new ArrayCollection();
  209. $this->exp = new ArrayCollection();
  210. }
  211. public static function getRolefromString(string $string): string{
  212. switch ($string){
  213. case "college" : return self::ROLE_COLLEGE;
  214. case "lycee" : return self::ROLE_LYCEE;
  215. case "adulte" : return self::ROLE_ADULTE;
  216. case "professeur" : return self::ROLE_PROF;
  217. case "parent" : return self::ROLE_PARENT;
  218. case "conseiller" : return self::ROLE_CONSEILLER;
  219. case "mentor" : return self::ROLE_MENTOR;
  220. case "expert" : return self::ROLE_EXPERT;
  221. default: return "";
  222. }
  223. }
  224. public function getId(): ?int
  225. {
  226. return $this->id;
  227. }
  228. public function getEmail(): ?string
  229. {
  230. return $this->email;
  231. }
  232. public function setEmail(string $email): self
  233. {
  234. $this->email = $email;
  235. return $this;
  236. }
  237. /**
  238. * A visual identifier that represents this user.
  239. *
  240. * @see UserInterface
  241. */
  242. public function getUsername(): string
  243. {
  244. return (string) $this->email;
  245. }
  246. /**
  247. * @see UserInterface
  248. */
  249. public function getRoles(): array
  250. {
  251. $roles = $this->roles;
  252. // guarantee every user at least has ROLE_USER
  253. $roles[] = 'ROLE_USER';
  254. return array_unique($roles);
  255. }
  256. public function hasRole(string $roles):bool {
  257. return in_array($roles, $this->getRoles());
  258. }
  259. public function setRoles(array $roles): self
  260. {
  261. $this->roles = $roles;
  262. return $this;
  263. }
  264. /**
  265. * @see UserInterface
  266. */
  267. public function getPassword()
  268. {
  269. return $this->password;
  270. }
  271. /**
  272. * @see UserInterface
  273. */
  274. public function getSalt()
  275. {
  276. // not needed for apps that do not check user passwords
  277. }
  278. /**
  279. * @see UserInterface
  280. */
  281. public function eraseCredentials()
  282. {
  283. // If you store any temporary, sensitive data on the user, clear it here
  284. // $this->plainPassword = null;
  285. }
  286. public function getFirstName(): ?string
  287. {
  288. return $this->firstName;
  289. }
  290. public function setFirstName(string $firstName): self
  291. {
  292. $this->firstName = $firstName;
  293. return $this;
  294. }
  295. public function getTwitterUsername(): ?string
  296. {
  297. return $this->twitterUsername;
  298. }
  299. public function setTwitterUsername(?string $twitterUsername): self
  300. {
  301. $this->twitterUsername = $twitterUsername;
  302. return $this;
  303. }
  304. public function setPassword(string $password): self
  305. {
  306. $this->password = $password;
  307. return $this;
  308. }
  309. public function isVerified(): bool
  310. {
  311. return $this->isVerified;
  312. }
  313. public function setIsVerified(bool $isVerified): self
  314. {
  315. $this->isVerified = $isVerified;
  316. return $this;
  317. }
  318. public function getStep(): ?Step
  319. {
  320. return $this->step;
  321. }
  322. public function setStep(?Step $step): self
  323. {
  324. $this->step = $step;
  325. return $this;
  326. }
  327. public function getQuestion(): ?Question
  328. {
  329. return $this->question;
  330. }
  331. public function setQuestion(?Question $question): self
  332. {
  333. $this->question = $question;
  334. return $this;
  335. }
  336. /**
  337. * @return Collection|UserAnswer[]
  338. */
  339. public function getAnswers(): Collection
  340. {
  341. return $this->answers;
  342. }
  343. public function addAnswer(UserAnswer $answer): self
  344. {
  345. if (!$this->answers->contains($answer)) {
  346. $this->answers[] = $answer;
  347. $answer->setUser($this);
  348. }
  349. return $this;
  350. }
  351. public function removeAnswer(UserAnswer $answer): self
  352. {
  353. if ($this->answers->contains($answer)) {
  354. $this->answers->removeElement($answer);
  355. // set the owning side to null (unless already changed)
  356. if ($answer->getUser() === $this) {
  357. $answer->setUser(null);
  358. }
  359. }
  360. return $this;
  361. }
  362. public function getIsVerified(): ?bool
  363. {
  364. return $this->isVerified;
  365. }
  366. public function getName(): ?string
  367. {
  368. return $this->name;
  369. }
  370. public function setName(?string $name): self
  371. {
  372. $this->name = $name;
  373. return $this;
  374. }
  375. /**
  376. * @return Collection|UserAnswerAdd[]
  377. */
  378. public function getUserAnswerAdds(): Collection
  379. {
  380. return $this->userAnswerAdds;
  381. }
  382. public function addUserAnswerAdd(UserAnswerAdd $userAnswerAdd): self
  383. {
  384. if (!$this->userAnswerAdds->contains($userAnswerAdd)) {
  385. $this->userAnswerAdds[] = $userAnswerAdd;
  386. $userAnswerAdd->setUser($this);
  387. }
  388. return $this;
  389. }
  390. public function removeUserAnswerAdd(UserAnswerAdd $userAnswerAdd): self
  391. {
  392. if ($this->userAnswerAdds->contains($userAnswerAdd)) {
  393. $this->userAnswerAdds->removeElement($userAnswerAdd);
  394. // set the owning side to null (unless already changed)
  395. if ($userAnswerAdd->getUser() === $this) {
  396. $userAnswerAdd->setUser(null);
  397. }
  398. }
  399. return $this;
  400. }
  401. public function getStatus(): ?int
  402. {
  403. return $this->status;
  404. }
  405. public function setStatus(int $status): self
  406. {
  407. $this->status = $status;
  408. return $this;
  409. }
  410. public function getToken(): ?string
  411. {
  412. return $this->token;
  413. }
  414. public function setToken(?string $token): self
  415. {
  416. $this->token = $token;
  417. return $this;
  418. }
  419. public function getEmailParent1(): ?string
  420. {
  421. return $this->emailParent1;
  422. }
  423. public function setEmailParent1(?string $emailParent1): self
  424. {
  425. $this->emailParent1 = $emailParent1;
  426. return $this;
  427. }
  428. public function getEmailParent2(): ?string
  429. {
  430. return $this->emailParent2;
  431. }
  432. public function setEmailParent2(?string $emailParent2): self
  433. {
  434. $this->emailParent2 = $emailParent2;
  435. return $this;
  436. }
  437. /**
  438. * @return Collection|self[]
  439. */
  440. public function getEnfants(): Collection
  441. {
  442. return $this->enfants;
  443. }
  444. public function addEnfant(self $enfant): self
  445. {
  446. if (!$this->enfants->contains($enfant)) {
  447. $this->enfants[] = $enfant;
  448. }
  449. return $this;
  450. }
  451. public function removeEnfant(self $enfant): self
  452. {
  453. if ($this->enfants->contains($enfant)) {
  454. $this->enfants->removeElement($enfant);
  455. }
  456. return $this;
  457. }
  458. /**
  459. * @return Collection|self[]
  460. */
  461. public function getParents(): Collection
  462. {
  463. return $this->parents;
  464. }
  465. public function addParent(self $parent): self
  466. {
  467. if (!$this->parents->contains($parent)) {
  468. $this->parents[] = $parent;
  469. $parent->addEnfant($this);
  470. }
  471. return $this;
  472. }
  473. public function removeParent(self $parent): self
  474. {
  475. if ($this->parents->contains($parent)) {
  476. $this->parents->removeElement($parent);
  477. $parent->removeEnfant($this);
  478. }
  479. return $this;
  480. }
  481. public function getProfPrincipal(): ?self
  482. {
  483. return $this->profPrincipal;
  484. }
  485. public function setProfPrincipal(?self $profPrincipal): self
  486. {
  487. $this->profPrincipal = $profPrincipal;
  488. return $this;
  489. }
  490. /**
  491. * @return Collection|self[]
  492. */
  493. public function getEleves(): Collection
  494. {
  495. return $this->eleves;
  496. }
  497. public function addEleve(self $eleve): self
  498. {
  499. if (!$this->eleves->contains($eleve)) {
  500. $this->eleves[] = $eleve;
  501. $eleve->setProfPrincipal($this);
  502. }
  503. return $this;
  504. }
  505. public function removeEleve(self $eleve): self
  506. {
  507. if ($this->eleves->contains($eleve)) {
  508. $this->eleves->removeElement($eleve);
  509. // set the owning side to null (unless already changed)
  510. if ($eleve->getProfPrincipal() === $this) {
  511. $eleve->setProfPrincipal(null);
  512. }
  513. }
  514. return $this;
  515. }
  516. /************************/
  517. public function getMentor(): ?self
  518. {
  519. return $this->mentor;
  520. }
  521. public function setMentor(?self $mentor): self
  522. {
  523. $this->mentor = $mentor;
  524. return $this;
  525. }
  526. /**
  527. * @return Collection|self[]
  528. */
  529. public function getMentored(): Collection
  530. {
  531. return $this->mentored;
  532. }
  533. public function addMentored(self $mentored): self
  534. {
  535. if (!$this->mentored->contains($mentored)) {
  536. $this->mentored[] = $mentored;
  537. $mentored->setProfPrincipal($this);
  538. }
  539. return $this;
  540. }
  541. public function removeMentored(self $mentored): self
  542. {
  543. if ($this->mentored->contains($mentored)) {
  544. $this->mentored->removeElement($mentored);
  545. // set the owning side to null (unless already changed)
  546. if ($mentored->getMentor() === $this) {
  547. $mentored->setMentor(null);
  548. }
  549. }
  550. return $this;
  551. }
  552. /************************/
  553. public function getConseille(): ?self
  554. {
  555. return $this->conseille;
  556. }
  557. public function setConseille(?self $conseille): self
  558. {
  559. $this->conseille = $conseille;
  560. return $this;
  561. }
  562. /**
  563. * @return Collection|self[]
  564. */
  565. public function getAdultes(): Collection
  566. {
  567. return $this->adultes;
  568. }
  569. public function addAdultes(self $adulte): self
  570. {
  571. if (!$this->adultes->contains($adulte)) {
  572. $this->adultes[] = $adulte;
  573. $adulte->setConseille($this);
  574. }
  575. return $this;
  576. }
  577. public function removeAdulte(self $adulte): self
  578. {
  579. if ($this->adultes->contains($adulte)) {
  580. $this->adultes->removeElement($adulte);
  581. // set the owning side to null (unless already changed)
  582. if ($adulte->getConseille() === $this) {
  583. $adulte->setConseille(null);
  584. }
  585. }
  586. return $this;
  587. }
  588. /************************/
  589. public function getFullName(){
  590. return $this->firstName .' '.$this->name;
  591. }
  592. public function getClasse(): ?string
  593. {
  594. return $this->classe;
  595. }
  596. public function setClasse(?string $classe): self
  597. {
  598. $this->classe = $classe;
  599. return $this;
  600. }
  601. public function getResetToken(): ?string
  602. {
  603. return $this->reset_token;
  604. }
  605. public function setResetToken(?string $reset_token): self
  606. {
  607. $this->reset_token = $reset_token;
  608. return $this;
  609. }
  610. public function getInstitution(): ?Institution
  611. {
  612. return $this->institution;
  613. }
  614. public function setInstitution(?Institution $institution): self
  615. {
  616. $this->institution = $institution;
  617. return $this;
  618. }
  619. /**
  620. * @return Collection|Institution[]
  621. */
  622. public function getListInstitutions(): Collection
  623. {
  624. return $this->listInstitutions;
  625. }
  626. public function addListInstitution(Institution $listInstitution): self
  627. {
  628. if (!$this->listInstitutions->contains($listInstitution)) {
  629. $this->listInstitutions[] = $listInstitution;
  630. }
  631. return $this;
  632. }
  633. public function removeListInstitution(Institution $listInstitution): self
  634. {
  635. if ($this->listInstitutions->contains($listInstitution)) {
  636. $this->listInstitutions->removeElement($listInstitution);
  637. }
  638. return $this;
  639. }
  640. public function getBilanStepProf(): ?int
  641. {
  642. return $this->bilanStepProf;
  643. }
  644. public function setBilanStepProf(?int $bilanStepProf): self
  645. {
  646. $this->bilanStepProf = $bilanStepProf;
  647. return $this;
  648. }
  649. public function getCreatedAt(): ?\DateTimeInterface
  650. {
  651. return $this->createdAt;
  652. }
  653. public function setCreatedAt(?\DateTimeInterface $createdAt): self
  654. {
  655. $this->createdAt = $createdAt;
  656. return $this;
  657. }
  658. public function getUpdatedAt(): ?\DateTimeInterface
  659. {
  660. return $this->updatedAt;
  661. }
  662. public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  663. {
  664. $this->updatedAt = $updatedAt;
  665. return $this;
  666. }
  667. public function getRole(): ?string
  668. {
  669. return $this->role;
  670. }
  671. public function setRole(?string $role): self
  672. {
  673. $this->role = $role;
  674. return $this;
  675. }
  676. public function getSurvey(): ?Survey
  677. {
  678. return $this->survey;
  679. }
  680. public function setSurvey(?Survey $survey): self
  681. {
  682. $this->survey = $survey;
  683. return $this;
  684. }
  685. public function getMetier(): ?string
  686. {
  687. return $this->metier;
  688. }
  689. public function setMetier(?string $metier): self
  690. {
  691. $this->metier = $metier;
  692. return $this;
  693. }
  694. public function getMustBeMentored(): ?bool
  695. {
  696. return $this->mustBeMentored;
  697. }
  698. public function setMustBeMentored(?bool $mustBeMentored): self
  699. {
  700. $this->mustBeMentored = $mustBeMentored;
  701. return $this;
  702. }
  703. public function getHasMentor(): ?bool
  704. {
  705. return $this->hasMentor;
  706. }
  707. public function setHasMentor(?bool $hasMentor): self
  708. {
  709. $this->hasMentor = $hasMentor;
  710. return $this;
  711. }
  712. public function getCodePostal(): ?int
  713. {
  714. return $this->codePostal;
  715. }
  716. public function setCodePostal(?int $codePostal): self
  717. {
  718. $this->codePostal = $codePostal;
  719. return $this;
  720. }
  721. /**
  722. * @return Collection|Institution[]
  723. */
  724. public function getExp(): Collection
  725. {
  726. return $this->exp;
  727. }
  728. public function addExp(Institution $exp): self
  729. {
  730. if (!$this->exp->contains($exp)) {
  731. $this->exp[] = $exp;
  732. $exp->setExp($this);
  733. }
  734. return $this;
  735. }
  736. public function removeExp(Institution $exp): self
  737. {
  738. if ($this->exp->contains($exp)) {
  739. $this->exp->removeElement($exp);
  740. // set the owning side to null (unless already changed)
  741. if ($exp->getExp() === $this) {
  742. $exp->setExp(null);
  743. }
  744. }
  745. return $this;
  746. }
  747. public function __call($name, $arguments)
  748. {
  749. // TODO: Implement @method string getUserIdentifier()
  750. }
  751. }