blob: 74d173a184b96fdb5f96f85d4a3084e78957357f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
<?php
// src/modele/Position.php
//
// pour Node et Page
declare(strict_types=1);
trait Position
{
public function sortChildren(bool $reposition = false): void
{
// ordre du tableau des enfants
// inefficace quand des noeuds ont la même position
// tri par insertion avant affichage
for($i = 1; $i < count($this->children); $i++)
{
$tmp = $this->children[$i];
$j = $i - 1;
// Déplacez les éléments du tableau qui sont plus grands que la clé
// à une position devant leur position actuelle
while ($j >= 0 && $this->children[$j]->getPosition() > $tmp->getPosition()) {
$this->children[$j + 1] = $this->children[$j];
$j = $j - 1;
}
$this->children[$j + 1] = $tmp;
}
foreach ($this->children as $child) {
if (count($child->children) > 0) {
$child->sortChildren($reposition);
}
}
// nouvelles positions (tableau $children => BDD)
if($reposition){
$i = 1;
foreach($this->children as $child){
$child->setPosition($i);
$i++;
}
}
}
/*private function sortChildren(): void
{
$iteration = count($this->children);
while($iteration > 1)
{
for($i = 0; $i < $iteration - 1; $i++)
{
if($this->children[$i]->getPosition() > $this->children[$i + 1]->getPosition())
{
$tmp = $this->children[$i];
$this->children[$i] = $this->children[$i + 1];
$this->children[$i + 1] = $tmp;
}
}
$iteration--;
}
}*/
}
|