src/Entity/EntityLists.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\EntityListsRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use ApiPlatform\Metadata\ApiFilter;
  10. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  11. #[ORM\Entity(repositoryClassEntityListsRepository::class)]
  12. #[ApiResource(
  13.     normalizationContext: ['groups' => ['entity_list:read']],
  14.     denormalizationContext: ['groups' => ['entity_list:write']],
  15.     order: ['id' => 'ASC'],
  16. )]
  17. class EntityLists
  18. {
  19.     #[Groups(['entity_list:read''entity_list:write''permission:read''role:read''user:read'])]
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue]
  22.     #[ORM\Column]
  23.     private ?int $id null;
  24.     #[Groups(['entity_list:read''entity_list:write''permission:read''role:read''user:read'])]
  25.     #[ORM\Column(length255nullabletrue)]
  26.     private ?string $name null;
  27.     #[Groups(['entity_list:read''entity_list:write''permission:read''role:read''user:read'])]
  28.     #[ORM\Column(length255nullabletrue)]
  29.     private ?string $key null;
  30.     /**
  31.      * @var Collection<int, Permission>
  32.      */
  33.     #[ORM\OneToMany(mappedBy'entityList'targetEntityPermission::class)]
  34.     private Collection $permissions;
  35.     public function __construct()
  36.     {
  37.         $this->permissions = new ArrayCollection();
  38.     }
  39.     public function getId(): ?int
  40.     {
  41.         return $this->id;
  42.     }
  43.     public function getName(): ?string
  44.     {
  45.         return $this->name;
  46.     }
  47.     public function setName(?string $name): static
  48.     {
  49.         $this->name $name;
  50.         return $this;
  51.     }
  52.     public function getKey(): ?string
  53.     {
  54.         return $this->key;
  55.     }
  56.     public function setKey(?string $key): static
  57.     {
  58.         $this->key $key;
  59.         return $this;
  60.     }
  61.     /**
  62.      * @return Collection<int, Permission>
  63.      */
  64.     public function getPermissions(): Collection
  65.     {
  66.         return $this->permissions;
  67.     }
  68.     public function addPermission(Permission $permission): static
  69.     {
  70.         if (!$this->permissions->contains($permission)) {
  71.             $this->permissions->add($permission);
  72.             $permission->setEntityList($this);
  73.         }
  74.         return $this;
  75.     }
  76.     public function removePermission(Permission $permission): static
  77.     {
  78.         if ($this->permissions->removeElement($permission)) {
  79.             // set the owning side to null (unless already changed)
  80.             if ($permission->getEntityList() === $this) {
  81.                 $permission->setEntityList(null);
  82.             }
  83.         }
  84.         return $this;
  85.     }
  86. }