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'])]
  28. class Menu
  29. {
  30.     #[Groups(['menu:read''menu:write'])]
  31.     #[ORM\Id]
  32.     #[ORM\GeneratedValue]
  33.     #[ORM\Column]
  34.     private ?int $id null;
  35.     #[Groups(['menu:read''menu:write'])]
  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'])]
  43.     private Collection $menuItems;
  44.     public function __construct()
  45.     {
  46.         $this->menuItems = new ArrayCollection();
  47.     }
  48.     public function getId(): ?int
  49.     {
  50.         return $this->id;
  51.     }
  52.     public function getName(): ?string
  53.     {
  54.         return $this->name;
  55.     }
  56.     public function setName(?string $name): self
  57.     {
  58.         $this->name $name;
  59.         return $this;
  60.     }
  61.     public function getType(): ?string
  62.     {
  63.         return $this->type;
  64.     }
  65.     public function setType(?string $type): self
  66.     {
  67.         $this->type $type;
  68.         return $this;
  69.     }
  70.     /**
  71.      * @return Collection<int, MenuItems>
  72.      */
  73.     public function getMenuItems(): Collection
  74.     {
  75.         return $this->menuItems;
  76.     }
  77.     public function addMenuItem(MenuItems $menuItem): self
  78.     {
  79.         if (!$this->menuItems->contains($menuItem)) {
  80.             $this->menuItems->add($menuItem);
  81.             $menuItem->setMenu($this);
  82.         }
  83.         return $this;
  84.     }
  85.     public function removeMenuItem(MenuItems $menuItem): self
  86.     {
  87.         if ($this->menuItems->removeElement($menuItem)) {
  88.             // set the owning side to null (unless already changed)
  89.             if ($menuItem->getMenu() === $this) {
  90.                 $menuItem->setMenu(null);
  91.             }
  92.         }
  93.         return $this;
  94.     }
  95. }