<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\MenuRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\GetCollection;
#[ORM\Entity(repositoryClass: MenuRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['menu:read']],
denormalizationContext: ['groups' => ['menu:write']],
)]
// #[GetCollection]
// #[Get]
// #[Put(security: "is_granted('ROLE_ADMIN')")]
// #[Post(security: "is_granted('ROLE _ADMIN')")]
// #[Delete(security: "is_granted('ROLE_ADMIN')")]
#[ApiFilter(SearchFilter::class, properties: ['type' => 'exact', 'active' => 'exact', 'parent' => 'exact'])]
class Menu
{
#[Groups(['menu:read', 'menu:write'])]
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[Groups(['menu:read', 'menu:write'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[Groups(['menu:read', 'menu:write'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $type = null;
#[Groups(['menu:read', 'menu:write'])]
#[ORM\OneToMany(mappedBy: 'menu', targetEntity: MenuItems::class,cascade:['persist'])]
private Collection $menuItems;
public function __construct()
{
$this->menuItems = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
/**
* @return Collection<int, MenuItems>
*/
public function getMenuItems(): Collection
{
return $this->menuItems;
}
public function addMenuItem(MenuItems $menuItem): self
{
if (!$this->menuItems->contains($menuItem)) {
$this->menuItems->add($menuItem);
$menuItem->setMenu($this);
}
return $this;
}
public function removeMenuItem(MenuItems $menuItem): self
{
if ($this->menuItems->removeElement($menuItem)) {
// set the owning side to null (unless already changed)
if ($menuItem->getMenu() === $this) {
$menuItem->setMenu(null);
}
}
return $this;
}
}