diff options
author | polo <ordipolo@gmx.fr> | 2025-05-07 01:11:27 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2025-05-07 01:11:27 +0200 |
commit | 2d8ec75f4aaf3b93fd9f6758f8dcb4f1f9f03d0c (patch) | |
tree | dfa6f5e31ed96f9ddcf9238304364e7887c26a7d /src/model/Position.php | |
parent | 5fc1a655e0271b583f3caa009524ea9d99a8bd3e (diff) | |
download | cms-2d8ec75f4aaf3b93fd9f6758f8dcb4f1f9f03d0c.zip |
page menu et chemins, partie5
Diffstat (limited to 'src/model/Position.php')
-rw-r--r-- | src/model/Position.php | 31 |
1 files changed, 9 insertions, 22 deletions
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); | |||
7 | 7 | ||
8 | trait Position | 8 | trait Position |
9 | { | 9 | { |
10 | // tri par insertion du tableau des enfants | ||
10 | public function sortChildren(bool $reindexation = false): void | 11 | public function sortChildren(bool $reindexation = false): void |
11 | { | 12 | { |
12 | // tri par insertion du tableau des enfants | ||
13 | for($i = 1; $i < count($this->children); $i++) | 13 | for($i = 1; $i < count($this->children); $i++) |
14 | { | 14 | { |
15 | $tmp = $this->children[$i]; | 15 | $tmp = $this->children[$i]; |
@@ -29,31 +29,18 @@ trait Position | |||
29 | } | 29 | } |
30 | } | 30 | } |
31 | 31 | ||
32 | // nouvelles positions (tableau $children => BDD) | ||
33 | if($reindexation){ | 32 | if($reindexation){ |
34 | $i = 1; | 33 | $this->reindex(); |
35 | foreach($this->children as $child){ | ||
36 | $child->setPosition($i); | ||
37 | $i++; | ||
38 | } | ||
39 | } | 34 | } |
40 | } | 35 | } |
41 | 36 | ||
42 | /*private function sortChildren(): void | 37 | // nouvelles positions (tableau $children => BDD) |
38 | public function reindex(): void | ||
43 | { | 39 | { |
44 | $iteration = count($this->children); | 40 | $i = 1; |
45 | while($iteration > 1) | 41 | foreach($this->children as $child){ |
46 | { | 42 | $child->setPosition($i); |
47 | for($i = 0; $i < $iteration - 1; $i++) | 43 | $i++; |
48 | { | ||
49 | if($this->children[$i]->getPosition() > $this->children[$i + 1]->getPosition()) | ||
50 | { | ||
51 | $tmp = $this->children[$i]; | ||
52 | $this->children[$i] = $this->children[$i + 1]; | ||
53 | $this->children[$i + 1] = $tmp; | ||
54 | } | ||
55 | } | ||
56 | $iteration--; | ||
57 | } | 44 | } |
58 | }*/ | 45 | } |
59 | } \ No newline at end of file | 46 | } \ No newline at end of file |