summaryrefslogtreecommitdiff
path: root/src/model/Position.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/model/Position.php')
-rw-r--r--src/model/Position.php22
1 files changed, 9 insertions, 13 deletions
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);
7 7
8trait Position 8trait Position
9{ 9{
10 public function sortChildren(bool $reposition = false): void 10 public function sortChildren(bool $reindexation = false): void
11 { 11 {
12 // ordre du tableau des enfants 12 // tri par insertion du tableau des enfants
13 // inefficace quand des noeuds ont la même position
14
15 // tri par insertion avant affichage
16 for($i = 1; $i < count($this->children); $i++) 13 for($i = 1; $i < count($this->children); $i++)
17 { 14 {
18 $tmp = $this->children[$i]; 15 $tmp = $this->children[$i];
19 $j = $i - 1; 16 $j = $i - 1;
20 17
21 // Déplacez les éléments du tableau qui sont plus grands que la clé 18 // Déplacez les éléments du tableau qui sont plus grands que la clé à une position devant leur position actuelle
22 // à une position devant leur position actuelle 19 while($j >= 0 && $this->children[$j]->getPosition() > $tmp->getPosition()) {
23 while ($j >= 0 && $this->children[$j]->getPosition() > $tmp->getPosition()) {
24 $this->children[$j + 1] = $this->children[$j]; 20 $this->children[$j + 1] = $this->children[$j];
25 $j = $j - 1; 21 $j--;
26 } 22 }
27 $this->children[$j + 1] = $tmp; 23 $this->children[$j + 1] = $tmp;
28 } 24 }
29 25
30 foreach ($this->children as $child) { 26 foreach($this->children as $child) {
31 if (count($child->children) > 0) { 27 if(count($child->children) > 0) {
32 $child->sortChildren($reposition); 28 $child->sortChildren($reindexation);
33 } 29 }
34 } 30 }
35 31
36 // nouvelles positions (tableau $children => BDD) 32 // nouvelles positions (tableau $children => BDD)
37 if($reposition){ 33 if($reindexation){
38 $i = 1; 34 $i = 1;
39 foreach($this->children as $child){ 35 foreach($this->children as $child){
40 $child->setPosition($i); 36 $child->setPosition($i);