| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- <?php
- declare(strict_types=1);
- namespace App\Entity\Access;
- use ApiPlatform\Core\Annotation\ApiResource;
- use ApiPlatform\Core\Annotation\ApiSubresource;
- use App\Entity\Organization\Organization;
- use App\Entity\Organization\OrganizationLicence;
- use App\Repository\Access\AccessRepository;
- use App\Entity\Person\Person;
- use App\Entity\Person\PersonActivity;
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\Common\Collections\Collection;
- use Doctrine\ORM\Mapping as ORM;
- use JetBrains\PhpStorm\Pure;
- use Symfony\Component\Security\Core\User\UserInterface;
- use Symfony\Component\Serializer\Annotation\Groups;
- /**
- * Fais le lien entre une Person et une Organization
- */
- #[ApiResource(
- collectionOperations:[
- 'cget_students'=> [
- 'method' => 'GET',
- 'path' => '/students',
- 'security' => 'is_granted("ROLE_USERS_VIEW")'
- ],
- 'cget_admin'=> [
- 'method' => 'GET',
- 'path' => '/admin'
- ],
- 'get'
- ],
- itemOperations: [
- 'get' => [
- 'security' => '(is_granted("ROLE_USERS_VIEW") and object.getOrganization().getId() == user.getOrganization().getId()) or (object.getId() == user.getId())'
- ],
- 'put' => [
- 'security' => 'is_granted("ROLE_USERS") or (object.getId() == user.getId())'
- ],
- 'delete'
- ]
- )]
- #[ORM\Entity(repositoryClass: AccessRepository::class)]
- class Access implements UserInterface
- {
- #[ORM\Id]
- #[ORM\Column]
- #[ORM\GeneratedValue]
- private ?int $id = null;
- #[ORM\Column(options: ['default' => false])]
- private bool $adminAccess = false;
- #[ORM\Column(nullable: true)]
- private ?int $activityYear = null;
- #[ORM\ManyToOne(cascade: ['persist'])]
- #[ORM\JoinColumn(nullable: false)]
- private Person $person;
- #[ORM\ManyToOne]
- #[ORM\JoinColumn(nullable: false)]
- private Organization $organization;
- #[ORM\Column(type: 'json', length: 4294967295, nullable: true)]
- private ?array $roles = [];
- #[Groups(['my_access:input'])]
- #[ORM\Column(type: 'json', length: 4294967295, nullable: true)]
- private ?array $setting = [];
- #[Groups(['my_access:input'])]
- private array $historical = [];
- #[ORM\OneToMany(mappedBy: 'access', targetEntity: PersonActivity::class, cascade: ['persist'], orphanRemoval: true)]
- #[ApiSubresource]
- private Collection $personActivity;
- #[ORM\OneToMany(mappedBy: 'access', targetEntity: OrganizationFunction::class, cascade: ['persist'], orphanRemoval: true)]
- #[ApiSubresource]
- private Collection $organizationFunction;
- #[ORM\OneToMany(mappedBy: 'licensee', targetEntity: OrganizationLicence::class, cascade: ['persist'], orphanRemoval: true)]
- private Collection $organizationLicences;
- #[ORM\OneToMany(mappedBy: 'access', targetEntity: PersonalizedList::class, cascade: ['persist'], orphanRemoval: true)]
- private Collection $personalizedLists;
- #[ORM\ManyToMany(targetEntity: Access::class, mappedBy: 'children', cascade: ['persist'])]
- private Collection $guardians;
- #[ORM\ManyToMany(targetEntity: Access::class, inversedBy: 'guardians', cascade: ['persist'])]
- #[ORM\JoinTable(name: 'children_guardians')]
- #[ORM\JoinColumn(name: 'guardians_id', referencedColumnName: 'id')]
- #[ORM\InverseJoinColumn(name: 'children_id', referencedColumnName: 'id')]
- private Collection $children;
- #[Pure] public function __construct()
- {
- $this->personActivity = new ArrayCollection();
- $this->organizationFunction = new ArrayCollection();
- $this->organizationLicences = new ArrayCollection();
- $this->personalizedLists = new ArrayCollection();
- $this->guardians = new ArrayCollection();
- $this->children = new ArrayCollection();
- }
- public function getId(): ?int
- {
- return $this->id;
- }
- public function getAdminAccess(): ?bool
- {
- return $this->adminAccess;
- }
- public function setAdminAccess(bool $adminAccess): self
- {
- $this->adminAccess = $adminAccess;
- return $this;
- }
- public function getPerson(): ?Person
- {
- return $this->person;
- }
- public function setPerson(?Person $person): self
- {
- $this->person = $person;
- return $this;
- }
- public function getOrganization(): ?Organization
- {
- return $this->organization;
- }
- public function setOrganization(?Organization $organization): self
- {
- $this->organization = $organization;
- return $this;
- }
- public function getActivityYear(): ?int
- {
- return $this->activityYear;
- }
- public function setActivityYear(?int $activityYear): self
- {
- $this->activityYear = $activityYear;
- return $this;
- }
- public function getHistorical(): array
- {
- return array_key_exists('historical', $this->setting) && $this->setting['historical'] ? $this->setting['historical'] : ['present' => true];
- }
- public function setHistorical(array $historical): self
- {
- if(!$historical['past'] && !$historical['present'] && !$historical['future'])
- $historical['present'] = true;
- $this->setting['historical'] = $historical;
- return $this;
- }
- public function setRoles(?array $roles): self
- {
- $this->roles = $roles;
- return $this;
- }
- public function getRoles(): ?array
- {
- $roles = $this->roles;
- return array_unique($roles);
- }
- public function getPersonActivity(): Collection
- {
- return $this->personActivity;
- }
- public function addPersonActivity(PersonActivity $personActivity): self
- {
- if (!$this->personActivity->contains($personActivity)) {
- $this->personActivity[] = $personActivity;
- $personActivity->setAccess($this);
- }
- return $this;
- }
- public function removePersonActivity(PersonActivity $personActivity): self
- {
- if ($this->personActivity->removeElement($personActivity)) {
- // set the owning side to null (unless already changed)
- if ($personActivity->getAccess() === $this) {
- $personActivity->setAccess(null);
- }
- }
- return $this;
- }
- public function getOrganizationFunction(): Collection
- {
- return $this->organizationFunction;
- }
- public function addOrganizationFunction (OrganizationFunction $organizationFunction): self
- {
- if (!$this->organizationFunction->contains($organizationFunction)) {
- $this->organizationFunction[] = $organizationFunction;
- $organizationFunction->setAccess($this);
- }
- return $this;
- }
- public function removeOrganizationFunction(OrganizationFunction $organizationFunction): self
- {
- if ($this->organizationFunction->removeElement($organizationFunction)) {
- // set the owning side to null (unless already changed)
- if ($organizationFunction->getAccess() === $this) {
- $organizationFunction->setAccess(null);
- }
- }
- return $this;
- }
- public function getOrganizationLicences(): Collection
- {
- return $this->organizationLicences;
- }
- public function addOrganizationLicence(OrganizationLicence $organizationLicence): self
- {
- if (!$this->organizationLicences->contains($organizationLicence)) {
- $this->organizationLicences[] = $organizationLicence;
- $organizationLicence->setLicensee($this);
- }
- return $this;
- }
- public function removeOrganizationLicence(OrganizationLicence $organizationLicence): self
- {
- if ($this->organizationLicences->removeElement($organizationLicence)) {
- // set the owning side to null (unless already changed)
- if ($organizationLicence->getLicensee() === $this) {
- $organizationLicence->setLicensee(null);
- }
- }
- return $this;
- }
- public function getPersonalizedLists(): Collection
- {
- return $this->personalizedLists;
- }
- public function addPersonalizedList(PersonalizedList $personalizedList): self
- {
- if (!$this->personalizedLists->contains($personalizedList)) {
- $this->personalizedLists[] = $personalizedList;
- $personalizedList->setAccess($this);
- }
- return $this;
- }
- public function removePersonalizedList(PersonalizedList $personalizedList): self
- {
- if ($this->personalizedLists->removeElement($personalizedList)) {
- // set the owning side to null (unless already changed)
- if ($personalizedList->getAccess() === $this) {
- $personalizedList->setAccess(null);
- }
- }
- return $this;
- }
- public function getChildren(): Collection
- {
- return $this->children;
- }
- public function addChild (Access $access): self
- {
- if (!$this->children->contains($access)) {
- $this->children[] = $access;
- $access->addGuardian($this);
- }
- return $this;
- }
- public function removeChild(Access $access): self
- {
- if ($this->children->removeElement($access)) {
- $access->removeGuardian($this);
- }
- return $this;
- }
- public function getGuardians(): Collection
- {
- return $this->guardians;
- }
- public function addGuardian(Access $access): self
- {
- if (!$this->guardians->contains($access)) {
- $this->guardians[] = $access;
- $access->addChild($this);
- }
- return $this;
- }
- public function removeGuardian(Access $access): self
- {
- if ($this->guardians->removeElement($access)) {
- $access->removeChild($this);
- }
- return $this;
- }
- #[Pure] public function getUserIdentifier(): string
- {
- return $this->person->getUsername();
- }
- public function getPassword()
- {
- // TODO: Implement getPassword() method.
- }
- public function getSalt()
- {
- // TODO: Implement getSalt() method.
- }
- public function getUsername()
- {
- // TODO: Implement getUsername() method.
- }
- public function eraseCredentials()
- {
- // TODO: Implement eraseCredentials() method.
- }
- }
|