children = new ArrayCollection(); $this->aliasNodes = 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 { if (null === $this->children) { $this->children = new ArrayCollection(); } 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 hasExternalUrl(): bool { $string = u($this->getUrl()); return $string->startsWith('http://') || $string->startsWith('https://'); } public function getIsVisible(): ?bool { return $this->isVisible; } public function setIsVisible(bool $isVisible): self { $this->isVisible = $isVisible; return $this; } public function getDisableUrl(): ?bool { return $this->disableUrl; } public function setDisableUrl(bool $disableUrl): self { $this->disableUrl = $disableUrl; return $this; } public function getTreeLabel() { $prefix = str_repeat('-', ($this->getTreeLevel() - 1) * 5); return trim($prefix.' '.$this->getLabel()); } public function getPage(): ?Page { if ($this->getAliasNode()) { return $this->getAliasNode()->getPage(); } return $this->page; } public function setPage(?Page $page): self { $this->page = $page; return $this; } public function getRouteName(): string { if ($this->getAliasNode()) { return $this->getAliasNode()->getRouteName(); } return $this->getMenu()->getRouteName().'_'.($this->getCode() ? $this->getCode() : $this->getId()); } public function getCode(): ?string { if ($this->getAliasNode()) { return $this->getAliasNode()->getCode(); } return $this->code; } public function setCode(?string $code): self { $this->code = $code; return $this; } public function getParameters(): ?array { if ($this->getAliasNode()) { return $this->getAliasNode()->getParameters(); } if (!is_array($this->parameters)) { $this->parameters = []; } return $this->parameters; } public function setParameters(array $parameters): self { $this->parameters = $parameters; return $this; } public function getAttributes(): ?array { if (!is_array($this->attributes)) { $this->attributes = []; } return $this->attributes; } public function setAttributes(array $attributes): self { $this->attributes = $attributes; return $this; } public function getController(): ?string { if ($this->getAliasNode()) { return $this->getAliasNode()->getController(); } return $this->controller; } public function setController(?string $controller): self { $this->controller = $controller; return $this; } public function getSitemapParameters(): ?array { if ($this->getAliasNode()) { return $this->getAliasNode()->getSitemapParameters(); } if (!is_array($this->sitemapParameters)) { $this->sitemapParameters = [ 'isVisible' => false, 'priority' => 0, 'changeFrequency' => 'daily', ]; } return $this->sitemapParameters; } public function setSitemapParameters(?array $sitemapParameters): self { $this->sitemapParameters = $sitemapParameters; return $this; } public function getAliasNode(): ?self { return $this->aliasNode; } public function setAliasNode(?self $aliasNode): self { $this->aliasNode = $aliasNode; return $this; } /** * @return Collection|self[] */ public function getAliasNodes(): Collection { return $this->aliasNodes; } public function addAliasNode(self $aliasNode): self { if (!$this->aliasNodes->contains($aliasNode)) { $this->aliasNodes[] = $aliasNode; $aliasNode->setAliasNode($this); } return $this; } public function removeAliasNode(self $aliasNode): self { if ($this->aliasNodes->removeElement($aliasNode)) { // set the owning side to null (unless already changed) if ($aliasNode->getAliasNode() === $this) { $aliasNode->setAliasNode(null); } } return $this; } public function getContentType(): ?string { return $this->contentType; } public function setContentType(?string $contentType): self { $this->contentType = $contentType; return $this; } }