From f27cca08ff786ceff1870147f6d6bad14d71117f Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 23 Oct 2026 00:47:32 +0200 Subject: =?UTF-8?q?dossiers=20avec=20majuscule,=20namespace=20pour=20toute?= =?UTF-8?q?s=20les=20classes,=20autoload=20psr-4,=20UserDataService::creat?= =?UTF-8?q?eZip=20d=C3=A9plac=C3=A9=20dans=20Backup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Model/Position.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/Model/Position.php (limited to 'src/Model/Position.php') diff --git a/src/Model/Position.php b/src/Model/Position.php new file mode 100644 index 0000000..7799cdf --- /dev/null +++ b/src/Model/Position.php @@ -0,0 +1,52 @@ +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--; + } + $this->children[$j + 1] = $tmp; + } + + // récursivité (utile dans Menu et chemin) + // appel dans Page et dans MenuAndPathController (un tri supplémentaire à faire?) + if(self::class === 'App\Entity\Page'){ + foreach($this->children as $child) { + if(count($child->children) > 0) { + $child->sortChildren($reindexation); + } + } + } + + if($reindexation){ + $this->reindexPositions(); + } + } + + // nouvelles positions (tableau $children => BDD) + public function reindexPositions(): void + { + $i = 1; + foreach($this->children as $child){ + $child->setPosition($i); + $i++; + } + } +} \ No newline at end of file -- cgit v1.2.3