src/Entity/Menu.php line 34

  1. <?php
  2. namespace App\Entity;
  3. use Ramsey\Uuid\Uuid;
  4. use App\Trait\UuidTrait;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\Put;
  7. use ApiPlatform\Metadata\Post;
  8. use ApiPlatform\Metadata\Patch;
  9. use ApiPlatform\Metadata\Delete;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use App\Controller\MenuController;
  12. use App\Repository\MenuRepository;
  13. use ApiPlatform\Metadata\ApiResource;
  14. use ApiPlatform\Metadata\GetCollection;
  15. use Doctrine\Common\Collections\Collection;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use Symfony\Component\Serializer\Annotation\Groups;
  18. use Symfony\Component\Validator\Constraints as Assert;
  19. #[ORM\Entity(repositoryClassMenuRepository::class)]
  20. #[ApiResource(
  21.         operations: [
  22.             new GetCollection(controllerMenuController::class),
  23.             new Post(validationContext: ['groups' => ['Default''menu:create']], denormalizationContext: ['groups' => ['menu:create']]),
  24.             new Get(),
  25.             new Put(denormalizationContext: ['groups' => ['menu:update']]),
  26.             new Patch(denormalizationContext: ['groups' => ['menu:update']]),
  27.             new Delete(),
  28.         ],
  29.         normalizationContext: ['groups' => ['menu:read''uuid']],
  30.     )
  31. ]
  32. class Menu
  33. {
  34.     use UuidTrait;
  35.     
  36.     #[Assert\NotNull(groups: ['menu:create'])]
  37.     #[Groups(['menu:read''menu:create''menu:update'])]
  38.     #[ORM\ManyToOne]
  39.     #[ORM\JoinColumn(nullablefalse)]
  40.     private ?Empresa $empresa null;
  41.     #[Assert\NotNull(groups: ['menu:create'])]
  42.     #[Groups(['menu:read''menu:create''menu:update'])]
  43.     #[ORM\Column(length255)]
  44.     private ?string $nombre null;
  45.     #[Groups(['menu:read''menu:create''menu:update'])]
  46.     #[ORM\Column]
  47.     private ?bool $isActive null;
  48.     #[Assert\NotNull(groups: ['menu:create'])]
  49.     #[Groups(['menu:read''menu:create''menu:update'])]
  50.     #[ORM\Column(length255)]
  51.     private ?string $icon null;
  52.     #[Groups(['menu:read''menu:create''menu:update'])]
  53.     #[ORM\Column(length255nullabletrue)]
  54.     private ?string $link null;
  55.     #[Groups(['menu:read''menu:create''menu:update'])]
  56.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'submenus')]
  57.     private ?self $parentMenu null;
  58.     #[Groups(['menu:read'])]
  59.     #[ORM\OneToMany(mappedBy'parentMenu'targetEntityself::class)]
  60.     private Collection $submenus;
  61.     #[Groups(['menu:read''menu:create''menu:update'])]
  62.     #[ORM\Column]
  63.     private ?int $orden null;
  64.     #[Groups(['menu:read''menu:create''menu:update'])]
  65.     #[ORM\Column(length255)]
  66.     private ?string $rol null;
  67.     #[Groups(['menu:read'])]
  68.     public $permisos;
  69.     public function __construct()
  70.     {
  71.         $this->submenus = new ArrayCollection();
  72.         $this->uuid Uuid::uuid4()->toString();
  73.     }
  74.     public function getEmpresa(): ?Empresa
  75.     {
  76.         return $this->empresa;
  77.     }
  78.     public function setEmpresa(?Empresa $empresa): self
  79.     {
  80.         $this->empresa $empresa;
  81.         return $this;
  82.     }
  83.     public function getNombre(): ?string
  84.     {
  85.         return $this->nombre;
  86.     }
  87.     public function setNombre(string $nombre): self
  88.     {
  89.         $this->nombre $nombre;
  90.         return $this;
  91.     }
  92.     public function isIsActive(): ?bool
  93.     {
  94.         return $this->isActive;
  95.     }
  96.     public function setIsActive(bool $isActive): self
  97.     {
  98.         $this->isActive $isActive;
  99.         return $this;
  100.     }
  101.     public function getIcon(): ?string
  102.     {
  103.         return $this->icon;
  104.     }
  105.     public function setIcon(string $icon): self
  106.     {
  107.         $this->icon $icon;
  108.         return $this;
  109.     }
  110.     public function getLink(): ?string
  111.     {
  112.         return $this->link;
  113.     }
  114.     public function setLink(?string $link): self
  115.     {
  116.         $this->link $link;
  117.         return $this;
  118.     }
  119.     public function getParentMenu(): ?self
  120.     {
  121.         return $this->parentMenu;
  122.     }
  123.     public function setParentMenu(?self $parentMenu): self
  124.     {
  125.         $this->parentMenu $parentMenu;
  126.         return $this;
  127.     }
  128.     /**
  129.      * @return Collection<int, self>
  130.      */
  131.     public function getSubmenus(): Collection
  132.     {
  133.         return $this->submenus;
  134.     }
  135.     public function addSubmenu(self $submenu): self
  136.     {
  137.         if (!$this->submenus->contains($submenu)) {
  138.             $this->submenus->add($submenu);
  139.             $submenu->setParentMenu($this);
  140.         }
  141.         return $this;
  142.     }
  143.     public function removeSubmenu(self $submenu): self
  144.     {
  145.         // set the owning side to null (unless already changed)
  146.         if ($this->submenus->removeElement($submenu) && $submenu->getParentMenu() === $this) {
  147.             $submenu->setParentMenu(null);
  148.         }
  149.         return $this;
  150.     }
  151.     public function getOrden(): ?int
  152.     {
  153.         return $this->orden;
  154.     }
  155.     public function setOrden(int $orden): self
  156.     {
  157.         $this->orden $orden;
  158.         return $this;
  159.     }
  160.     public function getRol(): ?string
  161.     {
  162.         return $this->rol;
  163.     }
  164.     public function setRol(string $rol): self
  165.     {
  166.         $this->rol $rol;
  167.         return $this;
  168.     }
  169. }