src/Entity/Website/Menu/MenuItem.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Website\Menu;
  3. use App\Entity\BaseEntity;
  4. use App\Repository\Website\Menu\MenuItemRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  9. #[ORM\Entity(repositoryClassMenuItemRepository::class)]
  10. class MenuItem extends BaseEntity
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\Column(type'guid'uniquetrue)]
  14.     #[ORM\GeneratedValue(strategy'CUSTOM')]
  15.     #[ORM\CustomIdGenerator(class: UuidGenerator::class)]
  16.     private ?string $id;
  17.     #[ORM\Column(length255)]
  18.     private ?string $label null;
  19.     #[ORM\Column(length255nullabletrue)]
  20.     private ?string $url null;
  21.     #[ORM\Column(nullabletrue)]
  22.     private ?int $menuItemOrder null;
  23.     #[ORM\ManyToOne(inversedBy'menuItems')]
  24.     #[ORM\JoinColumn(nullablefalse)]
  25.     private ?Menu $menu null;
  26.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'menuItems')]
  27.     private ?self $parent null;
  28.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class)]
  29.     private Collection $menuItems;
  30.     #[ORM\Column(length255)]
  31.     private ?string $type null;
  32.     #[ORM\Column(length255)]
  33.     private ?string $target null;
  34.     public function __construct()
  35.     {
  36.         parent::__construct();
  37.         $this->menuItems = new ArrayCollection();
  38.     }
  39.     public function getId(): ?string
  40.     {
  41.         return $this->id;
  42.     }
  43.     public function getLabel(): ?string
  44.     {
  45.         return $this->label;
  46.     }
  47.     public function setLabel(string $label): static
  48.     {
  49.         $this->label $label;
  50.         return $this;
  51.     }
  52.     public function getUrl(): ?string
  53.     {
  54.         return $this->url;
  55.     }
  56.     public function setUrl(?string $url): static
  57.     {
  58.         $this->url $url;
  59.         return $this;
  60.     }
  61.     public function getMenuItemOrder(): ?int
  62.     {
  63.         return $this->menuItemOrder;
  64.     }
  65.     public function setMenuItemOrder(?int $menuItemOrder): static
  66.     {
  67.         $this->menuItemOrder $menuItemOrder;
  68.         return $this;
  69.     }
  70.     public function getMenu(): ?Menu
  71.     {
  72.         return $this->menu;
  73.     }
  74.     public function setMenu(?Menu $menu): static
  75.     {
  76.         $this->menu $menu;
  77.         return $this;
  78.     }
  79.     public function getParent(): ?self
  80.     {
  81.         return $this->parent;
  82.     }
  83.     public function setParent(?self $parent): static
  84.     {
  85.         $this->parent $parent;
  86.         return $this;
  87.     }
  88.     /**
  89.      * @return Collection<int, self>
  90.      */
  91.     public function getMenuItems(): Collection
  92.     {
  93.         return $this->menuItems;
  94.     }
  95.     public function addMenuItem(self $menuItem): static
  96.     {
  97.         if (!$this->menuItems->contains($menuItem)) {
  98.             $this->menuItems->add($menuItem);
  99.             $menuItem->setParent($this);
  100.         }
  101.         return $this;
  102.     }
  103.     public function removeMenuItem(self $menuItem): static
  104.     {
  105.         if ($this->menuItems->removeElement($menuItem)) {
  106.             // set the owning side to null (unless already changed)
  107.             if ($menuItem->getParent() === $this) {
  108.                 $menuItem->setParent(null);
  109.             }
  110.         }
  111.         return $this;
  112.     }
  113.     public function getType(): ?string
  114.     {
  115.         return $this->type;
  116.     }
  117.     public function setType(string $type): static
  118.     {
  119.         $this->type $type;
  120.         return $this;
  121.     }
  122.     public function getTarget(): ?string
  123.     {
  124.         return $this->target;
  125.     }
  126.     public function setTarget$target): static
  127.     {
  128.         switch (true) {
  129.             case $target instanceof \App\Entity\Shop\Product\Product:
  130.                $this->target $target->getId();
  131.                 break;
  132.             case $target instanceof \App\Entity\Shop\Product\ProductCategory:
  133.                 $this->target $target->getId();
  134.                 break;
  135.             case $target instanceof \App\Entity\Shop\Page\Page:
  136.                 $this->target $target->getId();
  137.                 break;
  138.             default:
  139.                 $this->target $target;
  140.                 // حالت پیش‌فرض
  141.         }
  142.         return $this;
  143.     }
  144. }