diff options
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/Position.php | 22 | ||||
-rw-r--r-- | src/model/entities/Page.php | 16 |
2 files changed, 25 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 | ||
8 | trait Position | 8 | trait 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); |
diff --git a/src/model/entities/Page.php b/src/model/entities/Page.php index e3e60ca..aaff1ff 100644 --- a/src/model/entities/Page.php +++ b/src/model/entities/Page.php | |||
@@ -75,6 +75,10 @@ class Page | |||
75 | { | 75 | { |
76 | return $this->page_path; | 76 | return $this->page_path; |
77 | } | 77 | } |
78 | public function setPagePath(string $path):void | ||
79 | { | ||
80 | $this->page_path = $path; | ||
81 | } | ||
78 | public function getEndOfPath(): string | 82 | public function getEndOfPath(): string |
79 | { | 83 | { |
80 | return $this->end_of_path; | 84 | return $this->end_of_path; |
@@ -107,6 +111,10 @@ class Page | |||
107 | { | 111 | { |
108 | return $this->parent; | 112 | return $this->parent; |
109 | } | 113 | } |
114 | public function setParent(?Page $parent): void | ||
115 | { | ||
116 | $this->parent = $parent; | ||
117 | } | ||
110 | public function getChildren(): Collection | 118 | public function getChildren(): Collection |
111 | { | 119 | { |
112 | return $this->children; | 120 | return $this->children; |
@@ -125,6 +133,14 @@ class Page | |||
125 | $this->children[] = $child; | 133 | $this->children[] = $child; |
126 | $this->sortChildren(false); | 134 | $this->sortChildren(false); |
127 | } | 135 | } |
136 | public function removeChild(self $child): void | ||
137 | { | ||
138 | foreach($this->children as $index => $candidate){ | ||
139 | if($candidate === $child){ | ||
140 | unset($this->children[$index]); | ||
141 | } | ||
142 | } | ||
143 | } | ||
128 | 144 | ||
129 | public function findPageById(int $id): ?Page | 145 | public function findPageById(int $id): ?Page |
130 | { | 146 | { |