name_node = $name; $this->article_timestamp = $article_timestamp; $this->attributes = $attributes; $this->position = $position; $this->parent = $parent; $this->page = $page; $this->article = $article; } // pfff... public function getId(): int { return $this->id_node; } public function getName(): string { return $this->name_node; } /*public function setName(string $name): void { $this->name_node = $name; }*/ public function getArticleTimestamp(): string { return $this->article_timestamp; } public function getAttributes(): array { return $this->attributes; } /*public function setAttributes(array $attributes): void { $this->attributes = $attributes; }*/ public function getParent(): ?self { return $this->parent; } /*public function setParent(?self $parent): void { $this->parent = $parent; }*/ public function getPosition(): int { return $this->position; } public function setPosition(int $position): void { $this->position = $position; } public function getPage(): Page { return $this->page; } /*public function setPage(Page $page): void { $this->page = $page; }*/ public function getArticle(): Article { return $this->article; } /*public function setArticle(Article $article): void { $this->article = $article; }*/ public function getNodeData(): ?NodeData { return $this->node_data; } public function getChildren(): array { return $this->children; } public function addChild(self $child): void { $this->children[] = $child; $this->sortChildren(false); } // utiliser $position pour afficher les éléments dans l'ordre public function sortChildren(bool $reposition = false): void { // ordre du tableau des enfants // inefficace quand des noeuds ont la même position // tri par insertion for($i = 1; $i < count($this->children); $i++) { $tmp = $this->children[$i]; $j = $i - 1; // Déplacez les éléments du tableau qui sont plus grands que la clé // à une position devant leur position actuelle while ($j >= 0 && $this->children[$j]->getPosition() > $tmp->getPosition()) { $this->children[$j + 1] = $this->children[$j]; $j = $j - 1; } $this->children[$j + 1] = $tmp; } // nouvelles positions if($reposition){ $i = 1; foreach($this->children as $child){ $child->setPosition($i); $i++; } } } public function removeChild(self $child): void { foreach($this->children as $key => $object){ if($object->getId() === $child->getId()){ unset($this->children[$key]); } break; } $this->children = array_values($this->children); // réindexer pour supprimer la case vide } public function getTempChild(): ?self // peut renvoyer null { return $this->temp_child; } public function setTempChild(self $child): void { $this->temp_child = $child; } }