name_page = $name; $this->end_of_path = $eop; $this->reachable = $reachable; $this->in_menu = $in_menu; $this->position = $position; $this->parent = $parent; $this->children = new ArrayCollection(); } // getters /*public function getId(): int { return $this->id_page; }*/ public function getPageName(): string { return $this->name_page; } public function getPagePath(): string { return $this->page_path; } public function getEndOfPath(): string { return $this->end_of_path; } public function getInMenu(): bool { return $this->in_menu; } public function getPosition(): ?int { return $this->position; } public function getParent(): ?Page { return $this->parent; } public function getChildren(): Collection { return $this->children; } public function fillChildrenPagePath(string $parent_path = ''): void { $this->page_path = $parent_path != '' ? $parent_path . '/' . $this->end_of_path : $this->end_of_path; foreach($this->getChildren() as $page){ $page->fillChildrenPagePath($this->page_path); } } public function addChild(self $child): void { $this->children[] = $child; $this->sortChildren(); } // utiliser $position pour afficher les éléments dans l'ordre private function sortChildren(): void { $iteration = count($this->children); while($iteration > 1) { for($i = 0; $i < $iteration - 1; $i++) { //echo '
' . $this->children[$i]->getPosition() . ' - ' . $this->children[$i + 1]->getPosition(); if($this->children[$i]->getPosition() > $this->children[$i + 1]->getPosition()) { $tmp = $this->children[$i]; $this->children[$i] = $this->children[$i + 1]; $this->children[$i + 1] = $tmp; } } $iteration--; } } }