From fa3c582a2bd91433399a5b275616052028a5a011 Mon Sep 17 00:00:00 2001 From: polo Date: Thu, 18 Sep 2025 00:27:20 +0200 Subject: =?UTF-8?q?news=20positionn=C3=A9es=20en=20fonction=20de=20leur=20?= =?UTF-8?q?date,=20suppression=20de=20leurs=20boutons=20position,=20am?= =?UTF-8?q?=C3=A9liorations=20routage=20page=20article,=20bouton=20share?= =?UTF-8?q?=20en=20bas=20pour=20les=20news?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/entities/Node.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/model/entities') 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 public function addChild(self $child): void { $this->children[] = $child; - $this->sortChildren(false); + + // cas particulier des news: utilise les dates au lieu des positions (les positions existent mais sont ignorées) + if($this->getName() === 'news_block'){ + $this->sortNews($this->getNodeData()->getData()['chrono'] ?? false); // faux = ordre chronologique + } + else{ + $this->sortChildren(false); + } + } + + private function sortNews(bool $chrono = false) // affichage du plus récent au plus ancien par défaut + { + // tri par insertion similaire à Position::sortChildren + for($i = 1; $i < count($this->children); $i++){ + $tmp = $this->children[$i]; + $j = $i - 1; + + $compare = $chrono ? fn($a, $b) => $a > $b : fn($a, $b) => $a < $b; + + while($j >= 0 && $compare($this->children[$j]->getArticle()->getDateTime(), $tmp->getArticle()->getDateTime())){ + $this->children[$j + 1] = $this->children[$j]; + $j--; + } + $this->children[$j + 1] = $tmp; + } } public function removeChild(self $child): void -- cgit v1.2.3