summaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/model')
-rw-r--r--src/model/Position.php31
-rw-r--r--src/model/entities/Page.php8
2 files changed, 12 insertions, 27 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
8trait Position 8trait 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
diff --git a/src/model/entities/Page.php b/src/model/entities/Page.php
index aaff1ff..9564342 100644
--- a/src/model/entities/Page.php
+++ b/src/model/entities/Page.php
@@ -135,11 +135,9 @@ class Page
135 } 135 }
136 public function removeChild(self $child): void 136 public function removeChild(self $child): void
137 { 137 {
138 foreach($this->children as $index => $candidate){ 138 $this->children->removeElement($child);
139 if($candidate === $child){ 139 $this->children = new ArrayCollection(array_values($this->children->toArray())); // réindexer en passant par un tableau
140 unset($this->children[$index]); 140 $this->sortChildren(false);
141 }
142 }
143 } 141 }
144 142
145 public function findPageById(int $id): ?Page 143 public function findPageById(int $id): ?Page