From 962d315ec0c99974df3dc2261bf94c54ca8cdbdd Mon Sep 17 00:00:00 2001 From: polo Date: Sun, 27 Apr 2025 23:58:46 +0200 Subject: page menu et chemins, partie3 --- src/model/Position.php | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/model/Position.php') diff --git a/src/model/Position.php b/src/model/Position.php index 74d173a..76de966 100644 --- a/src/model/Position.php +++ b/src/model/Position.php @@ -7,34 +7,30 @@ declare(strict_types=1); trait Position { - public function sortChildren(bool $reposition = false): void + public function sortChildren(bool $reindexation = false): void { - // ordre du tableau des enfants - // inefficace quand des noeuds ont la même position - - // tri par insertion avant affichage + // tri par insertion du tableau des enfants 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()) { + // 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; + $j--; } $this->children[$j + 1] = $tmp; } - foreach ($this->children as $child) { - if (count($child->children) > 0) { - $child->sortChildren($reposition); + foreach($this->children as $child) { + if(count($child->children) > 0) { + $child->sortChildren($reindexation); } } // nouvelles positions (tableau $children => BDD) - if($reposition){ + if($reindexation){ $i = 1; foreach($this->children as $child){ $child->setPosition($i); -- cgit v1.2.3