src/Entity/Role.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\RoleRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. #[ORM\Entity(repositoryClassRoleRepository::class)]
  11. #[ApiResource(
  12.     normalizationContext: ['groups' => ['role:read']],
  13.     denormalizationContext: ['groups' => ['role:write']],
  14.     order: ['name' => 'ASC'],
  15. )]
  16. class Role
  17. {
  18.     #[ORM\Id]
  19.     #[ORM\GeneratedValue]
  20.     #[ORM\Column]
  21.     #[Groups(['role:read''role:write''user:read'])]
  22.     private ?int $id null;
  23.     #[Groups(['role:read''role:write''user:read'])]
  24.     #[ORM\Column(length255)]
  25.     private ?string $name null;
  26.     #[Groups(['role:read''role:write''user:read'])]
  27.     #[ORM\Column(length255)]
  28.     private ?string $label null;
  29.     #[Groups(['role:read''role:write''user:read'])]
  30.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  31.     private ?string $description null;
  32.     /**
  33.      * @var Collection<int, UserRole>
  34.      */
  35.     #[ORM\OneToMany(mappedBy'role'targetEntityUserRole::class, cascade:['persist''remove'])]
  36.     private Collection $userRoles;
  37.     /**
  38.      * @var Collection<int, Permission>
  39.      */
  40.     #[ORM\OneToMany(mappedBy'role'targetEntityPermission::class, cascade:['remove'])]
  41.     private Collection $permissions;
  42.     #[Groups(['role:read''role:write''user:read'])]
  43.     #[ORM\Column(nullabletrue)]
  44.     private ?bool $loginAdminPanel null;
  45.     /**
  46.      * @var Collection<int, Menu>
  47.      */
  48.     #[Groups(['role:read''role:write''user:read'])]
  49.     #[ORM\ManyToMany(targetEntityMenu::class, mappedBy'role')]
  50.     private Collection $menus;
  51.     public function __construct()
  52.     {
  53.         $this->userRoles = new ArrayCollection();
  54.         $this->permissions = new ArrayCollection();
  55.         $this->menus = new ArrayCollection();
  56.     }
  57.     public function getId(): ?int
  58.     {
  59.         return $this->id;
  60.     }
  61.     public function getName(): ?string
  62.     {
  63.         return $this->name;
  64.     }
  65.     public function setName(string $name): static
  66.     {
  67.         $this->name $name;
  68.         return $this;
  69.     }
  70.     public function getLabel(): ?string
  71.     {
  72.         return $this->label;
  73.     }
  74.     public function setLabel(string $label): static
  75.     {
  76.         $this->label $label;
  77.         return $this;
  78.     }
  79.     public function getDescription(): ?string
  80.     {
  81.         return $this->description;
  82.     }
  83.     public function setDescription(?string $description): static
  84.     {
  85.         $this->description $description;
  86.         return $this;
  87.     }
  88.     /**
  89.      * @return Collection<int, UserRole>
  90.      */
  91.     public function getUserRoles(): Collection
  92.     {
  93.         return $this->userRoles;
  94.     }
  95.     public function addUserRole(UserRole $userRole): static
  96.     {
  97.         if (!$this->userRoles->contains($userRole)) {
  98.             $this->userRoles->add($userRole);
  99.             $userRole->setRole($this);
  100.         }
  101.         return $this;
  102.     }
  103.     public function removeUserRole(UserRole $userRole): static
  104.     {
  105.         if ($this->userRoles->removeElement($userRole)) {
  106.             // set the owning side to null (unless already changed)
  107.             if ($userRole->getRole() === $this) {
  108.                 $userRole->setRole(null);
  109.             }
  110.         }
  111.         return $this;
  112.     }
  113.     /**
  114.      * @return Collection<int, Permission>
  115.      */
  116.     public function getPermissions(): Collection
  117.     {
  118.         return $this->permissions;
  119.     }
  120.     public function addPermission(Permission $permission): static
  121.     {
  122.         if (!$this->permissions->contains($permission)) {
  123.             $this->permissions->add($permission);
  124.             $permission->setRole($this);
  125.         }
  126.         return $this;
  127.     }
  128.     public function removePermission(Permission $permission): static
  129.     {
  130.         if ($this->permissions->removeElement($permission)) {
  131.             // set the owning side to null (unless already changed)
  132.             if ($permission->getRole() === $this) {
  133.                 $permission->setRole(null);
  134.             }
  135.         }
  136.         return $this;
  137.     }
  138.     public function isLoginAdminPanel(): ?bool
  139.     {
  140.         return $this->loginAdminPanel;
  141.     }
  142.     public function setLoginAdminPanel(?bool $loginAdminPanel): static
  143.     {
  144.         $this->loginAdminPanel $loginAdminPanel;
  145.         return $this;
  146.     }
  147.     /**
  148.      * @return Collection<int, Menu>
  149.      */
  150.     public function getMenus(): Collection
  151.     {
  152.         return $this->menus;
  153.     }
  154.     public function addMenu(Menu $menu): static
  155.     {
  156.         if (!$this->menus->contains($menu)) {
  157.             $this->menus->add($menu);
  158.             $menu->addRole($this);
  159.         }
  160.         return $this;
  161.     }
  162.     public function removeMenu(Menu $menu): static
  163.     {
  164.         if ($this->menus->removeElement($menu)) {
  165.             $menu->removeRole($this);
  166.         }
  167.         return $this;
  168.     }
  169. }