Person.php 16 KB

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