src/Entity/Menu.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\MenuRepository;
  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. use ApiPlatform\Metadata\ApiFilter;
  11. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  12. use ApiPlatform\Metadata\Get;
  13. use ApiPlatform\Metadata\Post;
  14. use ApiPlatform\Metadata\Put;
  15. use ApiPlatform\Metadata\Delete;
  16. use ApiPlatform\Metadata\GetCollection;
  17. #[ORM\Entity(repositoryClassMenuRepository::class)]
  18. #[ApiResource(
  19.     normalizationContext: ['groups' => ['menu:read']],
  20.     denormalizationContext: ['groups' => ['menu:write']],
  21. )]
  22.     // #[GetCollection]
  23.     // #[Get]
  24.     // #[Put(security: "is_granted('ROLE_ADMIN')")]
  25.     // #[Post(security: "is_granted('ROLE   _ADMIN')")]
  26.     // #[Delete(security: "is_granted('ROLE_ADMIN')")]
  27. #[ApiFilter(SearchFilter::class, properties: ['type' => 'exact''active' => 'exact''parent' => 'exact''role' => 'exact''role.name' => 'exact','language.id' => 'exact' ])]
  28. class Menu
  29. {
  30.     #[Groups(['menu:read''menu:write''user:read'])]
  31.     #[ORM\Id]
  32.     #[ORM\GeneratedValue]
  33.     #[ORM\Column]
  34.     private ?int $id null;
  35.     #[Groups(['menu:read''menu:write','user:read'])]
  36.     #[ORM\Column(length255nullabletrue)]
  37.     private ?string $name null;
  38.     #[Groups(['menu:read''menu:write'])]
  39.     #[ORM\Column(length255nullabletrue)]
  40.     private ?string $type null;
  41.     #[Groups(['menu:read''menu:write'])]
  42.     #[ORM\OneToMany(mappedBy'menu'targetEntityMenuItems::class, cascade:['persist''remove'])]
  43.     private Collection $menuItems;
  44.     /**
  45.      * @var Collection<int, Role>
  46.      */
  47.     #[ORM\ManyToMany(targetEntityRole::class, inversedBy'menus'cascade:['persist''remove'])]
  48.     private Collection $role;
  49.     public function __construct()
  50.     {
  51.         $this->menuItems = new ArrayCollection();
  52.         $this->role = new ArrayCollection();
  53.     }
  54.     public function getId(): ?int
  55.     {
  56.         return $this->id;
  57.     }
  58.     public function getName(): ?string
  59.     {
  60.         return $this->name;
  61.     }
  62.     public function setName(?string $name): self
  63.     {
  64.         $this->name $name;
  65.         return $this;
  66.     }
  67.     public function getType(): ?string
  68.     {
  69.         return $this->type;
  70.     }
  71.     public function setType(?string $type): self
  72.     {
  73.         $this->type $type;
  74.         return $this;
  75.     }
  76.     /**
  77.      * @return Collection<int, MenuItems>
  78.      */
  79.     public function getMenuItems(): Collection
  80.     {
  81.         return $this->menuItems;
  82.     }
  83.     public function addMenuItem(MenuItems $menuItem): self
  84.     {
  85.         if (!$this->menuItems->contains($menuItem)) {
  86.             $this->menuItems->add($menuItem);
  87.             $menuItem->setMenu($this);
  88.         }
  89.         return $this;
  90.     }
  91.     public function removeMenuItem(MenuItems $menuItem): self
  92.     {
  93.         if ($this->menuItems->removeElement($menuItem)) {
  94.             // set the owning side to null (unless already changed)
  95.             if ($menuItem->getMenu() === $this) {
  96.                 $menuItem->setMenu(null);
  97.             }
  98.         }
  99.         return $this;
  100.     }
  101.     /**
  102.      * @return Collection<int, Role>
  103.      */
  104.     public function getRole(): Collection
  105.     {
  106.         return $this->role;
  107.     }
  108.     public function addRole(Role $role): static
  109.     {
  110.         if (!$this->role->contains($role)) {
  111.             $this->role->add($role);
  112.         }
  113.         return $this;
  114.     }
  115.     public function removeRole(Role $role): static
  116.     {
  117.         $this->role->removeElement($role);
  118.         return $this;
  119.     }
  120. }