src/Entity/MenuItems.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\MenuItemsRepository;
  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(repositoryClassMenuItemsRepository::class)]
  18. #[ApiResource(
  19.     normalizationContext: ['groups' => ['menu_items:read']],
  20.     denormalizationContext: ['groups' => ['menu_items:write']],
  21.     order: ['orders' => 'ASC'],
  22. )]
  23. #[GetCollection]
  24. #[Get]
  25. #[Put(security"is_granted('ROLE_ADMIN')")]
  26. #[Post(security"is_granted('ROLE_ADMIN')")]
  27. #[Delete(security"is_granted('ROLE_ADMIN')")]
  28. #[ApiFilter(SearchFilter::class, properties: ['menu.id' => 'exact','type' => 'exact''parent' => 'exact'])]
  29. class MenuItems
  30. {
  31.     #[Groups(['menu:read''menu_items:read''menu_items:write'])]
  32.     #[ORM\Id]
  33.     #[ORM\GeneratedValue]
  34.     #[ORM\Column]
  35.     private ?int $id null;
  36.     #[Groups(['menu:read''menu_items:read''menu_items:write'])]
  37.     #[ORM\Column(length255nullabletrue)]
  38.     private ?string $name null;
  39.     
  40.     #[Groups(['menu:read''menu_items:read''menu_items:write'])]
  41.     #[ORM\Column(length100nullabletrue)]
  42.     private ?string $slug null;
  43.     #[ORM\Column(length1nullabletrue)]
  44.     private ?string $place null;
  45.     #[ORM\Column(length20nullabletrue)]
  46.     private ?string $type null;
  47.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  48.     private ?string $content null;
  49.     #[Groups(['menu:read''menu_items:read''menu_items:write'])]
  50.     #[ORM\Column(nullabletrue)]
  51.     private ?int $orders null;
  52.     #[ORM\Column(length10nullabletrue)]
  53.     private ?string $active null;
  54.     #[ORM\Column(length10nullabletrue)]
  55.     private ?string $clickability null;
  56.     #[ORM\Column(length255nullabletrue)]
  57.     private ?string $menu_class null;
  58.     
  59.     #[Groups(['menu:read''menu_items:read''menu_items:write'])]
  60.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'children')]
  61.     private ?self $parent null;
  62.     
  63.     #[Groups(['menu:read''menu_items:read''menu_items:write'])]
  64.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class, cascade:['persist'])]
  65.     private Collection $children;
  66.     #[ORM\ManyToOne]
  67.     private ?Pages $page null;
  68.     #[Groups(['menu:read''menu_items:read''menu_items:write'])]
  69.     #[ORM\ManyToOne(inversedBy'menuItems')]
  70.     private ?Menu $menu null;
  71.     public function __construct()
  72.     {
  73.         $this->children = new ArrayCollection();
  74.     }
  75.     public function getId(): ?int
  76.     {
  77.         return $this->id;
  78.     }
  79.     public function getName(): ?string
  80.     {
  81.         return $this->name;
  82.     }
  83.     public function setName(?string $name): self
  84.     {
  85.         $this->name $name;
  86.         return $this;
  87.     }
  88.     public function getSlug(): ?string
  89.     {
  90.         return $this->slug;
  91.     }
  92.     public function setSlug(?string $slug): self
  93.     {
  94.         $this->slug $slug;
  95.         return $this;
  96.     }
  97.     public function getPlace(): ?string
  98.     {
  99.         return $this->place;
  100.     }
  101.     public function setPlace(?string $place): self
  102.     {
  103.         $this->place $place;
  104.         return $this;
  105.     }
  106.     public function getType(): ?string
  107.     {
  108.         return $this->type;
  109.     }
  110.     public function setType(?string $type): self
  111.     {
  112.         $this->type $type;
  113.         return $this;
  114.     }
  115.     public function getContent(): ?string
  116.     {
  117.         return $this->content;
  118.     }
  119.     public function setContent(?string $content): self
  120.     {
  121.         $this->content $content;
  122.         return $this;
  123.     }
  124.     public function getOrders(): ?int
  125.     {
  126.         return $this->orders;
  127.     }
  128.     public function setOrders(?int $orders): self
  129.     {
  130.         $this->orders $orders;
  131.         return $this;
  132.     }
  133.     public function getActive(): ?string
  134.     {
  135.         return $this->active;
  136.     }
  137.     public function setActive(?string $active): self
  138.     {
  139.         $this->active $active;
  140.         return $this;
  141.     }
  142.     public function getClickability(): ?string
  143.     {
  144.         return $this->clickability;
  145.     }
  146.     public function setClickability(?string $clickability): self
  147.     {
  148.         $this->clickability $clickability;
  149.         return $this;
  150.     }
  151.     public function getMenuClass(): ?string
  152.     {
  153.         return $this->menu_class;
  154.     }
  155.     public function setMenuClass(?string $menu_class): self
  156.     {
  157.         $this->menu_class $menu_class;
  158.         return $this;
  159.     }
  160.     public function getParent(): ?self
  161.     {
  162.         return $this->parent;
  163.     }
  164.     public function setParent(?self $parent): self
  165.     {
  166.         $this->parent $parent;
  167.         return $this;
  168.     }
  169.     /**
  170.      * @return Collection<int, self>
  171.      */
  172.     public function getChildren(): Collection
  173.     {
  174.         return $this->children;
  175.     }
  176.     public function addChild(self $child): self
  177.     {
  178.         if (!$this->children->contains($child)) {
  179.             $this->children->add($child);
  180.             $child->setParent($this);
  181.         }
  182.         return $this;
  183.     }
  184.     public function removeChild(self $child): self
  185.     {
  186.         if ($this->children->removeElement($child)) {
  187.             // set the owning side to null (unless already changed)
  188.             if ($child->getParent() === $this) {
  189.                 $child->setParent(null);
  190.             }
  191.         }
  192.         return $this;
  193.     }
  194.     public function getPage(): ?Pages
  195.     {
  196.         return $this->page;
  197.     }
  198.     public function setPage(?Pages $page): self
  199.     {
  200.         $this->page $page;
  201.         return $this;
  202.     }
  203.     public function getMenu(): ?Menu
  204.     {
  205.         return $this->menu;
  206.     }
  207.     public function setMenu(?Menu $menu): self
  208.     {
  209.         $this->menu $menu;
  210.         return $this;
  211.     }
  212. }