| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <?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;
- /**
- * Fais le lien entre une Person et une Organization
- * @ApiResource(
- * collectionOperations={
- * "get"={"security"="is_granted('ROLE_USERS_VIEW')"},
- * "post"
- * },
- * 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')"},
- * "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\ManyToOne(targetEntity=Person::class, cascade={"persist"})
- * @ORM\JoinColumn(nullable=false)
- */
- private $person;
- /**
- * @ORM\ManyToOne(targetEntity=Organization::class)
- * @ORM\JoinColumn(nullable=false)
- */
- public $organization;
- /**
- * @var array
- * @ORM\Column(type="json_array", length=4294967295, nullable=true)
- */
- private $roles = [];
- /**
- * @ORM\OneToMany(targetEntity=PersonActivity::class, mappedBy="access")
- * @ApiSubresource()
- */
- private $personActivity;
- /**
- * @ORM\OneToMany(targetEntity=OrganizationLicence::class, mappedBy="licensee", orphanRemoval=true)
- */
- private $organizationLicences;
- public function __construct()
- {
- $this->personActivity = new ArrayCollection();
- $this->organizationLicences = 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;
- }
- /**
- * @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;
- }
- /**
- * A visual identifier that represents this user.
- *
- * @see string
- */
- public function getUserIdentifier(): string
- {
- return $this->getPerson()->getUsername();
- }
- /**
- * @inheritDoc
- */
- public function getRoles()
- {
- $roles = $this->roles;
- return array_unique($roles);
- }
- /**
- * @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;
- }
- }
|