diff options
author | polo <ordipolo@gmx.fr> | 2025-03-31 18:43:53 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2025-03-31 18:43:53 +0200 |
commit | 43c962f442165327d73756c62501ff823d43f9f3 (patch) | |
tree | 89feaa2c625b91b1ad451e73d074378bb54555c5 /src/model/entities/Page.php | |
parent | fb69a844f1ce20fd6ba4bbbb352004bfc5d881af (diff) | |
download | cms-43c962f442165327d73756c62501ff823d43f9f3.zip |
positions dans table page, fil d'ariane en haut, logo dans footer
Diffstat (limited to 'src/model/entities/Page.php')
-rw-r--r-- | src/model/entities/Page.php | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/model/entities/Page.php b/src/model/entities/Page.php index d7d8098..fbf0f27 100644 --- a/src/model/entities/Page.php +++ b/src/model/entities/Page.php | |||
@@ -32,6 +32,9 @@ class Page | |||
32 | #[ORM\Column(type: "boolean")] | 32 | #[ORM\Column(type: "boolean")] |
33 | private bool $in_menu; | 33 | private bool $in_menu; |
34 | 34 | ||
35 | #[ORM\Column(type: "integer", nullable: true)] // null si hors menu | ||
36 | private ?int $position; | ||
37 | |||
35 | #[ORM\ManyToOne(targetEntity: self::class)] | 38 | #[ORM\ManyToOne(targetEntity: self::class)] |
36 | #[ORM\JoinColumn(name: "parent_id", referencedColumnName: "id_page", onDelete: "SET NULL", nullable: true)] | 39 | #[ORM\JoinColumn(name: "parent_id", referencedColumnName: "id_page", onDelete: "SET NULL", nullable: true)] |
37 | private ?self $parent = null; | 40 | private ?self $parent = null; |
@@ -42,12 +45,13 @@ class Page | |||
42 | /*#[ORM\Column(type: "json", nullable: true)] | 45 | /*#[ORM\Column(type: "json", nullable: true)] |
43 | private ?array $metadata = null;*/ | 46 | private ?array $metadata = null;*/ |
44 | 47 | ||
45 | public function __construct(string $name, string $eop, bool $reachable, bool $in_menu, ?Page $parent) | 48 | public function __construct(string $name, string $eop, bool $reachable, bool $in_menu, ?int $position, ?Page $parent) |
46 | { | 49 | { |
47 | $this->name_page = $name; | 50 | $this->name_page = $name; |
48 | $this->end_of_path = $eop; | 51 | $this->end_of_path = $eop; |
49 | $this->reachable = $reachable; | 52 | $this->reachable = $reachable; |
50 | $this->in_menu = $in_menu; | 53 | $this->in_menu = $in_menu; |
54 | $this->position = $position; | ||
51 | $this->parent = $parent; | 55 | $this->parent = $parent; |
52 | $this->children = new ArrayCollection(); | 56 | $this->children = new ArrayCollection(); |
53 | } | 57 | } |
@@ -73,6 +77,10 @@ class Page | |||
73 | { | 77 | { |
74 | return $this->in_menu; | 78 | return $this->in_menu; |
75 | } | 79 | } |
80 | public function getPosition(): ?int | ||
81 | { | ||
82 | return $this->position; | ||
83 | } | ||
76 | public function getParent(): ?Page | 84 | public function getParent(): ?Page |
77 | { | 85 | { |
78 | return $this->parent; | 86 | return $this->parent; |
@@ -93,5 +101,26 @@ class Page | |||
93 | public function addChild(self $child): void | 101 | public function addChild(self $child): void |
94 | { | 102 | { |
95 | $this->children[] = $child; | 103 | $this->children[] = $child; |
104 | $this->sortChildren(); | ||
105 | } | ||
106 | |||
107 | // utiliser $position pour afficher les éléments dans l'ordre | ||
108 | private function sortChildren(): void | ||
109 | { | ||
110 | $iteration = count($this->children); | ||
111 | while($iteration > 1) | ||
112 | { | ||
113 | for($i = 0; $i < $iteration - 1; $i++) | ||
114 | { | ||
115 | //echo '<br>' . $this->children[$i]->getPosition() . ' - ' . $this->children[$i + 1]->getPosition(); | ||
116 | if($this->children[$i]->getPosition() > $this->children[$i + 1]->getPosition()) | ||
117 | { | ||
118 | $tmp = $this->children[$i]; | ||
119 | $this->children[$i] = $this->children[$i + 1]; | ||
120 | $this->children[$i + 1] = $tmp; | ||
121 | } | ||
122 | } | ||
123 | $iteration--; | ||
124 | } | ||
96 | } | 125 | } |
97 | } | 126 | } |