src/Entity/MenuItem.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity
  8.  * @ORM\Table(name="menu_items")
  9.  */
  10. class MenuItem
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $title;
  22.     /**
  23.      * @ORM\Column(type="string", length=255, nullable=true)
  24.      */
  25.     private $url;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity=Menu::class, inversedBy="menuItems")
  28.      */
  29.     private $menu;
  30.     /**
  31.      * @ORM\Column(type="string", length=255)
  32.      */
  33.     private $contentType// 'External', 'Page', 'Brand', etc.
  34.     /**
  35.      * @ORM\ManyToMany(targetEntity=Marque::class)
  36.      * @ORM\JoinTable(name="menu_item_marques")
  37.      */
  38.     private $marques;
  39.     /**
  40.      * @ORM\ManyToOne(targetEntity=MenuItem::class, inversedBy="children")
  41.      */
  42.     private $parent;
  43.     /**
  44.      * @ORM\OneToMany(targetEntity=MenuItem::class, mappedBy="parent")
  45.      */
  46.     private $children;
  47.     public function __construct()
  48.     {
  49.         $this->children = new ArrayCollection();
  50.         $this->marques = new ArrayCollection();
  51.     }
  52.     public function getParent(): ?self
  53.     {
  54.         return $this->parent;
  55.     }
  56.     public function setParent(?self $parent): self
  57.     {
  58.         $this->parent $parent;
  59.         return $this;
  60.     }
  61.     /**
  62.      * @return Collection|self[]
  63.      */
  64.     public function getChildren(): Collection
  65.     {
  66.         return $this->children;
  67.     }
  68.     public function addChild(self $child): self
  69.     {
  70.         if (!$this->children->contains($child)) {
  71.             $this->children[] = $child;
  72.             $child->setParent($this);
  73.         }
  74.         return $this;
  75.     }
  76.     public function removeChild(self $child): self
  77.     {
  78.         if ($this->children->removeElement($child)) {
  79.             // set the owning side to null (unless already changed)
  80.             if ($child->getParent() === $this) {
  81.                 $child->setParent(null);
  82.             }
  83.         }
  84.         return $this;
  85.     }
  86.     /**
  87.      * @return Collection|Marque[]
  88.      */
  89.     public function getMarques(): Collection
  90.     {
  91.         return $this->marques;
  92.     }
  93.     public function addMarque(Marque $marque): self
  94.     {
  95.         if (!$this->marques->contains($marque)) {
  96.             $this->marques[] = $marque;
  97.         }
  98.         return $this;
  99.     }
  100.     public function removeMarque(Marque $marque): self
  101.     {
  102.         $this->marques->removeElement($marque);
  103.         return $this;
  104.     }
  105. }