<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\EntityListsRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
#[ORM\Entity(repositoryClass: EntityListsRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['entity_list:read']],
denormalizationContext: ['groups' => ['entity_list:write']],
order: ['id' => 'ASC'],
)]
class EntityLists
{
#[Groups(['entity_list:read', 'entity_list:write', 'permission:read', 'role:read', 'user:read'])]
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[Groups(['entity_list:read', 'entity_list:write', 'permission:read', 'role:read', 'user:read'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[Groups(['entity_list:read', 'entity_list:write', 'permission:read', 'role:read', 'user:read'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $key = null;
/**
* @var Collection<int, Permission>
*/
#[ORM\OneToMany(mappedBy: 'entityList', targetEntity: Permission::class)]
private Collection $permissions;
public function __construct()
{
$this->permissions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
public function getKey(): ?string
{
return $this->key;
}
public function setKey(?string $key): static
{
$this->key = $key;
return $this;
}
/**
* @return Collection<int, Permission>
*/
public function getPermissions(): Collection
{
return $this->permissions;
}
public function addPermission(Permission $permission): static
{
if (!$this->permissions->contains($permission)) {
$this->permissions->add($permission);
$permission->setEntityList($this);
}
return $this;
}
public function removePermission(Permission $permission): static
{
if ($this->permissions->removeElement($permission)) {
// set the owning side to null (unless already changed)
if ($permission->getEntityList() === $this) {
$permission->setEntityList(null);
}
}
return $this;
}
}