From eb3e1eb8c8365d3b3d1d39f24314ba420255afc2 Mon Sep 17 00:00:00 2001 From: polo Date: Mon, 21 Apr 2025 20:36:10 +0200 Subject: page menu et chemin, partie1 --- src/model/Position.php | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 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..74d173a --- /dev/null +++ b/src/model/Position.php @@ -0,0 +1,63 @@ +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; + } + + foreach ($this->children as $child) { + if (count($child->children) > 0) { + $child->sortChildren($reposition); + } + } + + // nouvelles positions (tableau $children => BDD) + if($reposition){ + $i = 1; + foreach($this->children as $child){ + $child->setPosition($i); + $i++; + } + } + } + + /*private function sortChildren(): 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--; + } + }*/ +} \ No newline at end of file -- cgit v1.2.3