children = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getMenu(): ?Menu { return $this->menu; } public function setMenu(?Menu $menu): self { $this->menu = $menu; return $this; } public function getTreeLeft(): ?int { return $this->treeLeft; } public function setTreeLeft(int $treeLeft): self { $this->treeLeft = $treeLeft; return $this; } public function getTreeLevel(): ?int { return $this->treeLevel; } public function setTreeLevel(int $treeLevel): self { $this->treeLevel = $treeLevel; return $this; } public function getTreeRight(): ?int { return $this->treeRight; } public function setTreeRight(int $treeRight): self { $this->treeRight = $treeRight; return $this; } public function getTreeRoot(): ?self { return $this->treeRoot; } public function setTreeRoot(?self $treeRoot): self { $this->treeRoot = $treeRoot; return $this; } public function getParent(): ?self { return $this->parent; } public function setParent(?self $parent): self { $this->parent = $parent; return $this; } /** * @return Collection|Node[] */ public function getChildren(): Collection { return $this->children; } public function addChild(Node $child): self { if (!$this->children->contains($child)) { $this->children[] = $child; $child->setParent($this); } return $this; } public function removeChild(Node $child): self { if ($this->children->removeElement($child)) { // set the owning side to null (unless already changed) if ($child->getParent() === $this) { $child->setParent(null); } } return $this; } public function getAllChildren(): ArrayCollection { $children = []; $getChildren = function (Node $node) use (&$children, &$getChildren) { foreach ($node->getChildren() as $nodeChildren) { $children[] = $nodeChildren; $getChildren($nodeChildren); } }; $getChildren($this); usort($children, function ($a, $b) { return $a->getTreeLeft() < $b->getTreeLeft() ? -1 : 1; }); return new ArrayCollection($children); } public function getLabel(): ?string { return $this->label; } public function setLabel(?string $label): self { $this->label = $label; return $this; } public function getUrl(): ?string { return $this->url; } public function setUrl(?string $url): self { $this->url = $url; return $this; } public function getIsVisible(): ?bool { return $this->isVisible; } public function setIsVisible(bool $isVisible): self { $this->isVisible = $isVisible; return $this; } public function getTreeLabel() { $prefix = str_repeat('-', ($this->getTreeLevel() - 1) * 5); return trim($prefix.' '.$this->getLabel()); } }