aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2025-09-29 15:39:49 +0200
committerpolo <ordipolo@gmx.fr>2025-09-29 15:39:49 +0200
commit58d2a7f5f0b8fbb93730ad2332fa484bbfc80d4c (patch)
tree8376c00ae1a46076609b7a3fe743730b2e14ff5e /src
parente93cd6c352a8e4fbb4e1174bdb15484adbe4c0f7 (diff)
downloadcms-58d2a7f5f0b8fbb93730ad2332fa484bbfc80d4c.zip
ordre des news inversables, champ chrono_order dans NodeData
Diffstat (limited to 'src')
-rw-r--r--src/controller/PageManagementController.php37
-rw-r--r--src/model/entities/Node.php2
-rw-r--r--src/model/entities/NodeData.php20
-rw-r--r--src/router.php3
-rw-r--r--src/view/MainBuilder.php5
-rw-r--r--src/view/templates/modify_block.php23
-rw-r--r--src/view/templates/modify_page.php5
7 files changed, 78 insertions, 17 deletions
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
85 $page); 85 $page);
86 $node->useDefaultAttributes(); // fichiers CSS et JS 86 $node->useDefaultAttributes(); // fichiers CSS et JS
87 87
88 $data = new NodeData([ 88 $data = new NodeData(['description' => trim(htmlspecialchars($_POST["page_description"]))], $node);
89 // pas de titre, il est dans $page
90 'description' => trim(htmlspecialchars($_POST["page_description"]))],
91 $node);
92 89
93 $bulk_data = $entityManager 90 $bulk_data = $entityManager
94 ->createQuery('SELECT n FROM App\Entity\Image n WHERE n.file_name LIKE :name') 91 ->createQuery('SELECT n FROM App\Entity\Image n WHERE n.file_name LIKE :name')
@@ -162,9 +159,7 @@ class PageManagementController
162 } 159 }
163 160
164 $block = new Node($_POST["bloc_select"], [], $position, $main, $page); 161 $block = new Node($_POST["bloc_select"], [], $position, $main, $page);
165 $data = new NodeData( 162 $data = new NodeData(['title' => trim(htmlspecialchars($_POST["bloc_title"]))], $block);
166 ['title' => trim(htmlspecialchars($_POST["bloc_title"]))],
167 $block);
168 163
169 // valeurs par défaut 164 // valeurs par défaut
170 if($_POST["bloc_select"] === 'post_block'){ 165 if($_POST["bloc_select"] === 'post_block'){
@@ -268,6 +263,33 @@ class PageManagementController
268 die; 263 die;
269 } 264 }
270 265
266 static public function changeArticlesOrder(EntityManager $entityManager, array $json): void
267 {
268 if(isset($json['id']) && isset($json['chrono_order'])){
269 $director = new Director($entityManager, false);
270 $director->findNodeById($json['id']);
271
272 if($json['chrono_order'] === 'chrono'){
273 $chrono_order = true;
274 }
275 elseif($json['chrono_order'] === 'antichrono'){
276 $chrono_order = false;
277 }
278 else{
279 echo json_encode(['success' => false]);
280 die;
281 }
282 $director->getNode()->getNodeData()->setChronoOrder($chrono_order);
283 $entityManager->flush();
284
285 echo json_encode(['success' => true, 'chrono_order' => $json['chrono_order']]);
286 }
287 else{
288 echo json_encode(['success' => false]);
289 }
290 die;
291 }
292
271 static public function changePresentation(EntityManager $entityManager, array $json): void 293 static public function changePresentation(EntityManager $entityManager, array $json): void
272 { 294 {
273 if(isset($json['id']) && isset($json['presentation'])){ 295 if(isset($json['id']) && isset($json['presentation'])){
@@ -276,7 +298,6 @@ class PageManagementController
276 298
277 if(in_array($json['presentation'], array_keys(Blocks::$presentations))){ 299 if(in_array($json['presentation'], array_keys(Blocks::$presentations))){
278 $director->getNode()->getNodeData()->setPresentation($json['presentation']); 300 $director->getNode()->getNodeData()->setPresentation($json['presentation']);
279
280 $entityManager->flush(); 301 $entityManager->flush();
281 302
282 $response_data = ['success' => true, 'presentation' => $json['presentation']]; 303 $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
174 174
175 // cas particulier des news: utilise les dates au lieu des positions (les positions existent mais sont ignorées) 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'){ 176 if($this->getName() === 'news_block'){
177 $this->sortNews($this->getNodeData()->getData()['chrono'] ?? false); // faux = ordre chronologique 177 $this->sortNews($this->getNodeData()->getChronoOrder() ?? false); // faux = ordre chronologique
178 } 178 }
179 else{ 179 else{
180 $this->sortChildren(false); 180 $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
30 #[ORM\Column(type: "string", length: 255, nullable: true)] 30 #[ORM\Column(type: "string", length: 255, nullable: true)]
31 private ?string $presentation; 31 private ?string $presentation;
32 32
33 #[ORM\Column(type: "integer", length: 255, nullable: true)] 33 #[ORM\Column(type: "boolean", length: 255, nullable: true)]
34 private ?bool $chrono_order = null;
35
36 #[ORM\Column(type: "integer", nullable: true)]
34 private ?int $grid_cols_min_width = null; // pour le mode grille 37 private ?int $grid_cols_min_width = null; // pour le mode grille
35 38
36 // liaison avec table intermédiaire 39 // liaison avec table intermédiaire
@@ -42,7 +45,7 @@ class NodeData
42 )] 45 )]
43 private Collection $images; 46 private Collection $images;
44 47
45 public function __construct(array $data, Node $node, Collection $images = new ArrayCollection, string $presentation = null) 48 public function __construct(array $data, Node $node, Collection $images = new ArrayCollection, ?string $presentation = null, ?bool $chrono_order = null)
46 { 49 {
47 $this->data = $data; 50 $this->data = $data;
48 $this->node = $node; 51 $this->node = $node;
@@ -50,6 +53,7 @@ class NodeData
50 if(!empty($presentation) && $presentation === 'grid'){ 53 if(!empty($presentation) && $presentation === 'grid'){
51 $this->grid_cols_min_width = 250; 54 $this->grid_cols_min_width = 250;
52 } 55 }
56 $this->chrono_order = $chrono_order ?? null;
53 } 57 }
54 58
55 public function getId(): int 59 public function getId(): int
@@ -60,7 +64,7 @@ class NodeData
60 { 64 {
61 return $this->data; 65 return $this->data;
62 } 66 }
63 /*public function setData(array $data): void 67 /*public function setData(array $data): void // entrée = tableau associatif
64 { 68 {
65 $this->data = $data; 69 $this->data = $data;
66 }*/ 70 }*/
@@ -74,6 +78,8 @@ class NodeData
74 unset($this->data[$key]); 78 unset($this->data[$key]);
75 } 79 }
76 } 80 }
81
82 // spécifique aux blocs contenant des articles
77 public function getPresentation(): ?string 83 public function getPresentation(): ?string
78 { 84 {
79 return $this->presentation; 85 return $this->presentation;
@@ -91,6 +97,14 @@ class NodeData
91 { 97 {
92 $this->grid_cols_min_width = $columns; 98 $this->grid_cols_min_width = $columns;
93 } 99 }
100 public function getChronoOrder(): bool
101 {
102 return $this->chrono_order ?? false;
103 }
104 public function setChronoOrder(bool $reverse_order): void
105 {
106 $this->chrono_order = $reverse_order;
107 }
94 108
95 /*public function setNode(Node $node): void 109 /*public function setNode(Node $node): void
96 { 110 {
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'){
186 elseif($request->query->get('bloc_edit') === 'switch_blocs_positions'){ 186 elseif($request->query->get('bloc_edit') === 'switch_blocs_positions'){
187 PageManagementController::SwitchBlocsPositions($entityManager, $json); 187 PageManagementController::SwitchBlocsPositions($entityManager, $json);
188 } 188 }
189 elseif($request->query->get('bloc_edit') === 'change_articles_order'){
190 PageManagementController::changeArticlesOrder($entityManager, $json);
191 }
189 elseif($request->query->get('bloc_edit') === 'change_presentation'){ 192 elseif($request->query->get('bloc_edit') === 'change_presentation'){
190 PageManagementController::changePresentation($entityManager, $json); 193 PageManagementController::changePresentation($entityManager, $json);
191 } 194 }
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
71 // ceci pourrait être déplacé au début des blocs 71 // ceci pourrait être déplacé au début des blocs
72 $bloc_edit = ''; 72 $bloc_edit = '';
73 foreach($node->getChildren() as $child_node){ 73 foreach($node->getChildren() as $child_node){
74 // ordre des articles 'news'
75 if($child_node->getName() === 'news_block'){
76 $order = $child_node->getNodeData()->getChronoOrder() ? 'chrono' : 'antichrono';
77 }
78
74 ob_start(); 79 ob_start();
75 require self::VIEWS_PATH . 'modify_block.php'; 80 require self::VIEWS_PATH . 'modify_block.php';
76 $bloc_edit .= ob_get_clean(); 81 $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 @@
19 </div> 19 </div>
20 </div> 20 </div>
21<?php 21<?php
22if($child_node->getName() === 'news_block'){
23?>
24 <div class="news_order">
25 <label>Ordre des articles</label>
26 <select id="articles_order_select_<?= $child_node->getId() ?>" onchange="articlesOrderSelect(<?= $child_node->getId() ?>)">
27 <option value="antichrono" <?= $order === 'antichrono' ? 'selected' : '' ?>>Antichronologique</option>
28 <option value="chrono" <?= $order === 'chrono' ? 'selected' : '' ?>>Chronologique</option>
29 </select>
30 </div>
31<?php
32}
22if($child_node->getNodeData()->getPresentation() !== null){ 33if($child_node->getNodeData()->getPresentation() !== null){
23?> 34?>
24 <div class="grid_options"><p> 35 <div class="grid_options">
25 <label for="presentation_select_<?= $child_node->getId() ?>">Présentation</label> 36 <div>
26 <select id="presentation_select_<?= $child_node->getId() ?>" onchange="changePresentation(<?= $child_node->getId() ?>)"> 37 <label for="presentation_select_<?= $child_node->getId() ?>">Présentation</label>
27 <?= $this->makePresentationOptions($child_node->getNodeData()->getPresentation()) ?> 38 <select id="presentation_select_<?= $child_node->getId() ?>" onchange="changePresentation(<?= $child_node->getId() ?>)">
28 </select> 39 <?= $this->makePresentationOptions($child_node->getNodeData()->getPresentation()) ?>
40 </select>
41 </div>
29 <div id="cols_min_width_edit_<?= $child_node->getId() ?>" class="<?= ($child_node->getNodeData()->getPresentation() === 'grid' ? '' : 'hidden') ?>"> 42 <div id="cols_min_width_edit_<?= $child_node->getId() ?>" class="<?= ($child_node->getNodeData()->getPresentation() === 'grid' ? '' : 'hidden') ?>">
30 <label for="cols_min_width_select_<?= $child_node->getId() ?>">Largeur minimum </label> 43 <label for="cols_min_width_select_<?= $child_node->getId() ?>">Largeur minimum </label>
31 <input type="number" id="cols_min_width_select_<?= $child_node->getId() ?>" onchange="changeColsMinWidth(<?= $child_node->getId() ?>)" min="150" max="400" value="<?= $child_node->getNodeData()->getColsMinWidth() ?>"> pixels 44 <input type="number" id="cols_min_width_select_<?= $child_node->getId() ?>" onchange="changeColsMinWidth(<?= $child_node->getId() ?>)" min="150" max="400" value="<?= $child_node->getNodeData()->getColsMinWidth() ?>"> 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 @@
44 <input type="hidden" name="bloc_title_hidden"> 44 <input type="hidden" name="bloc_title_hidden">
45 <input type="submit" value="Valider"></p> 45 <input type="submit" value="Valider"></p>
46 </form> 46 </form>
47 <div class="explanations">
48 <p><b>Articles libres</b>: textes riches générés par l'éditeur et librement positionnables</p>
49 <p><b>Actualilés</b>: contenus structurés avec titre, aperçu, date et possédant une page dédiée</p>
50 <p><b>Galerie</b>: photos parcourables en mode plein écran (cette fonctionalité n'est pas encore disponible)</p>
51 </div>
47 </div> 52 </div>
48 <div class="modify_block"> 53 <div class="modify_block">
49 <p>Modifier un bloc</p> 54 <p>Modifier un bloc</p>