From 2d8ec75f4aaf3b93fd9f6758f8dcb4f1f9f03d0c Mon Sep 17 00:00:00 2001 From: polo Date: Wed, 7 May 2025 01:11:27 +0200 Subject: page menu et chemins, partie5 --- src/model/Position.php | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'src/model/Position.php') diff --git a/src/model/Position.php b/src/model/Position.php index 76de966..b5040df 100644 --- a/src/model/Position.php +++ b/src/model/Position.php @@ -7,9 +7,9 @@ declare(strict_types=1); trait Position { + // tri par insertion du tableau des enfants public function sortChildren(bool $reindexation = false): void { - // tri par insertion du tableau des enfants for($i = 1; $i < count($this->children); $i++) { $tmp = $this->children[$i]; @@ -29,31 +29,18 @@ trait Position } } - // nouvelles positions (tableau $children => BDD) if($reindexation){ - $i = 1; - foreach($this->children as $child){ - $child->setPosition($i); - $i++; - } + $this->reindex(); } } - /*private function sortChildren(): void + // nouvelles positions (tableau $children => BDD) + public function reindex(): void { - $iteration = count($this->children); - while($iteration > 1) - { - for($i = 0; $i < $iteration - 1; $i++) - { - 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--; + $i = 1; + foreach($this->children as $child){ + $child->setPosition($i); + $i++; } - }*/ + } } \ No newline at end of file -- cgit v1.2.3