Person.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Person;
  4. use App\Entity\Core\ContactPoint;
  5. use App\Repository\Person\PersonRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. /**
  11. * Personne physique ou morale
  12. *
  13. * @ORM\Entity(repositoryClass=PersonRepository::class)
  14. */
  15. class Person implements UserInterface
  16. {
  17. /**
  18. * @ORM\Id
  19. * @ORM\GeneratedValue
  20. * @ORM\Column(type="integer")
  21. */
  22. private $id;
  23. /**
  24. * @ORM\Column(type="string", length=180, unique=true)
  25. */
  26. private $username;
  27. /**
  28. *
  29. */
  30. private $roles = [];
  31. /**
  32. * @var string The hashed password
  33. * @ORM\Column(type="string")
  34. */
  35. private $password;
  36. /**
  37. * @ORM\Column(type="string", length=255, nullable=true)
  38. */
  39. private $name;
  40. /**
  41. * @ORM\Column(type="string", length=255, nullable=true)
  42. */
  43. private $givenName;
  44. /**
  45. * @ORM\ManyToMany(targetEntity=ContactPoint::class, mappedBy="person")
  46. */
  47. private $contactPoints;
  48. public function __construct()
  49. {
  50. $this->contactPoints = new ArrayCollection();
  51. }
  52. public function getId(): ?int
  53. {
  54. return $this->id;
  55. }
  56. /**
  57. * A visual identifier that represents this user.
  58. *
  59. * @see UserInterface
  60. */
  61. public function getUsername(): string
  62. {
  63. return (string) $this->username;
  64. }
  65. public function setUsername(string $username): self
  66. {
  67. $this->username = $username;
  68. return $this;
  69. }
  70. /**
  71. * @see UserInterface
  72. */
  73. public function getRoles(): array
  74. {
  75. $roles = $this->roles;
  76. // guarantee every user at least has ROLE_USER
  77. $roles[] = 'ROLE_USER';
  78. return array_unique($roles);
  79. }
  80. public function setRoles(array $roles): self
  81. {
  82. $this->roles = $roles;
  83. return $this;
  84. }
  85. /**
  86. * @see UserInterface
  87. */
  88. public function getPassword(): string
  89. {
  90. return (string) $this->password;
  91. }
  92. public function setPassword(string $password): self
  93. {
  94. $this->password = $password;
  95. return $this;
  96. }
  97. /**
  98. * @see UserInterface
  99. */
  100. public function getSalt()
  101. {
  102. // not needed when using the "bcrypt" algorithm in security.yaml
  103. }
  104. /**
  105. * @see UserInterface
  106. */
  107. public function eraseCredentials()
  108. {
  109. // If you store any temporary, sensitive data on the user, clear it here
  110. // $this->plainPassword = null;
  111. }
  112. public function getName(): ?string
  113. {
  114. return $this->name;
  115. }
  116. public function setName(?string $name): self
  117. {
  118. $this->name = $name;
  119. return $this;
  120. }
  121. public function getGivenName(): ?string
  122. {
  123. return $this->givenName;
  124. }
  125. public function setGivenName(?string $givenName): self
  126. {
  127. $this->givenName = $givenName;
  128. return $this;
  129. }
  130. /**
  131. * @return Collection|ContactPoint[]
  132. */
  133. public function getContactPoints(): Collection
  134. {
  135. return $this->contactPoints;
  136. }
  137. public function addContactPoint(ContactPoint $contactPoint): self
  138. {
  139. if (!$this->contactPoints->contains($contactPoint)) {
  140. $this->contactPoints[] = $contactPoint;
  141. $contactPoint->addPerson($this);
  142. }
  143. return $this;
  144. }
  145. public function removeContactPoint(ContactPoint $contactPoint): self
  146. {
  147. if ($this->contactPoints->removeElement($contactPoint)) {
  148. $contactPoint->removePerson($this);
  149. }
  150. return $this;
  151. }
  152. }