| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408 |
- <?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 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\GeneratedValue
- * @ORM\Column(type="integer")
- */
- private $id;
- /**
- * @ORM\Column(type="boolean", options={"default" : false})
- */
- private $adminAccess = false;
- /**
- * @ORM\Column(type="integer", nullable=true)
- */
- private $activityYear;
- /**
- * @ORM\ManyToOne(targetEntity=Person::class, cascade={"persist"})
- * @ORM\JoinColumn(nullable=false)
- */
- private $person;
- /**
- * @ORM\ManyToOne(targetEntity=Organization::class)
- * @ORM\JoinColumn(nullable=false)
- */
- public $organization;
- /**
- * @ORM\Column(type="json_array", length=4294967295, nullable=true)
- */
- private $roles = [];
- /**
- * @Groups({"my_access:input"})
- * @ORM\Column(type="json_array", length=4294967295, nullable=true)
- */
- private $setting;
- /**
- * @Groups({"my_access:input"})
- */
- private $historical;
- /**
- * @var ArrayCollection<PersonActivity>
- * @ORM\OneToMany(targetEntity=PersonActivity::class, mappedBy="access", orphanRemoval=true, cascade={"persist"})
- * @ApiSubresource()
- */
- private $personActivity;
- /**
- * @var ArrayCollection<OrganizationFunction>
- * @ORM\OneToMany(targetEntity=OrganizationFunction::class, mappedBy="access", orphanRemoval=true, cascade={"persist"})
- * @ApiSubresource()
- */
- private $organizationFunction;
- /**
- * @var ArrayCollection<OrganizationLicence>
- * @ORM\OneToMany(targetEntity=OrganizationLicence::class, mappedBy="licensee", orphanRemoval=true)
- */
- private $organizationLicences;
- /**
- * @var ArrayCollection<Access>
- * @ORM\ManyToMany(targetEntity=Access::class, mappedBy="children", cascade={"persist"})
- */
- private $guardians;
- /**
- * @var ArrayCollection<Access>
- * @ORM\ManyToMany(targetEntity=Access::class, inversedBy="guardians", cascade={"persist"})
- * @ORM\JoinTable(name="children_guardians",
- * joinColumns={@ORM\JoinColumn(name="guardians_id", referencedColumnName="id")},
- * inverseJoinColumns={@ORM\JoinColumn(name="children_id", referencedColumnName="id")}
- * )
- */
- private $children;
- public function __construct()
- {
- $this->personActivity = new ArrayCollection();
- $this->organizationFunction = new ArrayCollection();
- $this->organizationLicences = 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 getActivityYear(): ?int
- {
- return $this->activityYear;
- }
- public function setActivityYear(int $activityYear): self
- {
- $this->activityYear = $activityYear;
- 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;
- }
- /**
- * @return Collection|PersonActivity[]
- */
- 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;
- }
- /**
- * @return Collection|OrganizationFunction[]
- */
- 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;
- }
- /**
- * A visual identifier that represents this user.
- *
- * @see string
- */
- public function getUserIdentifier(): string
- {
- return $this->getPerson()->getUsername();
- }
- /**
- * @inheritDoc
- */
- public function setRoles(array $roles): self
- {
- $this->roles = $roles;
- return $this;
- }
- /**
- * @inheritDoc
- */
- public function getRoles(): array
- {
- $roles = $this->roles;
- return array_unique($roles);
- }
- public function setSetting(array $setting): self
- {
- $this->setting = $setting;
- return $this;
- }
- public function getSetting(): array
- {
- return $this->setting;
- }
- public function getHistorical(): array
- {
- return $this->setting['historical'] ?? [];
- }
- public function setHistorical(array $historical): self
- {
- $this->setting['historical'] = $historical;
- return $this;
- }
- /**
- * @inheritDoc
- */
- public function getPassword()
- {
- // TODO: Implement getPassword() method.
- }
- /**
- * @inheritDoc
- */
- public function getSalt()
- {
- // TODO: Implement getSalt() method.
- }
- /**
- * @inheritDoc
- */
- public function getUsername()
- {
- // TODO: Implement getUsername() method.
- }
- /**
- * @inheritDoc
- */
- public function eraseCredentials()
- {
- // TODO: Implement eraseCredentials() method.
- }
- /**
- * @return Collection|OrganizationLicence[]
- */
- 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;
- }
- /**
- * @return Collection|Access[]
- */
- 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;
- }
- /**
- * @return Collection|Access[]
- */
- 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;
- }
- }
|