Access.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Access;
  4. use ApiPlatform\Core\Annotation\ApiFilter;
  5. use App\Filter\Person\FullNameFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  7. use ApiPlatform\Core\Annotation\ApiResource;
  8. use ApiPlatform\Core\Annotation\ApiSubresource;
  9. use App\Entity\Billing\AccessIntangible;
  10. use App\Entity\Billing\AccessPayer;
  11. use App\Entity\Core\Notification;
  12. use App\Entity\Core\NotificationUser;
  13. use App\Entity\Organization\Organization;
  14. use App\Entity\Organization\OrganizationLicence;
  15. use App\Repository\Access\AccessRepository;
  16. use App\Entity\Person\Person;
  17. use App\Entity\Person\PersonActivity;
  18. use Doctrine\Common\Collections\ArrayCollection;
  19. use Doctrine\Common\Collections\Collection;
  20. use Doctrine\ORM\Mapping as ORM;
  21. use JetBrains\PhpStorm\Pure;
  22. use Symfony\Component\Security\Core\User\UserInterface;
  23. use Symfony\Component\Serializer\Annotation\Groups;
  24. /**
  25. * Fais le lien entre une Person et une Organization
  26. * @ApiResource @see : config/api_platform/Access/access.yaml
  27. */
  28. #[ORM\Entity(repositoryClass: AccessRepository::class)]
  29. #[ApiFilter(BooleanFilter::class, properties: ['person.isPhysical'])]
  30. #[ApiFilter(FullNameFilter::class)]
  31. class Access implements UserInterface
  32. {
  33. #[ORM\Id]
  34. #[ORM\Column]
  35. #[ORM\GeneratedValue]
  36. #[Groups("access_people_ref")]
  37. private ?int $id = null;
  38. #[ORM\Column(options: ['default' => false])]
  39. private bool $adminAccess = false;
  40. #[ORM\Column(options: ['default' => false])]
  41. #[Groups(['private'])]
  42. private bool $superAdminAccess = false;
  43. #[ORM\Column(nullable: true)]
  44. #[Groups(['my_access:input'])]
  45. private ?int $activityYear = null;
  46. #[ORM\ManyToOne(cascade: ['persist'])]
  47. #[ORM\JoinColumn(nullable: false)]
  48. #[Groups(["access_people_ref", "access_address"])]
  49. private Person $person;
  50. #[ORM\ManyToOne]
  51. #[ORM\JoinColumn(nullable: false)]
  52. private Organization $organization;
  53. #[ORM\Column(type: 'json', length: 4294967295, nullable: true)]
  54. private ?array $roles = [];
  55. #[Groups(['my_access:input'])]
  56. #[ORM\Column(type: 'json', length: 4294967295, nullable: true)]
  57. private ?array $setting = [];
  58. #[Groups(['my_access:input'])]
  59. private array $historical = [];
  60. #[ORM\OneToMany(mappedBy: 'access', targetEntity: PersonActivity::class, cascade: ['persist'], orphanRemoval: true)]
  61. #[ApiSubresource]
  62. private Collection $personActivity;
  63. #[ORM\OneToMany(mappedBy: 'access', targetEntity: OrganizationFunction::class, cascade: ['persist'], orphanRemoval: true)]
  64. #[ApiSubresource]
  65. private Collection $organizationFunction;
  66. #[ORM\OneToMany(mappedBy: 'licensee', targetEntity: OrganizationLicence::class, cascade: ['persist'], orphanRemoval: true)]
  67. private Collection $organizationLicences;
  68. #[ORM\OneToMany(mappedBy: 'access', targetEntity: PersonalizedList::class, cascade: ['persist'], orphanRemoval: true)]
  69. private Collection $personalizedLists;
  70. #[ORM\OneToMany(mappedBy: 'recipientAccess', targetEntity: Notification::class, orphanRemoval: true)]
  71. private Collection $notifications;
  72. #[ORM\OneToMany(mappedBy: 'access', targetEntity: NotificationUser::class, orphanRemoval: true)]
  73. private Collection $notificationUsers;
  74. #[ORM\ManyToMany(targetEntity: Access::class, mappedBy: 'children', cascade: ['persist'])]
  75. private Collection $guardians;
  76. #[ORM\ManyToMany(targetEntity: Access::class, inversedBy: 'guardians', cascade: ['persist'])]
  77. #[ORM\JoinTable(name: 'children_guardians')]
  78. #[ORM\JoinColumn(name: 'guardians_id', referencedColumnName: 'id')]
  79. #[ORM\InverseJoinColumn(name: 'children_id', referencedColumnName: 'id')]
  80. private Collection $children;
  81. #[ORM\OneToMany(mappedBy: 'accessPayer', targetEntity: AccessPayer::class, cascade: ['persist'], orphanRemoval: true)]
  82. private Collection $billingPayers;
  83. #[ORM\OneToMany(mappedBy: 'accessReceiver', targetEntity: AccessPayer::class, cascade: ['persist'], orphanRemoval: true)]
  84. private Collection $billingReceivers;
  85. #[ORM\OneToMany(mappedBy: 'access', targetEntity: AccessIntangible::class, cascade: ['persist'], orphanRemoval: true)]
  86. private Collection $accessIntangibles;
  87. #[Pure] public function __construct()
  88. {
  89. $this->personActivity = new ArrayCollection();
  90. $this->organizationFunction = new ArrayCollection();
  91. $this->organizationLicences = new ArrayCollection();
  92. $this->personalizedLists = new ArrayCollection();
  93. $this->guardians = new ArrayCollection();
  94. $this->children = new ArrayCollection();
  95. $this->billingPayers = new ArrayCollection();
  96. $this->billingReceivers = new ArrayCollection();
  97. $this->accessIntangibles = new ArrayCollection();
  98. $this->notifications = new ArrayCollection();
  99. $this->notificationUsers = new ArrayCollection();
  100. }
  101. public function getId(): ?int
  102. {
  103. return $this->id;
  104. }
  105. public function getAdminAccess(): ?bool
  106. {
  107. return $this->adminAccess;
  108. }
  109. public function setAdminAccess(bool $adminAccess): self
  110. {
  111. $this->adminAccess = $adminAccess;
  112. return $this;
  113. }
  114. public function getSuperAdminAccess(): ?bool
  115. {
  116. return $this->superAdminAccess;
  117. }
  118. public function setSuperAdminAccess(bool $superAdminAccess): self
  119. {
  120. $this->superAdminAccess = $superAdminAccess;
  121. return $this;
  122. }
  123. public function getPerson(): ?Person
  124. {
  125. return $this->person;
  126. }
  127. public function setPerson(?Person $person): self
  128. {
  129. $this->person = $person;
  130. return $this;
  131. }
  132. public function getOrganization(): ?Organization
  133. {
  134. return $this->organization;
  135. }
  136. public function setOrganization(?Organization $organization): self
  137. {
  138. $this->organization = $organization;
  139. return $this;
  140. }
  141. public function getActivityYear(): ?int
  142. {
  143. return $this->activityYear;
  144. }
  145. public function setActivityYear(?int $activityYear): self
  146. {
  147. $this->activityYear = $activityYear;
  148. return $this;
  149. }
  150. public function getHistorical(): array
  151. {
  152. return array_key_exists('historical', $this->setting) && $this->setting['historical'] ? $this->setting['historical'] : ['present' => true];
  153. }
  154. public function setHistorical(array $historical): self
  155. {
  156. if(!$historical['past'] && !$historical['present'] && !$historical['future'])
  157. $historical['present'] = true;
  158. $this->setting['historical'] = $historical;
  159. return $this;
  160. }
  161. public function setRoles(?array $roles): self
  162. {
  163. $this->roles = $roles;
  164. return $this;
  165. }
  166. public function getRoles(): ?array
  167. {
  168. $roles = $this->roles;
  169. return array_unique($roles);
  170. }
  171. public function getPersonActivity(): Collection
  172. {
  173. return $this->personActivity;
  174. }
  175. public function addPersonActivity(PersonActivity $personActivity): self
  176. {
  177. if (!$this->personActivity->contains($personActivity)) {
  178. $this->personActivity[] = $personActivity;
  179. $personActivity->setAccess($this);
  180. }
  181. return $this;
  182. }
  183. public function removePersonActivity(PersonActivity $personActivity): self
  184. {
  185. if ($this->personActivity->removeElement($personActivity)) {
  186. // set the owning side to null (unless already changed)
  187. if ($personActivity->getAccess() === $this) {
  188. $personActivity->setAccess(null);
  189. }
  190. }
  191. return $this;
  192. }
  193. public function getOrganizationFunction(): Collection
  194. {
  195. return $this->organizationFunction;
  196. }
  197. public function addOrganizationFunction (OrganizationFunction $organizationFunction): self
  198. {
  199. if (!$this->organizationFunction->contains($organizationFunction)) {
  200. $this->organizationFunction[] = $organizationFunction;
  201. $organizationFunction->setAccess($this);
  202. }
  203. return $this;
  204. }
  205. public function removeOrganizationFunction(OrganizationFunction $organizationFunction): self
  206. {
  207. if ($this->organizationFunction->removeElement($organizationFunction)) {
  208. // set the owning side to null (unless already changed)
  209. if ($organizationFunction->getAccess() === $this) {
  210. $organizationFunction->setAccess(null);
  211. }
  212. }
  213. return $this;
  214. }
  215. public function getOrganizationLicences(): Collection
  216. {
  217. return $this->organizationLicences;
  218. }
  219. public function addOrganizationLicence(OrganizationLicence $organizationLicence): self
  220. {
  221. if (!$this->organizationLicences->contains($organizationLicence)) {
  222. $this->organizationLicences[] = $organizationLicence;
  223. $organizationLicence->setLicensee($this);
  224. }
  225. return $this;
  226. }
  227. public function removeOrganizationLicence(OrganizationLicence $organizationLicence): self
  228. {
  229. if ($this->organizationLicences->removeElement($organizationLicence)) {
  230. // set the owning side to null (unless already changed)
  231. if ($organizationLicence->getLicensee() === $this) {
  232. $organizationLicence->setLicensee(null);
  233. }
  234. }
  235. return $this;
  236. }
  237. public function getPersonalizedLists(): Collection
  238. {
  239. return $this->personalizedLists;
  240. }
  241. public function addPersonalizedList(PersonalizedList $personalizedList): self
  242. {
  243. if (!$this->personalizedLists->contains($personalizedList)) {
  244. $this->personalizedLists[] = $personalizedList;
  245. $personalizedList->setAccess($this);
  246. }
  247. return $this;
  248. }
  249. public function removePersonalizedList(PersonalizedList $personalizedList): self
  250. {
  251. if ($this->personalizedLists->removeElement($personalizedList)) {
  252. // set the owning side to null (unless already changed)
  253. if ($personalizedList->getAccess() === $this) {
  254. $personalizedList->setAccess(null);
  255. }
  256. }
  257. return $this;
  258. }
  259. public function getChildren(): Collection
  260. {
  261. return $this->children;
  262. }
  263. public function addChild (Access $access): self
  264. {
  265. if (!$this->children->contains($access)) {
  266. $this->children[] = $access;
  267. $access->addGuardian($this);
  268. }
  269. return $this;
  270. }
  271. public function removeChild(Access $access): self
  272. {
  273. if ($this->children->removeElement($access)) {
  274. $access->removeGuardian($this);
  275. }
  276. return $this;
  277. }
  278. public function getGuardians(): Collection
  279. {
  280. return $this->guardians;
  281. }
  282. public function addGuardian(Access $access): self
  283. {
  284. if (!$this->guardians->contains($access)) {
  285. $this->guardians[] = $access;
  286. $access->addChild($this);
  287. }
  288. return $this;
  289. }
  290. public function removeGuardian(Access $access): self
  291. {
  292. if ($this->guardians->removeElement($access)) {
  293. $access->removeChild($this);
  294. }
  295. return $this;
  296. }
  297. public function getBillingPayers(): Collection
  298. {
  299. return $this->billingPayers;
  300. }
  301. public function addBillingPayer(AccessPayer $billingPayer): self
  302. {
  303. if (!$this->billingPayers->contains($billingPayer)) {
  304. $this->billingPayers[] = $billingPayer;
  305. $billingPayer->setAccessPayer($this);
  306. }
  307. return $this;
  308. }
  309. public function removeBillingPayer(AccessPayer $billingPayer): self
  310. {
  311. if ($this->billingPayers->removeElement($billingPayer)) {
  312. // set the owning side to null (unless already changed)
  313. if ($billingPayer->getAccessPayer() === $this) {
  314. $billingPayer->setAccessPayer(null);
  315. }
  316. }
  317. return $this;
  318. }
  319. public function getBillingReceivers(): Collection
  320. {
  321. return $this->billingReceivers;
  322. }
  323. public function addBillingReceiver(AccessPayer $billingReceiver): self
  324. {
  325. if (!$this->billingReceivers->contains($billingReceiver)) {
  326. $this->billingReceivers[] = $billingReceiver;
  327. $billingReceiver->setAccessReceiver($this);
  328. }
  329. return $this;
  330. }
  331. public function removeBillingReceiver(AccessPayer $billingPayer): self
  332. {
  333. if ($this->billingReceivers->removeElement($billingPayer)) {
  334. // set the owning side to null (unless already changed)
  335. if ($billingPayer->getAccessReceiver() === $this) {
  336. $billingPayer->setAccessReceiver(null);
  337. }
  338. }
  339. return $this;
  340. }
  341. public function getAccessIntangibles(): Collection
  342. {
  343. return $this->accessIntangibles;
  344. }
  345. public function addAccessIntangible(AccessIntangible $accessIntangibles): self
  346. {
  347. if (!$this->accessIntangibles->contains($accessIntangibles)) {
  348. $this->accessIntangibles[] = $accessIntangibles;
  349. $accessIntangibles->setAccess($this);
  350. }
  351. return $this;
  352. }
  353. public function removeAccessIntangible(AccessIntangible $accessIntangibles): self
  354. {
  355. if ($this->accessIntangibles->removeElement($accessIntangibles)) {
  356. // set the owning side to null (unless already changed)
  357. if ($accessIntangibles->getAccess() === $this) {
  358. $accessIntangibles->setAccess(null);
  359. }
  360. }
  361. return $this;
  362. }
  363. public function getNotifications(): Collection
  364. {
  365. return $this->notifications;
  366. }
  367. public function addNotification(Notification $notification): self
  368. {
  369. if (!$this->notifications->contains($notification)) {
  370. $this->notifications[] = $notification;
  371. $notification->setRecipientAccess($this);
  372. }
  373. return $this;
  374. }
  375. public function removeNotification(Notification $notification): self
  376. {
  377. if ($this->notifications->removeElement($notification)) {
  378. // set the owning side to null (unless already changed)
  379. if ($notification->getRecipientAccess() === $this) {
  380. $notification->setRecipientAccess(null);
  381. }
  382. }
  383. return $this;
  384. }
  385. public function getNotificationUsers(): Collection
  386. {
  387. return $this->notificationUsers;
  388. }
  389. public function addNotificationUser(NotificationUser $notificationUser): self
  390. {
  391. if (!$this->notificationUsers->contains($notificationUser)) {
  392. $this->notificationUsers[] = $notificationUser;
  393. $notificationUser->setAccess($this);
  394. }
  395. return $this;
  396. }
  397. public function removeNotificationUser(NotificationUser $notificationUser): self
  398. {
  399. if ($this->notificationUsers->removeElement($notificationUser)) {
  400. // set the owning side to null (unless already changed)
  401. if ($notificationUser->getAccess() === $this) {
  402. $notificationUser->setAccess(null);
  403. }
  404. }
  405. return $this;
  406. }
  407. #[Pure] public function getUserIdentifier(): string
  408. {
  409. return $this->person->getUsername();
  410. }
  411. public function getPassword(): ?string
  412. {
  413. return null;
  414. }
  415. public function getSalt(): ?string
  416. {
  417. return null;
  418. }
  419. public function getUsername(): ?string
  420. {
  421. return null;
  422. }
  423. public function eraseCredentials()
  424. {
  425. // TODO: Implement eraseCredentials() method.
  426. }
  427. }