aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2025-09-18 00:27:20 +0200
committerpolo <ordipolo@gmx.fr>2025-09-18 00:27:20 +0200
commitfa3c582a2bd91433399a5b275616052028a5a011 (patch)
tree64a5c2c0eb54dc033fb5ed78ed69745bd492aa05 /src/model
parent027af942de75f7c5bc519fabfa5fa11de9bc89ea (diff)
downloadcms-fa3c582a2bd91433399a5b275616052028a5a011.zip
news positionnées en fonction de leur date, suppression de leurs boutons position, améliorations routage page article, bouton share en bas pour les news
Diffstat (limited to 'src/model')
-rw-r--r--src/model/entities/Node.php26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php
index eb73116..c5df8d1 100644
--- a/src/model/entities/Node.php
+++ b/src/model/entities/Node.php
@@ -171,7 +171,31 @@ class Node
171 public function addChild(self $child): void 171 public function addChild(self $child): void
172 { 172 {
173 $this->children[] = $child; 173 $this->children[] = $child;
174 $this->sortChildren(false); 174
175 // cas particulier des news: utilise les dates au lieu des positions (les positions existent mais sont ignorées)
176 if($this->getName() === 'news_block'){
177 $this->sortNews($this->getNodeData()->getData()['chrono'] ?? false); // faux = ordre chronologique
178 }
179 else{
180 $this->sortChildren(false);
181 }
182 }
183
184 private function sortNews(bool $chrono = false) // affichage du plus récent au plus ancien par défaut
185 {
186 // tri par insertion similaire à Position::sortChildren
187 for($i = 1; $i < count($this->children); $i++){
188 $tmp = $this->children[$i];
189 $j = $i - 1;
190
191 $compare = $chrono ? fn($a, $b) => $a > $b : fn($a, $b) => $a < $b;
192
193 while($j >= 0 && $compare($this->children[$j]->getArticle()->getDateTime(), $tmp->getArticle()->getDateTime())){
194 $this->children[$j + 1] = $this->children[$j];
195 $j--;
196 }
197 $this->children[$j + 1] = $tmp;
198 }
175 } 199 }
176 200
177 public function removeChild(self $child): void 201 public function removeChild(self $child): void