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.     #[Groups(['menu:read''menu_items:read''menu_items:write'])] 
  72.     #[ORM\Column(length255nullabletrue)]
  73.     private ?string $imageUrl null;
  74.     public function __construct()
  75.     {
  76.         $this->children = new ArrayCollection();
  77.     }
  78.     public function getId(): ?int
  79.     {
  80.         return $this->id;
  81.     }
  82.     public function getName(): ?string
  83.     {
  84.         return $this->name;
  85.     }
  86.     public function setName(?string $name): self
  87.     {
  88.         $this->name $name;
  89.         return $this;
  90.     }
  91.     public function getSlug(): ?string
  92.     {
  93.         return $this->slug;
  94.     }
  95.     public function setSlug(?string $slug): self
  96.     {
  97.         $this->slug $slug;
  98.         return $this;
  99.     }
  100.     public function getPlace(): ?string
  101.     {
  102.         return $this->place;
  103.     }
  104.     public function setPlace(?string $place): self
  105.     {
  106.         $this->place $place;
  107.         return $this;
  108.     }
  109.     public function getType(): ?string
  110.     {
  111.         return $this->type;
  112.     }
  113.     public function setType(?string $type): self
  114.     {
  115.         $this->type $type;
  116.         return $this;
  117.     }
  118.     public function getContent(): ?string
  119.     {
  120.         return $this->content;
  121.     }
  122.     public function setContent(?string $content): self
  123.     {
  124.         $this->content $content;
  125.         return $this;
  126.     }
  127.     public function getOrders(): ?int
  128.     {
  129.         return $this->orders;
  130.     }
  131.     public function setOrders(?int $orders): self
  132.     {
  133.         $this->orders $orders;
  134.         return $this;
  135.     }
  136.     public function getActive(): ?string
  137.     {
  138.         return $this->active;
  139.     }
  140.     public function setActive(?string $active): self
  141.     {
  142.         $this->active $active;
  143.         return $this;
  144.     }
  145.     public function getClickability(): ?string
  146.     {
  147.         return $this->clickability;
  148.     }
  149.     public function setClickability(?string $clickability): self
  150.     {
  151.         $this->clickability $clickability;
  152.         return $this;
  153.     }
  154.     public function getMenuClass(): ?string
  155.     {
  156.         return $this->menu_class;
  157.     }
  158.     public function setMenuClass(?string $menu_class): self
  159.     {
  160.         $this->menu_class $menu_class;
  161.         return $this;
  162.     }
  163.     public function getParent(): ?self
  164.     {
  165.         return $this->parent;
  166.     }
  167.     public function setParent(?self $parent): self
  168.     {
  169.         $this->parent $parent;
  170.         return $this;
  171.     }
  172.     /**
  173.      * @return Collection<int, self>
  174.      */
  175.     public function getChildren(): Collection
  176.     {
  177.         return $this->children;
  178.     }
  179.     public function addChild(self $child): self
  180.     {
  181.         if (!$this->children->contains($child)) {
  182.             $this->children->add($child);
  183.             $child->setParent($this);
  184.         }
  185.         return $this;
  186.     }
  187.     public function removeChild(self $child): self
  188.     {
  189.         if ($this->children->removeElement($child)) {
  190.             // set the owning side to null (unless already changed)
  191.             if ($child->getParent() === $this) {
  192.                 $child->setParent(null);
  193.             }
  194.         }
  195.         return $this;
  196.     }
  197.     public function getPage(): ?Pages
  198.     {
  199.         return $this->page;
  200.     }
  201.     public function setPage(?Pages $page): self
  202.     {
  203.         $this->page $page;
  204.         return $this;
  205.     }
  206.     public function getMenu(): ?Menu
  207.     {
  208.         return $this->menu;
  209.     }
  210.     public function setMenu(?Menu $menu): self
  211.     {
  212.         $this->menu $menu;
  213.         return $this;
  214.     }
  215.     public function getImageUrl(): ?string
  216.     {
  217.         return $this->imageUrl;
  218.     }
  219.     public function setImageUrl(string $imageUrl): self
  220.     {
  221.         $this->imageUrl $imageUrl;
  222.         return $this;
  223.     }
  224. }