Person.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Person;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use App\Entity\Access\Access;
  6. use App\Entity\AccessWish\DocumentWish;
  7. use App\Entity\Core\BankAccount;
  8. use App\Entity\Core\ContactPoint;
  9. use App\Entity\Core\Country;
  10. use App\Entity\Core\File;
  11. use App\Enum\Person\GenderEnum;
  12. use App\Repository\Person\PersonRepository;
  13. // use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use Doctrine\Common\Collections\Collection;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use JetBrains\PhpStorm\Pure;
  18. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  19. use Symfony\Component\Security\Core\User\UserInterface;
  20. use Symfony\Component\Serializer\Annotation\Groups;
  21. /**
  22. * Personne physique ou morale.
  23. */
  24. #[ApiResource(operations: [])]
  25. // #[Auditable]
  26. #[ORM\Entity(repositoryClass: PersonRepository::class)]
  27. class Person implements UserInterface, PasswordAuthenticatedUserInterface
  28. {
  29. #[ORM\Id]
  30. #[ORM\Column]
  31. #[ORM\GeneratedValue]
  32. #[Groups(['access_people_ref'])]
  33. private ?int $id = null;
  34. #[ORM\Column(length: 180, unique: true, nullable: true)]
  35. private ?string $username = null;
  36. /** @var string[]|null */
  37. private ?array $roles = [];
  38. #[ORM\Column(nullable: true)]
  39. private ?string $password = null;
  40. #[ORM\Column(length: 255, nullable: true)]
  41. #[Groups(['access_people_ref', 'access_address'])]
  42. private ?string $name = null;
  43. #[ORM\Column(length: 255, nullable: true)]
  44. #[Groups(['access_people_ref', 'access_address'])]
  45. private ?string $givenName = null;
  46. #[ORM\ManyToMany(targetEntity: ContactPoint::class, mappedBy: 'person')]
  47. private Collection $contactPoints;
  48. #[ORM\ManyToMany(targetEntity: BankAccount::class, inversedBy: 'person', cascade: ['persist'], orphanRemoval: true)]
  49. #[ORM\JoinColumn(name: 'person_id', referencedColumnName: 'id')]
  50. #[ORM\InverseJoinColumn(name: 'bankAccount_id', referencedColumnName: 'id')]
  51. private Collection $bankAccount;
  52. #[ORM\OneToMany(mappedBy: 'person', targetEntity: PersonAddressPostal::class, orphanRemoval: true)]
  53. #[Groups('access_address')]
  54. private Collection $personAddressPostal;
  55. #[ORM\Column(length: 50, nullable: true, enumType: GenderEnum::class)]
  56. private ?GenderEnum $gender = null;
  57. #[ORM\ManyToOne(inversedBy: 'personImages')]
  58. #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  59. private ?File $image = null;
  60. #[ORM\Column(options: ['default' => true])]
  61. private bool $isPhysical = true;
  62. #[ORM\ManyToOne]
  63. private Country $nationality;
  64. #[ORM\OneToMany(mappedBy: 'person', targetEntity: Access::class, orphanRemoval: true)]
  65. private Collection $access;
  66. #[ORM\OneToMany(mappedBy: 'person', targetEntity: File::class, orphanRemoval: true)]
  67. private Collection $files;
  68. #[ORM\OneToMany(mappedBy: 'person', targetEntity: DisciplineOtherEstablishment::class, cascade: ['persist'], orphanRemoval: true)]
  69. private Collection $disciplineotherestablishments;
  70. #[ORM\OneToMany(mappedBy: 'person', targetEntity: Qualification::class, cascade: ['persist'], orphanRemoval: true)]
  71. private Collection $qualifications;
  72. #[ORM\OneToMany(mappedBy: 'person', targetEntity: SchoolingInEstablishment::class, cascade: ['persist'], orphanRemoval: true)]
  73. private Collection $schoolingEstablisments;
  74. #[ORM\OneToMany(mappedBy: 'person', targetEntity: TeacherSchoolingHistory::class, cascade: ['persist'], orphanRemoval: true)]
  75. private Collection $teacherSchoolingHistories;
  76. #[ORM\ManyToMany(targetEntity: File::class, mappedBy: 'accessPersons', cascade: ['persist'])]
  77. #[ORM\OrderBy(['id' => 'DESC'])]
  78. private Collection $personFiles;
  79. #[ORM\OneToMany(mappedBy: 'personOwner', targetEntity: DocumentWish::class, cascade: ['persist'], orphanRemoval: true)]
  80. private Collection $documentWishes;
  81. #[ORM\OneToOne(targetEntity: Medical::class, inversedBy: 'person', cascade: ['persist'])]
  82. private Medical $medical;
  83. #[ORM\OneToMany(targetEntity: AllowedIp::class, mappedBy: 'person', cascade: ['persist'], orphanRemoval: true)]
  84. private Collection $allowedIps;
  85. #[Pure]
  86. public function __construct()
  87. {
  88. $this->contactPoints = new ArrayCollection();
  89. $this->personAddressPostal = new ArrayCollection();
  90. $this->bankAccount = new ArrayCollection();
  91. $this->access = new ArrayCollection();
  92. $this->files = new ArrayCollection();
  93. $this->disciplineotherestablishments = new ArrayCollection();
  94. $this->qualifications = new ArrayCollection();
  95. $this->schoolingEstablisments = new ArrayCollection();
  96. $this->teacherSchoolingHistories = new ArrayCollection();
  97. $this->personFiles = new ArrayCollection();
  98. $this->documentWishes = new ArrayCollection();
  99. }
  100. public function getId(): ?int
  101. {
  102. return $this->id;
  103. }
  104. public function getUsername(): ?string
  105. {
  106. return (string) $this->username;
  107. }
  108. public function getUserIdentifier(): string
  109. {
  110. return (string) $this->username;
  111. }
  112. public function setUsername(?string $username): self
  113. {
  114. $this->username = $username;
  115. return $this;
  116. }
  117. /**
  118. * @return string[]
  119. */
  120. public function getRoles(): array
  121. {
  122. $roles = $this->roles;
  123. // guarantee every user at least has ROLE_USER
  124. $roles[] = 'ROLE_USER';
  125. return array_unique($roles);
  126. }
  127. /**
  128. * @param string[] $roles
  129. *
  130. * @return $this
  131. */
  132. public function setRoles(array $roles): self
  133. {
  134. $this->roles = $roles;
  135. return $this;
  136. }
  137. public function getPassword(): ?string
  138. {
  139. return (string) $this->password;
  140. }
  141. public function setPassword(?string $password): self
  142. {
  143. $this->password = $password;
  144. return $this;
  145. }
  146. public function getSalt(): ?string
  147. {
  148. return null;
  149. // not needed when using the "bcrypt" algorithm in security.yaml
  150. }
  151. public function eraseCredentials(): void
  152. {
  153. // If you store any temporary, sensitive data on the user, clear it here
  154. // $this->plainPassword = null;
  155. }
  156. public function getName(): ?string
  157. {
  158. return $this->name;
  159. }
  160. public function setName(?string $name): self
  161. {
  162. $this->name = $name;
  163. return $this;
  164. }
  165. public function getGivenName(): ?string
  166. {
  167. return $this->givenName;
  168. }
  169. public function setGivenName(?string $givenName): self
  170. {
  171. $this->givenName = $givenName;
  172. return $this;
  173. }
  174. public function getFullName(): ?string
  175. {
  176. if (!$this->getName() || !$this->getGivenName()) {
  177. return null;
  178. }
  179. return "{$this->getName()} {$this->getGivenName()}";
  180. }
  181. public function setGender(?GenderEnum $gender): self
  182. {
  183. $this->gender = $gender;
  184. return $this;
  185. }
  186. public function getGender(): ?GenderEnum
  187. {
  188. return $this->gender;
  189. }
  190. public function getContactPoints(): Collection
  191. {
  192. return $this->contactPoints;
  193. }
  194. public function addContactPoint(ContactPoint $contactPoint): self
  195. {
  196. if (!$this->contactPoints->contains($contactPoint)) {
  197. $this->contactPoints[] = $contactPoint;
  198. $contactPoint->addPerson($this);
  199. }
  200. return $this;
  201. }
  202. public function removeContactPoint(ContactPoint $contactPoint): self
  203. {
  204. if ($this->contactPoints->removeElement($contactPoint)) {
  205. $contactPoint->removePerson($this);
  206. }
  207. return $this;
  208. }
  209. public function setImage(?File $image): self
  210. {
  211. $this->image = $image;
  212. return $this;
  213. }
  214. public function getImage(): ?File
  215. {
  216. return $this->image;
  217. }
  218. public function getPersonAddressPostal(): Collection
  219. {
  220. return $this->personAddressPostal;
  221. }
  222. public function addPersonAddressPostal(PersonAddressPostal $personAddressPostal): self
  223. {
  224. if (!$this->personAddressPostal->contains($personAddressPostal)) {
  225. $this->personAddressPostal[] = $personAddressPostal;
  226. $personAddressPostal->setPerson($this);
  227. }
  228. return $this;
  229. }
  230. public function removePersonAddressPostal(PersonAddressPostal $personAddressPostal): self
  231. {
  232. if ($this->personAddressPostal->removeElement($personAddressPostal)) {
  233. // set the owning side to null (unless already changed)
  234. if ($personAddressPostal->getPerson() === $this) {
  235. $personAddressPostal->setPerson(null);
  236. }
  237. }
  238. return $this;
  239. }
  240. public function getIsPhysical(): ?bool
  241. {
  242. return $this->isPhysical;
  243. }
  244. public function setAdminAccess(bool $isPhysical): self
  245. {
  246. $this->isPhysical = $isPhysical;
  247. return $this;
  248. }
  249. public function setIsPhysical(bool $isPhysical): self
  250. {
  251. $this->isPhysical = $isPhysical;
  252. return $this;
  253. }
  254. /**
  255. * @return Collection<int, BankAccount>
  256. */
  257. public function getBankAccount(): Collection
  258. {
  259. return $this->bankAccount;
  260. }
  261. public function addBankAccount(BankAccount $bankAccount): self
  262. {
  263. if (!$this->bankAccount->contains($bankAccount)) {
  264. $this->bankAccount[] = $bankAccount;
  265. }
  266. return $this;
  267. }
  268. public function removeBankAccount(BankAccount $bankAccount): self
  269. {
  270. $this->bankAccount->removeElement($bankAccount);
  271. return $this;
  272. }
  273. public function getNationality(): ?Country
  274. {
  275. return $this->nationality;
  276. }
  277. public function setNationality(?Country $nationality): self
  278. {
  279. $this->nationality = $nationality;
  280. return $this;
  281. }
  282. /**
  283. * @return Collection<int, Access>
  284. */
  285. public function getAccess(): Collection
  286. {
  287. return $this->access;
  288. }
  289. public function addAccess(Access $access): self
  290. {
  291. if (!$this->access->contains($access)) {
  292. $this->access[] = $access;
  293. $access->setPerson($this);
  294. }
  295. return $this;
  296. }
  297. public function removeAccess(Access $access): self
  298. {
  299. if ($this->access->removeElement($access)) {
  300. // set the owning side to null (unless already changed)
  301. if ($access->getPerson() === $this) {
  302. $access->setPerson(null);
  303. }
  304. }
  305. return $this;
  306. }
  307. /**
  308. * @return Collection<int, File>
  309. */
  310. public function getFiles(): Collection
  311. {
  312. return $this->files;
  313. }
  314. public function addFile(File $file): self
  315. {
  316. if (!$this->files->contains($file)) {
  317. $this->files[] = $file;
  318. $file->setPerson($this);
  319. }
  320. return $this;
  321. }
  322. public function removeFile(File $file): self
  323. {
  324. if ($this->files->removeElement($file)) {
  325. // set the owning side to null (unless already changed)
  326. if ($file->getPerson() === $this) {
  327. $file->setPerson(null);
  328. }
  329. }
  330. return $this;
  331. }
  332. /**
  333. * @return Collection<int, DisciplineOtherEstablishment>
  334. */
  335. public function getDisciplineotherestablishments(): Collection
  336. {
  337. return $this->disciplineotherestablishments;
  338. }
  339. public function addDisciplineotherestablishment(DisciplineOtherEstablishment $disciplineotherestablishment): self
  340. {
  341. if (!$this->disciplineotherestablishments->contains($disciplineotherestablishment)) {
  342. $this->disciplineotherestablishments[] = $disciplineotherestablishment;
  343. $disciplineotherestablishment->setPerson($this);
  344. }
  345. return $this;
  346. }
  347. public function removeDisciplineotherestablishment(DisciplineOtherEstablishment $disciplineotherestablishment): self
  348. {
  349. if ($this->disciplineotherestablishments->removeElement($disciplineotherestablishment)) {
  350. // set the owning side to null (unless already changed)
  351. if ($disciplineotherestablishment->getPerson() === $this) {
  352. $disciplineotherestablishment->setPerson(null);
  353. }
  354. }
  355. return $this;
  356. }
  357. /**
  358. * @return Collection<int, Qualification>
  359. */
  360. public function getQualifications(): Collection
  361. {
  362. return $this->qualifications;
  363. }
  364. public function addQualification(Qualification $qualification): self
  365. {
  366. if (!$this->qualifications->contains($qualification)) {
  367. $this->qualifications[] = $qualification;
  368. $qualification->setPerson($this);
  369. }
  370. return $this;
  371. }
  372. public function removeQualification(Qualification $qualification): self
  373. {
  374. if ($this->qualifications->removeElement($qualification)) {
  375. // set the owning side to null (unless already changed)
  376. if ($qualification->getPerson() === $this) {
  377. $qualification->setPerson(null);
  378. }
  379. }
  380. return $this;
  381. }
  382. /**
  383. * @return Collection<int, SchoolingInEstablishment>
  384. */
  385. public function getSchoolingEstablisments(): Collection
  386. {
  387. return $this->schoolingEstablisments;
  388. }
  389. public function addSchoolingEstablisment(SchoolingInEstablishment $schoolingEstablisment): self
  390. {
  391. if (!$this->schoolingEstablisments->contains($schoolingEstablisment)) {
  392. $this->schoolingEstablisments[] = $schoolingEstablisment;
  393. $schoolingEstablisment->setPerson($this);
  394. }
  395. return $this;
  396. }
  397. public function removeSchoolingEstablisment(SchoolingInEstablishment $schoolingEstablisment): self
  398. {
  399. if ($this->schoolingEstablisments->removeElement($schoolingEstablisment)) {
  400. // set the owning side to null (unless already changed)
  401. if ($schoolingEstablisment->getPerson() === $this) {
  402. $schoolingEstablisment->setPerson(null);
  403. }
  404. }
  405. return $this;
  406. }
  407. /**
  408. * @return Collection<int, TeacherSchoolingHistory>
  409. */
  410. public function getTeacherSchoolingHistories(): Collection
  411. {
  412. return $this->teacherSchoolingHistories;
  413. }
  414. public function addTeacherSchoolingHistory(TeacherSchoolingHistory $teacherSchoolingHistory): self
  415. {
  416. if (!$this->teacherSchoolingHistories->contains($teacherSchoolingHistory)) {
  417. $this->teacherSchoolingHistories[] = $teacherSchoolingHistory;
  418. $teacherSchoolingHistory->setPerson($this);
  419. }
  420. return $this;
  421. }
  422. public function removeTeacherSchoolingHistory(TeacherSchoolingHistory $teacherSchoolingHistory): self
  423. {
  424. if ($this->teacherSchoolingHistories->removeElement($teacherSchoolingHistory)) {
  425. // set the owning side to null (unless already changed)
  426. if ($teacherSchoolingHistory->getPerson() === $this) {
  427. $teacherSchoolingHistory->setPerson(null);
  428. }
  429. }
  430. return $this;
  431. }
  432. /**
  433. * @return Collection<int, File>
  434. */
  435. public function getPersonFiles(): Collection
  436. {
  437. return $this->personFiles;
  438. }
  439. public function addPersonFile(File $personFile): self
  440. {
  441. if (!$this->personFiles->contains($personFile)) {
  442. $this->personFiles[] = $personFile;
  443. $personFile->addAccessPerson($this);
  444. }
  445. return $this;
  446. }
  447. public function removePersonFile(File $personFile): self
  448. {
  449. if ($this->personFiles->removeElement($personFile)) {
  450. $personFile->removeAccessPerson($this);
  451. }
  452. return $this;
  453. }
  454. /**
  455. * @return Collection<int, DocumentWish>
  456. */
  457. public function getDocumentWishes(): Collection
  458. {
  459. return $this->documentWishes;
  460. }
  461. public function addDocumentWish(DocumentWish $documentWish): self
  462. {
  463. if (!$this->documentWishes->contains($documentWish)) {
  464. $this->documentWishes[] = $documentWish;
  465. $documentWish->setPersonOwner($this);
  466. }
  467. return $this;
  468. }
  469. public function removeDocumentWish(DocumentWish $documentWish): self
  470. {
  471. if ($this->documentWishes->removeElement($documentWish)) {
  472. // set the owning side to null (unless already changed)
  473. if ($documentWish->getPersonOwner() === $this) {
  474. $documentWish->setPersonOwner(null);
  475. }
  476. }
  477. return $this;
  478. }
  479. public function getMedical(): Medical
  480. {
  481. return $this->medical;
  482. }
  483. public function setMedical(Medical $medical): self
  484. {
  485. $this->medical = $medical;
  486. return $this;
  487. }
  488. public function getAllowedIps(): Collection
  489. {
  490. return $this->allowedIps;
  491. }
  492. public function addAllowedIp(AllowedIp $allowedIp): self
  493. {
  494. if (!$this->allowedIps->contains($allowedIp)) {
  495. $this->allowedIps[] = $allowedIp;
  496. $allowedIp->setPerson($this);
  497. }
  498. return $this;
  499. }
  500. public function removeAllowedIp(AllowedIp $allowedIp): self
  501. {
  502. $this->allowedIps->removeElement($allowedIp);
  503. return $this;
  504. }
  505. }