src/CmsBundle/Entity/MenuItem.php line 22

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_item",
  9.  *     indexes={
  10.  *         @ORM\Index(name="menu_menu_index", columns={"menu_id"}),
  11.  *         @ORM\Index(name="menu_parent_index", columns={"parent_id"}),
  12.  *         @ORM\Index(name="menu_item_level_index", columns={"level"}),
  13.  *         @ORM\Index(name="menu_item_published_index", columns={"published"})
  14.  *     }
  15.  * )
  16.  * @ORM\Entity(repositoryClass="App\CmsBundle\Repository\MenuItemRepository")
  17.  * @ORM\HasLifecycleCallbacks()
  18.  */
  19. class MenuItem
  20. {
  21.     use IdTraitTitleTraitTimeStampedTraitPositionTraitPublishedTrait;
  22.     /**
  23.      * @var string
  24.      *
  25.      * @ORM\Column(
  26.      *     name="title",
  27.      *     type="string",
  28.      *     length=255,
  29.      *     nullable=false
  30.      *     )
  31.      */
  32.     private $title;
  33.     /**
  34.      * @var string
  35.      *
  36.      * @ORM\Column(
  37.      *     name="subtitle",
  38.      *     type="string",
  39.      *     length=255,
  40.      *     nullable=true
  41.      *     )
  42.      */
  43.     private $subtitle;
  44.     /**
  45.      * @ORM\Column(type="string", length=255, nullable=true)
  46.      */
  47.     private $path;
  48.     /**
  49.      * @ORM\Column(type="integer")
  50.      */
  51.     private $level;
  52.     /**
  53.      * @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\Menu", inversedBy="menuItems")
  54.      * @ORM\JoinColumn(nullable=false)
  55.      */
  56.     private $menu;
  57.     /**
  58.      * @ORM\Column(type="integer", nullable=true)
  59.      */
  60.     private $target;
  61.     /**
  62.      * @ORM\Column(type="text", nullable=true)
  63.      */
  64.     private $additional;
  65.     /**
  66.      * @ORM\Column(type="text", nullable=true)
  67.      */
  68.     private $icon;
  69.     /**
  70.      * @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\MenuItem", inversedBy="childs" )
  71.      */
  72.     private $parent;
  73.     /**
  74.      * @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\MenuItem", mappedBy="parent", orphanRemoval=true, fetch="EAGER")
  75.      */
  76.     private $childs;
  77.     /**
  78.      * @ORM\Column(type="boolean", nullable=false, options={"default" : false})
  79.      */
  80.     private $isMostPopular;
  81.     public function __construct()
  82.     {
  83.         $this->childs = new ArrayCollection();
  84.         $this->level 0;
  85.         $this->hidden false;
  86.     }
  87.     public function __toString(): string
  88.     {
  89.         return $this->title;
  90.     }
  91.     public function getSubtitle(): ?string
  92.     {
  93.         return $this->subtitle;
  94.     }
  95.     public function setSubtitle(?string $subtitle): self
  96.     {
  97.         $this->subtitle $subtitle;
  98.         return $this;
  99.     }
  100.     public function getIcon(): ?string
  101.     {
  102.         return $this->icon;
  103.     }
  104.     public function setIcon(?string $icon): self
  105.     {
  106.         $this->icon $icon;
  107.         return $this;
  108.     }
  109.     public function getMenu(): ?Menu
  110.     {
  111.         return $this->menu;
  112.     }
  113.     public function setMenu(?Menu $menu): self
  114.     {
  115.         $this->menu $menu;
  116.         return $this;
  117.     }
  118.     public function getPath(): ?string
  119.     {
  120.         return $this->path;
  121.     }
  122.     public function setPath(?string $path): self
  123.     {
  124.         $this->path $path;
  125.         return $this;
  126.     }
  127.     public function getAdditional(): ?string
  128.     {
  129.         return $this->additional;
  130.     }
  131.     public function setAdditional(?string $additional): self
  132.     {
  133.         $this->additional $additional;
  134.         return $this;
  135.     }
  136.     public function getTarget(): ?int
  137.     {
  138.         return $this->target;
  139.     }
  140.     public function setTarget(?int $target): self
  141.     {
  142.         $this->target $target;
  143.         return $this;
  144.     }
  145.     public function getParent(): ?self
  146.     {
  147.         return $this->parent;
  148.     }
  149.     public function setParent(?self $parent): self
  150.     {
  151.         $this->parent $parent;
  152.         $this->level++;
  153.         if ($parent) {
  154.             while ($parent $parent->getParent()) {
  155.                 $this->level++;
  156.             }
  157.         }
  158.         return $this;
  159.     }
  160.     /**
  161.      * @return Collection|self[]
  162.      */
  163.     public function getChilds(): Collection
  164.     {
  165.         return $this->childs;
  166.     }
  167.     public function addChild(self $child): self
  168.     {
  169.         if (!$this->childs->contains($child)) {
  170.             $this->childs[] = $child;
  171.             $child->setParent($this);
  172.         }
  173.         return $this;
  174.     }
  175.     public function removeChild(self $child): self
  176.     {
  177.         if ($this->childs->contains($child)) {
  178.             $this->childs->removeElement($child);
  179.             // set the owning side to null (unless already changed)
  180.             if ($child->getParent() === $this) {
  181.                 $child->setParent(null);
  182.             }
  183.         }
  184.         return $this;
  185.     }
  186.     public function relationTitle(): string
  187.     {
  188.         $title $this->getTitle();
  189.         $parent $this;
  190.         while ($parent $parent->getParent()) {
  191.             $title $parent->getTitle() . ' > ' $title;
  192.         }
  193.         return $title;
  194.     }
  195.     public function getIsMostPopular(): ?bool
  196.     {
  197.         return $this->isMostPopular;
  198.     }
  199.     public function setIsMostPopular(?bool $isMostPopular): self
  200.     {
  201.         $this->isMostPopular $isMostPopular;
  202.         return $this;
  203.     }
  204. }