From 58d2a7f5f0b8fbb93730ad2332fa484bbfc80d4c Mon Sep 17 00:00:00 2001 From: polo Date: Mon, 29 Sep 2025 15:39:49 +0200 Subject: ordre des news inversables, champ chrono_order dans NodeData --- public/css/modif_page.css | 20 +++++++++++----- public/js/modif_page.js | 29 ++++++++++++++++++++++ src/controller/PageManagementController.php | 37 ++++++++++++++++++++++------- src/model/entities/Node.php | 2 +- src/model/entities/NodeData.php | 20 +++++++++++++--- src/router.php | 3 +++ src/view/MainBuilder.php | 5 ++++ src/view/templates/modify_block.php | 23 ++++++++++++++---- src/view/templates/modify_page.php | 5 ++++ 9 files changed, 121 insertions(+), 23 deletions(-) diff --git a/public/css/modif_page.css b/public/css/modif_page.css index 8095766..4e38f1b 100644 --- a/public/css/modif_page.css +++ b/public/css/modif_page.css @@ -53,16 +53,20 @@ justify-content: space-evenly; flex-wrap: wrap; } -.edit_page_zone p, .edit_block_zone p, .edit_page_zone form +.new_block { - margin: 5px; + max-width: 300px; } - .new_block #bloc_title { width: 70%; max-width: 300px; } +.explanations +{ + font-style: italic; + font-size: smaller; +} .modify_block img { @@ -76,17 +80,21 @@ { background-color: white; margin: 8px 0; - padding: 5px; } -.modify_one_block > * +.modify_one_block p { - /*text-wrap: nowrap;*/ + margin: 0px; } .modify_one_block > div { + padding: 4px; display: flex; align-items: center; } +.modify_one_block > div > * +{ + margin: 4px; +} .block_options { flex-wrap: wrap; diff --git a/public/js/modif_page.js b/public/js/modif_page.js index ee2004b..bf269ee 100644 --- a/public/js/modif_page.js +++ b/public/js/modif_page.js @@ -176,6 +176,35 @@ function switchBlocsPositions(bloc_id, direction) { }); } +function articlesOrderSelect(bloc_id){ + const articles_order_select = document.getElementById('articles_order_select_' + bloc_id).value; + + fetch('index.php?bloc_edit=change_articles_order', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ id: bloc_id, chrono_order: articles_order_select }) + }) + .then(response => response.json()) + .then(data => { + if(data.success){ + // inverser l'ordre des articles!! + const parent = document.getElementById(bloc_id).querySelector(".section_child"); + const articles = Array.from(parent.querySelectorAll("article")); + articles.reverse().forEach(article => { + parent.appendChild(article); // déplace dans le DOM, ne copie pas + }); + + console.log('ordre ' + articles_order_select); + } + else{ + console.log("Erreur au changement de l'ordre d'affichage côté serveur"); + } + }) + .catch(error => { + console.error('Erreur:', error); + }); +} + function changePresentation(bloc_id){ const presentation = document.getElementById('presentation_select_' + bloc_id).value; diff --git a/src/controller/PageManagementController.php b/src/controller/PageManagementController.php index e811a6a..27bf2c2 100644 --- a/src/controller/PageManagementController.php +++ b/src/controller/PageManagementController.php @@ -85,10 +85,7 @@ class PageManagementController $page); $node->useDefaultAttributes(); // fichiers CSS et JS - $data = new NodeData([ - // pas de titre, il est dans $page - 'description' => trim(htmlspecialchars($_POST["page_description"]))], - $node); + $data = new NodeData(['description' => trim(htmlspecialchars($_POST["page_description"]))], $node); $bulk_data = $entityManager ->createQuery('SELECT n FROM App\Entity\Image n WHERE n.file_name LIKE :name') @@ -162,9 +159,7 @@ class PageManagementController } $block = new Node($_POST["bloc_select"], [], $position, $main, $page); - $data = new NodeData( - ['title' => trim(htmlspecialchars($_POST["bloc_title"]))], - $block); + $data = new NodeData(['title' => trim(htmlspecialchars($_POST["bloc_title"]))], $block); // valeurs par défaut if($_POST["bloc_select"] === 'post_block'){ @@ -268,6 +263,33 @@ class PageManagementController die; } + static public function changeArticlesOrder(EntityManager $entityManager, array $json): void + { + if(isset($json['id']) && isset($json['chrono_order'])){ + $director = new Director($entityManager, false); + $director->findNodeById($json['id']); + + if($json['chrono_order'] === 'chrono'){ + $chrono_order = true; + } + elseif($json['chrono_order'] === 'antichrono'){ + $chrono_order = false; + } + else{ + echo json_encode(['success' => false]); + die; + } + $director->getNode()->getNodeData()->setChronoOrder($chrono_order); + $entityManager->flush(); + + echo json_encode(['success' => true, 'chrono_order' => $json['chrono_order']]); + } + else{ + echo json_encode(['success' => false]); + } + die; + } + static public function changePresentation(EntityManager $entityManager, array $json): void { if(isset($json['id']) && isset($json['presentation'])){ @@ -276,7 +298,6 @@ class PageManagementController if(in_array($json['presentation'], array_keys(Blocks::$presentations))){ $director->getNode()->getNodeData()->setPresentation($json['presentation']); - $entityManager->flush(); $response_data = ['success' => true, 'presentation' => $json['presentation']]; diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php index c5df8d1..08961e0 100644 --- a/src/model/entities/Node.php +++ b/src/model/entities/Node.php @@ -174,7 +174,7 @@ class Node // 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 + $this->sortNews($this->getNodeData()->getChronoOrder() ?? false); // faux = ordre chronologique } else{ $this->sortChildren(false); diff --git a/src/model/entities/NodeData.php b/src/model/entities/NodeData.php index 99dda83..0d42f3a 100644 --- a/src/model/entities/NodeData.php +++ b/src/model/entities/NodeData.php @@ -30,7 +30,10 @@ class NodeData #[ORM\Column(type: "string", length: 255, nullable: true)] private ?string $presentation; - #[ORM\Column(type: "integer", length: 255, nullable: true)] + #[ORM\Column(type: "boolean", length: 255, nullable: true)] + private ?bool $chrono_order = null; + + #[ORM\Column(type: "integer", nullable: true)] private ?int $grid_cols_min_width = null; // pour le mode grille // liaison avec table intermédiaire @@ -42,7 +45,7 @@ class NodeData )] private Collection $images; - public function __construct(array $data, Node $node, Collection $images = new ArrayCollection, string $presentation = null) + public function __construct(array $data, Node $node, Collection $images = new ArrayCollection, ?string $presentation = null, ?bool $chrono_order = null) { $this->data = $data; $this->node = $node; @@ -50,6 +53,7 @@ class NodeData if(!empty($presentation) && $presentation === 'grid'){ $this->grid_cols_min_width = 250; } + $this->chrono_order = $chrono_order ?? null; } public function getId(): int @@ -60,7 +64,7 @@ class NodeData { return $this->data; } - /*public function setData(array $data): void + /*public function setData(array $data): void // entrée = tableau associatif { $this->data = $data; }*/ @@ -74,6 +78,8 @@ class NodeData unset($this->data[$key]); } } + + // spécifique aux blocs contenant des articles public function getPresentation(): ?string { return $this->presentation; @@ -91,6 +97,14 @@ class NodeData { $this->grid_cols_min_width = $columns; } + public function getChronoOrder(): bool + { + return $this->chrono_order ?? false; + } + public function setChronoOrder(bool $reverse_order): void + { + $this->chrono_order = $reverse_order; + } /*public function setNode(Node $node): void { diff --git a/src/router.php b/src/router.php index 8c33d6e..773a25c 100644 --- a/src/router.php +++ b/src/router.php @@ -186,6 +186,9 @@ elseif($_SERVER['REQUEST_METHOD'] === 'POST'){ elseif($request->query->get('bloc_edit') === 'switch_blocs_positions'){ PageManagementController::SwitchBlocsPositions($entityManager, $json); } + elseif($request->query->get('bloc_edit') === 'change_articles_order'){ + PageManagementController::changeArticlesOrder($entityManager, $json); + } elseif($request->query->get('bloc_edit') === 'change_presentation'){ PageManagementController::changePresentation($entityManager, $json); } diff --git a/src/view/MainBuilder.php b/src/view/MainBuilder.php index 2510b08..e4f91f3 100644 --- a/src/view/MainBuilder.php +++ b/src/view/MainBuilder.php @@ -71,6 +71,11 @@ class MainBuilder extends AbstractBuilder // ceci pourrait être déplacé au début des blocs $bloc_edit = ''; foreach($node->getChildren() as $child_node){ + // ordre des articles 'news' + if($child_node->getName() === 'news_block'){ + $order = $child_node->getNodeData()->getChronoOrder() ? 'chrono' : 'antichrono'; + } + ob_start(); require self::VIEWS_PATH . 'modify_block.php'; $bloc_edit .= ob_get_clean(); diff --git a/src/view/templates/modify_block.php b/src/view/templates/modify_block.php index 22a2932..b44327f 100644 --- a/src/view/templates/modify_block.php +++ b/src/view/templates/modify_block.php @@ -19,13 +19,26 @@ getName() === 'news_block'){ +?> +
+ + +
+getNodeData()->getPresentation() !== null){ ?> -

- - +

+
+ + +
pixels diff --git a/src/view/templates/modify_page.php b/src/view/templates/modify_page.php index 5ab1a95..fbcbf20 100644 --- a/src/view/templates/modify_page.php +++ b/src/view/templates/modify_page.php @@ -44,6 +44,11 @@

+
+

Articles libres: textes riches générés par l'éditeur et librement positionnables

+

Actualilés: contenus structurés avec titre, aperçu, date et possédant une page dédiée

+

Galerie: photos parcourables en mode plein écran (cette fonctionalité n'est pas encore disponible)

+

Modifier un bloc

-- cgit v1.2.3