aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Position.php
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2026-10-23 00:47:32 +0200
committerpolo <ordipolo@gmx.fr>2026-10-23 00:47:32 +0200
commitf27cca08ff786ceff1870147f6d6bad14d71117f (patch)
treed36597a72025313d6faf4ed228755fa267ebe2f6 /src/Model/Position.php
parentc7309f900ef05bd5cb313110ec159b761af394ec (diff)
downloadcms-f27cca08ff786ceff1870147f6d6bad14d71117f.tar.gz
cms-f27cca08ff786ceff1870147f6d6bad14d71117f.tar.bz2
cms-f27cca08ff786ceff1870147f6d6bad14d71117f.zip
dossiers avec majuscule, namespace pour toutes les classes, autoload psr-4, UserDataService::createZip déplacé dans Backup
Diffstat (limited to 'src/Model/Position.php')
-rw-r--r--src/Model/Position.php52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/Model/Position.php b/src/Model/Position.php
new file mode 100644
index 0000000..7799cdf
--- /dev/null
+++ b/src/Model/Position.php
@@ -0,0 +1,52 @@
1<?php
2// src/Model/Position.php
3//
4// pour Node et Page
5
6declare(strict_types=1);
7
8namespace App\Model;
9
10trait Position
11{
12 // tri par insertion du tableau des enfants
13 public function sortChildren(bool $reindexation = false): void
14 {
15 for($i = 1; $i < count($this->children); $i++)
16 {
17 $tmp = $this->children[$i];
18 $j = $i - 1;
19
20 // Déplacez les éléments du tableau qui sont plus grands que la clé à une position devant leur position actuelle
21 while($j >= 0 && $this->children[$j]->getPosition() > $tmp->getPosition()) {
22 $this->children[$j + 1] = $this->children[$j];
23 $j--;
24 }
25 $this->children[$j + 1] = $tmp;
26 }
27
28 // récursivité (utile dans Menu et chemin)
29 // appel dans Page et dans MenuAndPathController (un tri supplémentaire à faire?)
30 if(self::class === 'App\Entity\Page'){
31 foreach($this->children as $child) {
32 if(count($child->children) > 0) {
33 $child->sortChildren($reindexation);
34 }
35 }
36 }
37
38 if($reindexation){
39 $this->reindexPositions();
40 }
41 }
42
43 // nouvelles positions (tableau $children => BDD)
44 public function reindexPositions(): void
45 {
46 $i = 1;
47 foreach($this->children as $child){
48 $child->setPosition($i);
49 $i++;
50 }
51 }
52} \ No newline at end of file