Person.php 4.3 KB

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