blob: 76de9665a37d6998564d358a3b1d82067c09f899 (
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
|
<?php
// src/modele/Position.php
//
// pour Node et Page
declare(strict_types=1);
trait Position
{
public function sortChildren(bool $reindexation = false): void
{
// tri par insertion du tableau des enfants
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--;
}
$this->children[$j + 1] = $tmp;
}
foreach($this->children as $child) {
if(count($child->children) > 0) {
$child->sortChildren($reindexation);
}
}
// nouvelles positions (tableau $children => BDD)
if($reindexation){
$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--;
}
}*/
}
|