Person.php 17 KB

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