src/CmsBundle/Entity/Menu.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\CmsBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Table(
  8.  *     name="menu",
  9.  *     indexes={
  10.  *         @ORM\Index(name="menu_site_index", columns={"site_id"})
  11.  *     }
  12.  * )
  13.  * @ORM\Entity(repositoryClass="App\CmsBundle\Repository\MenuRepository")
  14.  * @ORM\HasLifecycleCallbacks()
  15.  */
  16. class Menu
  17. {
  18.     use IdTraitTitleTraitTimeStampedTrait;
  19.     /**
  20.      * @ORM\Column(type="string", length=255, nullable=false)
  21.      */
  22.     private $title;
  23.     /**
  24.      * @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\Site", inversedBy="menus")
  25.      * @ORM\JoinColumn(nullable=false)
  26.      */
  27.     private $site;
  28.     /**
  29.      * @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\MenuItem", mappedBy="menu", orphanRemoval=true, cascade={"persist", "remove"})
  30.      */
  31.     private $menuItems;
  32.     public function __construct()
  33.     {
  34.         $this->menuItems = new ArrayCollection();
  35.     }
  36.     public function __toString()
  37.     {
  38.         return $this->getSite()->getTitle().' - '.$this->title;
  39.     }
  40.     public function getId(): ?int
  41.     {
  42.         return $this->id;
  43.     }
  44.     public function getTitle(): ?string
  45.     {
  46.         return $this->title;
  47.     }
  48.     public function setTitle(string $title): self
  49.     {
  50.         $this->title $title;
  51.         return $this;
  52.     }
  53.     public function getSite(): ?Site
  54.     {
  55.         return $this->site;
  56.     }
  57.     public function setSite(?Site $site): self
  58.     {
  59.         $this->site $site;
  60.         return $this;
  61.     }
  62.     /**
  63.      * @return Collection|MenuItem[]
  64.      */
  65.     public function getMenuItems(): Collection
  66.     {
  67.         return $this->menuItems;
  68.     }
  69.     public function addMenuItem(MenuItem $menuItem): self
  70.     {
  71.         if (!$this->menuItems->contains($menuItem)) {
  72.             $this->menuItems[] = $menuItem;
  73.             $menuItem->setMenu($this);
  74.         }
  75.         return $this;
  76.     }
  77.     public function removeMenuItem(MenuItem $menuItem): self
  78.     {
  79.         if ($this->menuItems->contains($menuItem)) {
  80.             $this->menuItems->removeElement($menuItem);
  81.             // set the owning side to null (unless already changed)
  82.             if ($menuItem->getMenu() === $this) {
  83.                 $menuItem->setMenu(null);
  84.             }
  85.         }
  86.         return $this;
  87.     }
  88. }