diff options
Diffstat (limited to 'src/model/entities/Node.php')
-rw-r--r-- | src/model/entities/Node.php | 33 |
1 files changed, 3 insertions, 30 deletions
diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php index a52a7e6..103163b 100644 --- a/src/model/entities/Node.php +++ b/src/model/entities/Node.php | |||
@@ -12,6 +12,8 @@ use Doctrine\ORM\Mapping as ORM; | |||
12 | #[ORM\Table(name: TABLE_PREFIX . "node")] | 12 | #[ORM\Table(name: TABLE_PREFIX . "node")] |
13 | class Node | 13 | class Node |
14 | { | 14 | { |
15 | use \Position; | ||
16 | |||
15 | #[ORM\Id] | 17 | #[ORM\Id] |
16 | #[ORM\GeneratedValue] | 18 | #[ORM\GeneratedValue] |
17 | #[ORM\Column(type: "integer")] | 19 | #[ORM\Column(type: "integer")] |
@@ -135,36 +137,7 @@ class Node | |||
135 | $this->children[] = $child; | 137 | $this->children[] = $child; |
136 | $this->sortChildren(false); | 138 | $this->sortChildren(false); |
137 | } | 139 | } |
138 | // utiliser $position pour afficher les éléments dans l'ordre | 140 | |
139 | public function sortChildren(bool $reposition = false): void | ||
140 | { | ||
141 | // ordre du tableau des enfants | ||
142 | // inefficace quand des noeuds ont la même position | ||
143 | |||
144 | // tri par insertion | ||
145 | for($i = 1; $i < count($this->children); $i++) | ||
146 | { | ||
147 | $tmp = $this->children[$i]; | ||
148 | $j = $i - 1; | ||
149 | |||
150 | // Déplacez les éléments du tableau qui sont plus grands que la clé | ||
151 | // à une position devant leur position actuelle | ||
152 | while ($j >= 0 && $this->children[$j]->getPosition() > $tmp->getPosition()) { | ||
153 | $this->children[$j + 1] = $this->children[$j]; | ||
154 | $j = $j - 1; | ||
155 | } | ||
156 | $this->children[$j + 1] = $tmp; | ||
157 | } | ||
158 | |||
159 | // nouvelles positions | ||
160 | if($reposition){ | ||
161 | $i = 1; | ||
162 | foreach($this->children as $child){ | ||
163 | $child->setPosition($i); | ||
164 | $i++; | ||
165 | } | ||
166 | } | ||
167 | } | ||
168 | public function removeChild(self $child): void | 141 | public function removeChild(self $child): void |
169 | { | 142 | { |
170 | foreach($this->children as $key => $object){ | 143 | foreach($this->children as $key => $object){ |