aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2025-09-01 18:52:17 +0200
committerpolo <ordipolo@gmx.fr>2025-09-01 18:52:17 +0200
commitf477314613beb26b0ce4c61ec0b1900df1de1cb1 (patch)
treed41ace78a572a11887e7cfa2611c3f02fb04e51c
parente642cd51d7e8599537f8514bef8d5d16096dddf8 (diff)
downloadcms-f477314613beb26b0ce4c61ec0b1900df1de1cb1.zip
renommage des présentations,modif présentation des blocs et largeur min (donc nb de colonnes) en mode grid, corrections de bugs et erreurs 404, le param page_modif n'est plus une action, légère symfonyfication du routeur
-rw-r--r--public/css/body.css28
-rw-r--r--public/css/modif_page.css46
-rw-r--r--public/js/modif_page.js75
-rw-r--r--src/controller/ArticleController.php5
-rw-r--r--src/controller/Director.php11
-rw-r--r--src/controller/PageManagementController.php65
-rw-r--r--src/controller/ViewController.php24
-rw-r--r--src/installation.php8
-rw-r--r--src/model/Blocks.php4
-rw-r--r--src/model/entities/Node.php9
-rw-r--r--src/model/entities/NodeData.php40
-rw-r--r--src/model/entities/Presentation.php22
-rw-r--r--src/router.php32
-rw-r--r--src/view/FooterBuilder.php29
-rw-r--r--src/view/MainBuilder.php63
-rw-r--r--src/view/NewBuilder.php13
-rw-r--r--src/view/NewsBlockBuilder.php11
-rw-r--r--src/view/PostBlockBuilder.php11
-rw-r--r--src/view/templates/modify_page.php (renamed from src/view/templates/main.php)6
-rw-r--r--src/view/templates/news_block.php2
-rw-r--r--src/view/templates/post_block.php2
21 files changed, 364 insertions, 142 deletions
diff --git a/public/css/body.css b/public/css/body.css
index 17bdad5..af178a8 100644
--- a/public/css/body.css
+++ b/public/css/body.css
@@ -49,6 +49,10 @@ main
49 background-color: #E3F3FF; 49 background-color: #E3F3FF;
50 padding: 15px 0; 50 padding: 15px 0;
51} 51}
52.hidden
53{
54 display: none;
55}
52section > h3 56section > h3
53{ 57{
54 padding: 15px; 58 padding: 15px;
@@ -62,28 +66,10 @@ section > h3
62 padding: 15px; 66 padding: 15px;
63} 67}
64 68
65.grid_columns 69.grid > .section_child
66{ 70{
67 display: grid; 71 display: grid; /* et c'est tout */
68 grid-template-columns: repeat(3, 1fr); 72 /*grid-template-columns: repeat(auto-fit, minmax(' . $min_width . 'px, 1fr)); */ /* dans PostBlockBuilder et NewsBlockBuilder */
69}
70@media screen and (max-width: 800px)
71{
72 .grid_columns
73 {
74 grid-template-columns: repeat(2, 1fr);
75 }
76}
77@media screen and (max-width: 600px)
78{
79 article
80 {
81 /*margin: 5px;*/
82 }
83 .grid_columns
84 {
85 display: block;
86 }
87} 73}
88.galery_photos 74.galery_photos
89{ 75{
diff --git a/public/css/modif_page.css b/public/css/modif_page.css
index d6fc23e..9048f05 100644
--- a/public/css/modif_page.css
+++ b/public/css/modif_page.css
@@ -5,7 +5,7 @@
5 padding: 10px; 5 padding: 10px;
6 margin: 10px 15px; 6 margin: 10px 15px;
7} 7}
8.page_modification form select, .page_modification form input[type=submit] 8.page_modification select, .page_modification input[type=submit]
9{ 9{
10 color: #ff1d04; 10 color: #ff1d04;
11 font-size: medium; 11 font-size: medium;
@@ -17,7 +17,7 @@
17{ 17{
18 cursor: pointer; 18 cursor: pointer;
19}*/ 19}*/
20.page_modification form input[type=submit]:hover 20.page_modification input[type=submit]:hover
21{ 21{
22 background-color: yellow; 22 background-color: yellow;
23 border-radius: 4px; 23 border-radius: 4px;
@@ -29,10 +29,10 @@
29 flex-wrap: wrap; 29 flex-wrap: wrap;
30 justify-content: space-evenly; 30 justify-content: space-evenly;
31} 31}
32.edit_page_zone, .edit_bloc_zone, .delete_page_zone 32.edit_page_zone, .edit_block_zone, .delete_page_zone
33{ 33{
34 background-color: #f0f0f0f0; 34 background-color: #f0f0f0f0;
35 margin: 5px; 35 margin: 8px 5px;
36 padding: 10px; 36 padding: 10px;
37} 37}
38#edit_description 38#edit_description
@@ -47,32 +47,54 @@
47{ 47{
48 vertical-align: top; 48 vertical-align: top;
49} 49}
50.edit_bloc_zone 50.edit_block_zone
51{ 51{
52 display: flex; 52 display: flex;
53 justify-content: space-evenly; 53 justify-content: space-evenly;
54 flex-wrap: wrap; 54 flex-wrap: wrap;
55} 55}
56.edit_page_zone p, .edit_bloc_zone p, .edit_page_zone form 56.edit_page_zone p, .edit_block_zone p, .edit_page_zone form
57{ 57{
58 margin: 5px; 58 margin: 5px;
59} 59}
60 60
61.new_bloc #bloc_title 61.new_block #bloc_title
62{ 62{
63 width: 70%; 63 width: 70%;
64 max-width: 300px; 64 max-width: 300px;
65} 65}
66.modify_bloc > div 66
67.modify_block img
68{
69 vertical-align: middle;
70}
71.delete_page_zone
72{
73 text-align: center;
74}
75.modify_one_block
76{
77 background-color: white;
78 margin: 8px 0;
79 padding: 5px;
80}
81.modify_one_block > *
82{
83 /*text-wrap: nowrap;*/
84}
85.modify_one_block > div
67{ 86{
68 display: flex; 87 display: flex;
69 align-items: baseline; 88 align-items: baseline;
70} 89}
71.modify_bloc img 90.block_options > *
72{ 91{
73 vertical-align: middle; 92 /*display: flex;
93 flex-wrap: wrap;*/
94 text-wrap: nowrap;
74} 95}
75.delete_page_zone 96.grid_options
76{ 97{
77 text-align: center; 98 /*text-wrap: nowrap;*/ /* saut de la div grid_options */
99 flex-wrap: wrap; /* éléments à l'intérieur de grid_options lorsque lui-même dépasse la largeur dispo (téléphone) */
78} \ No newline at end of file 100} \ No newline at end of file
diff --git a/public/js/modif_page.js b/public/js/modif_page.js
index b307f69..615f34a 100644
--- a/public/js/modif_page.js
+++ b/public/js/modif_page.js
@@ -19,9 +19,7 @@ function changePageTitle(page_id){
19 19
20 fetch('index.php?page_edit=page_title', { 20 fetch('index.php?page_edit=page_title', {
21 method: 'POST', 21 method: 'POST',
22 headers: { 22 headers: { 'Content-Type': 'application/json' },
23 'Content-Type': 'application/json'
24 },
25 body: JSON.stringify({title: page_name.value, page_id: page_id}) 23 body: JSON.stringify({title: page_name.value, page_id: page_id})
26 }) 24 })
27 .then(response => response.json()) 25 .then(response => response.json())
@@ -49,9 +47,7 @@ function changePageTitle(page_id){
49 47
50 fetch('index.php?page_edit=page_menu_path', { 48 fetch('index.php?page_edit=page_menu_path', {
51 method: 'POST', 49 method: 'POST',
52 headers: { 50 headers: { 'Content-Type': 'application/json' },
53 'Content-Type': 'application/json'
54 },
55 body: JSON.stringify({page_menu_path: page_name_path.value, page_id: page_id}) 51 body: JSON.stringify({page_menu_path: page_name_path.value, page_id: page_id})
56 }) 52 })
57 .then(response => response.json()) 53 .then(response => response.json())
@@ -88,9 +84,7 @@ function changeDescription(node_data_id){
88 84
89 fetch('index.php?page_edit=page_description', { 85 fetch('index.php?page_edit=page_description', {
90 method: 'POST', 86 method: 'POST',
91 headers: { 87 headers: { 'Content-Type': 'application/json' },
92 'Content-Type': 'application/json'
93 },
94 body: JSON.stringify({description: textarea.value, node_data_id: node_data_id}) 88 body: JSON.stringify({description: textarea.value, node_data_id: node_data_id})
95 }) 89 })
96 .then(response => response.json()) 90 .then(response => response.json())
@@ -117,9 +111,7 @@ function renamePageBloc(bloc_id){
117 111
118 fetch('index.php?bloc_edit=rename_page_bloc', { 112 fetch('index.php?bloc_edit=rename_page_bloc', {
119 method: 'POST', 113 method: 'POST',
120 headers: { 114 headers: { 'Content-Type': 'application/json' },
121 'Content-Type': 'application/json'
122 },
123 body: JSON.stringify({bloc_title: input.value, bloc_id: bloc_id}) 115 body: JSON.stringify({bloc_title: input.value, bloc_id: bloc_id})
124 }) 116 })
125 .then(response => response.json()) 117 .then(response => response.json())
@@ -159,9 +151,7 @@ function switchBlocsPositions(bloc_id, direction, current_page) {
159 151
160 fetch('index.php?page=' + current_page + '&bloc_edit=switch_blocs_positions', { 152 fetch('index.php?page=' + current_page + '&bloc_edit=switch_blocs_positions', {
161 method: 'POST', 153 method: 'POST',
162 headers: { 154 headers: { 'Content-Type': 'application/json' },
163 'Content-Type': 'application/json'
164 },
165 body: JSON.stringify({ id1: bloc_id, id2: parseInt(other_bloc.id) }) 155 body: JSON.stringify({ id1: bloc_id, id2: parseInt(other_bloc.id) })
166 }) 156 })
167 .then(response => response.json()) 157 .then(response => response.json())
@@ -187,4 +177,59 @@ function switchBlocsPositions(bloc_id, direction, current_page) {
187 .catch(error => { 177 .catch(error => {
188 console.error('Erreur:', error); 178 console.error('Erreur:', error);
189 }); 179 });
180}
181
182function changePresentation(bloc_id){
183 const presentation = document.getElementById('presentation_select_' + bloc_id).value;
184
185 fetch('index.php?bloc_edit=change_presentation', {
186 method: 'POST',
187 headers: { 'Content-Type': 'application/json' },
188 body: JSON.stringify({ id: bloc_id, presentation: presentation })
189 })
190 .then(response => response.json())
191 .then(data => {
192 if(data.success){
193 document.getElementById(bloc_id).className = presentation;
194 document.getElementById('cols_min_width_edit_' + bloc_id).className = presentation === 'grid' ? '' : 'hidden';
195 console.log('changement de présentation');
196 }
197 else{
198 console.log('Erreur au changement de présentation côté serveur');
199 }
200 })
201 .catch(error => {
202 console.error('Erreur:', error);
203 });
204}
205
206function changeColsMinWidth(bloc_id){
207 const cols_min_width_input = document.getElementById('cols_min_width_select_' + bloc_id);
208
209 if(cols_min_width_input.value < 150){
210 cols_min_width_input.value = 150;
211 }
212 else if(cols_min_width_input.value > 500){
213 cols_min_width_input.value = 500;
214 }
215
216 fetch('index.php?bloc_edit=change_cols_min_width', {
217 method: 'POST',
218 headers: { 'Content-Type': 'application/json' },
219 body: JSON.stringify({ id: bloc_id, cols_min_width: cols_min_width_input.value })
220 })
221 .then(response => response.json())
222 .then(data => {
223 if(data.success){
224 document.getElementById(bloc_id).className = 'grid';
225 document.getElementById(bloc_id).querySelector(".section_child").style.gridTemplateColumns = 'repeat(auto-fit, minmax(' + data.cols_min_width + 'px, 1fr))';
226 console.log('changement de la largeur minimum en mode grille');
227 }
228 else{
229 console.log('Erreur au changement du nb de colonnes en mode grille côté serveur');
230 }
231 })
232 .catch(error => {
233 console.error('Erreur:', error);
234 });
190} \ No newline at end of file 235} \ No newline at end of file
diff --git a/src/controller/ArticleController.php b/src/controller/ArticleController.php
index 71bfdc3..b8af290 100644
--- a/src/controller/ArticleController.php
+++ b/src/controller/ArticleController.php
@@ -32,7 +32,10 @@ class ArticleController
32 if($id[0] === 'n') 32 if($id[0] === 'n')
33 { 33 {
34 $section_id = (int)substr($id, 1); // id du bloc <section> 34 $section_id = (int)substr($id, 1); // id du bloc <section>
35 $director->findNodeById($section_id); 35 if(!$director->findNodeById($section_id)){
36 echo json_encode(['success' => false, 'error' => 'article_not_saved']);
37 die;
38 }
36 $director->makeSectionNode(); 39 $director->makeSectionNode();
37 $node = $director->getNode(); // = <section> 40 $node = $director->getNode(); // = <section>
38 41
diff --git a/src/controller/Director.php b/src/controller/Director.php
index b154432..6ee0993 100644
--- a/src/controller/Director.php
+++ b/src/controller/Director.php
@@ -13,7 +13,7 @@ class Director
13 static public Menu $menu_data; // pour NavBuilder 13 static public Menu $menu_data; // pour NavBuilder
14 static public ?Path $page_path = null; // pour $current dans NavBuilder et pour BreadcrumbBuilder 14 static public ?Path $page_path = null; // pour $current dans NavBuilder et pour BreadcrumbBuilder
15 private Page $page; 15 private Page $page;
16 private Node $node; 16 private ?Node $node;
17 private Node $article; 17 private Node $article;
18 18
19 public function __construct(EntityManager $entityManager, bool $get_menu = false) 19 public function __construct(EntityManager $entityManager, bool $get_menu = false)
@@ -82,8 +82,10 @@ class Director
82 $node->getParent()->addChild($node); 82 $node->getParent()->addChild($node);
83 83
84 // spécifique page article 84 // spécifique page article
85 if($node->getName() === 'new' && $this->page->getEndOfPath() == 'article'){ 85 if($this->page->getEndOfPath() == 'article'){
86 $new = $node; 86 if($node->getName() === 'new'){
87 $new = $node;
88 }
87 } 89 }
88 } 90 }
89 } 91 }
@@ -93,9 +95,10 @@ class Director
93 } 95 }
94 96
95 // le basique 97 // le basique
96 public function findNodeById(int $id): void 98 public function findNodeById(int $id): bool
97 { 99 {
98 $this->node = $this->entityManager->find('App\Entity\Node', $id); 100 $this->node = $this->entityManager->find('App\Entity\Node', $id);
101 return $this->node === null ? false : true;
99 } 102 }
100 103
101 // récupération d'un article pour modification 104 // récupération d'un article pour modification
diff --git a/src/controller/PageManagementController.php b/src/controller/PageManagementController.php
index 50ce193..4528810 100644
--- a/src/controller/PageManagementController.php
+++ b/src/controller/PageManagementController.php
@@ -39,7 +39,7 @@ class PageManagementController
39 } 39 }
40 } 40 }
41 $entityManager->flush(); 41 $entityManager->flush();
42 header("Location: " . new URL(['page' => $page->getPagePath(), 'action' => 'modif_page'])); 42 header("Location: " . new URL(['page' => $page->getPagePath(), 'mode' => 'page_modif']));
43 die; 43 die;
44 } 44 }
45 45
@@ -104,7 +104,7 @@ class PageManagementController
104 $entityManager->flush(); 104 $entityManager->flush();
105 105
106 // page créée, direction la page en mode modification pour ajouter des blocs 106 // page créée, direction la page en mode modification pour ajouter des blocs
107 header("Location: " . new URL(['page' => $page->getPagePath(), 'action' => 'modif_page'])); 107 header("Location: " . new URL(['page' => $page->getPagePath(), 'mode' => 'page_modif']));
108 die; 108 die;
109 } 109 }
110 110
@@ -146,10 +146,10 @@ class PageManagementController
146 if($_POST["bloc_select"] === 'calendar' || $_POST["bloc_select"] === 'form'){ 146 if($_POST["bloc_select"] === 'calendar' || $_POST["bloc_select"] === 'form'){
147 $dql = 'SELECT n FROM App\Entity\Node n WHERE n.page = :page AND n.name_node = :name'; // noeud 'head' de la page 147 $dql = 'SELECT n FROM App\Entity\Node n WHERE n.page = :page AND n.name_node = :name'; // noeud 'head' de la page
148 $bulk_data = $entityManager 148 $bulk_data = $entityManager
149 ->createQuery($dql) 149 ->createQuery($dql)
150 ->setParameter('page', $page) 150 ->setParameter('page', $page)
151 ->setParameter('name', 'head') 151 ->setParameter('name', 'head')
152 ->getResult(); 152 ->getResult();
153 153
154 if(count($bulk_data) != 1){ // 1 head par page 154 if(count($bulk_data) != 1){ // 1 head par page
155 header("Location: " . new URL(['page' => $_GET['page'], 'error' => 'head_node_not_found'])); 155 header("Location: " . new URL(['page' => $_GET['page'], 'error' => 'head_node_not_found']));
@@ -175,16 +175,20 @@ class PageManagementController
175 175
176 // valeurs par défaut 176 // valeurs par défaut
177 if($_POST["bloc_select"] === 'post_block'){ 177 if($_POST["bloc_select"] === 'post_block'){
178 $data->setPresentation($entityManager->find('App\Entity\Presentation', 1)); // pas génial l'utilisation de l'index dans la table 178 $data->setPresentation(Presentation::findPresentation($entityManager, 'fullwidth')); // pas génial l'utilisation de l'index dans la table
179 } 179 }
180 elseif($_POST["bloc_select"] === 'news_block'){ 180 elseif($_POST["bloc_select"] === 'news_block'){
181 $data->setPresentation($entityManager->find('App\Entity\Presentation', 2)); 181 $data->setPresentation(Presentation::findPresentation($entityManager, 'grid'));
182 }
183 elseif($_POST["bloc_select"] === 'galery'){
184 $data->setPresentation(Presentation::findPresentation($entityManager, 'mosaic')); // mieux que carousel pour commencer
182 } 185 }
186 // else = null par défaut
183 187
184 $entityManager->persist($block); 188 $entityManager->persist($block);
185 $entityManager->persist($data); 189 $entityManager->persist($data);
186 $entityManager->flush(); 190 $entityManager->flush();
187 header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); 191 header("Location: " . new URL(['page' => $_GET['page'], 'mode' => 'page_modif']));
188 die; 192 die;
189 } 193 }
190 194
@@ -208,7 +212,8 @@ class PageManagementController
208 $entityManager->remove($bloc); // suppression en BDD 212 $entityManager->remove($bloc); // suppression en BDD
209 $entityManager->flush(); 213 $entityManager->flush();
210 } 214 }
211 header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); 215
216 header("Location: " . new URL(['page' => $_GET['page'], 'mode' => 'page_modif']));
212 die; 217 die;
213 } 218 }
214 219
@@ -235,7 +240,7 @@ class PageManagementController
235 static public function SwitchBlocsPositions(EntityManager $entityManager, array $json): void 240 static public function SwitchBlocsPositions(EntityManager $entityManager, array $json): void
236 { 241 {
237 if(isset($json['id1']) && is_int($json['id1']) && isset($json['id2']) && is_int($json['id2']) && isset($_GET['page'])){ 242 if(isset($json['id1']) && is_int($json['id1']) && isset($json['id2']) && is_int($json['id2']) && isset($_GET['page'])){
238 $director = new Director($entityManager, true); 243 $director = new Director($entityManager, true); // true pour $director->findItsChildren();
239 $director->findUniqueNodeByName('main'); 244 $director->findUniqueNodeByName('main');
240 $director->findItsChildren(); 245 $director->findItsChildren();
241 $main = $director->getNode(); 246 $main = $director->getNode();
@@ -269,4 +274,42 @@ class PageManagementController
269 } 274 }
270 die; 275 die;
271 } 276 }
277
278 static public function changePresentation(EntityManager $entityManager, array $json): void
279 {
280 if(isset($json['id']) && isset($json['presentation'])){
281 $director = new Director($entityManager, false);
282 $director->findNodeById($json['id']);
283
284 $presentation = Presentation::findPresentation($entityManager, $json['presentation']);
285 if($presentation !== null){
286 $director->getNode()->getNodeData()->setPresentation($presentation);
287
288 $entityManager->flush();
289 echo json_encode(['success' => true, 'presentation' => $json['presentation'], 'cols_min_width' => $director->getNode()->getNodeData()->getColsMinWidth()]);
290 }
291 else{
292 echo json_encode(['success' => false]);
293 }
294 }
295 else{
296 echo json_encode(['success' => false]);
297 }
298 die;
299 }
300 static public function changeColsMinWidth(EntityManager $entityManager, array $json): void
301 {
302 if(isset($json['id']) && isset($json['cols_min_width'])){
303 $director = new Director($entityManager, false);
304 $director->findNodeById($json['id']);
305 $director->getNode()->getNodeData()->setColsMinWidth((int)$json['cols_min_width']); // attention conversion?
306
307 $entityManager->flush();
308 echo json_encode(['success' => true, 'cols_min_width' => $json['cols_min_width']]);
309 }
310 else{
311 echo json_encode(['success' => false]);
312 }
313 die;
314 }
272} \ No newline at end of file 315} \ No newline at end of file
diff --git a/src/controller/ViewController.php b/src/controller/ViewController.php
index 0830a5b..668fa25 100644
--- a/src/controller/ViewController.php
+++ b/src/controller/ViewController.php
@@ -5,16 +5,17 @@
5 5
6declare(strict_types=1); 6declare(strict_types=1);
7 7
8use App\Entity\Article;
8use App\Entity\Node; 9use App\Entity\Node;
9use Doctrine\ORM\EntityManager; 10use Doctrine\ORM\EntityManager;
10use Symfony\Component\HttpFoundation\Request; 11use Symfony\Component\HttpFoundation\Request;
11use Symfony\Component\HttpFoundation\Response; 12use Symfony\Component\HttpFoundation\Response;
12 13
13class ViewController extends AbstractBuilder 14class ViewController extends AbstractBuilder // ViewController est aussi le premier Builder
14{ 15{
15 static public Node $root_node; 16 static public Node $root_node;
16 17
17 public function __construct(){} 18 public function __construct(){} // surcharge celui de AbstractBuilder
18 19
19 public function buildView(EntityManager $entityManager, Request $request): Response 20 public function buildView(EntityManager $entityManager, Request $request): Response
20 { 21 {
@@ -25,13 +26,28 @@ class ViewController extends AbstractBuilder
25 26
26 // mode modification d'une page activé 27 // mode modification d'une page activé
27 if($_SESSION['admin'] && $request->query->has('page') 28 if($_SESSION['admin'] && $request->query->has('page')
28 && $request->query->has('action') && $request->query->get('action') === 'modif_page' 29 && $request->query->has('mode') && $request->query->get('mode') === 'page_modif'
29 && $request->query->get('page') !== 'connexion' && $request->query->get('page') !== 'article' && $request->query->get('page') !== 'nouvelle_page' && $request->query->get('page') !== 'menu_chemins'){ 30 && $request->query->get('page') !== 'connexion' && $request->query->get('page') !== 'article' && $request->query->get('page') !== 'nouvelle_page' && $request->query->get('page') !== 'menu_chemins'){
30 // les contrôles de la 2è ligne devraient utiliser un tableau 31 // les contrôles de la 2è ligne devraient utiliser un tableau
31 MainBuilder::$modif_mode = true; 32 MainBuilder::$modif_mode = true;
32 } 33 }
33 34
34 // construction de la page 35 // page article: mode création et erreurs d'id
36 if($_SESSION['admin'] && $request->query->has('page') && $request->query->get('page') === 'article'){
37 if(!$request->query->has('id')){
38 return new Response($this->html, 302);
39 }
40 else{
41 if($request->query->get('id')[0] === 'n'){ // mode création d'article (vérification de l'id du bloc dans ArticleController)
42 NewBuilder::$new_article_mode = true;
43 }
44 elseif(self::$root_node->getNodeByName('main')->getAdoptedChild() === null){ // id inconnu
45 return new Response($this->html, 302);
46 }
47 }
48 }
49
50 //début de la construction de la page
35 $this->useChildrenBuilder(self::$root_node); 51 $this->useChildrenBuilder(self::$root_node);
36 52
37 return new Response($this->html, 200); 53 return new Response($this->html, 200);
diff --git a/src/installation.php b/src/installation.php
index dd3aa35..b251c43 100644
--- a/src/installation.php
+++ b/src/installation.php
@@ -118,8 +118,10 @@ function makeStartPage(EntityManager $entityManager){
118 $bloc_new_page = new Node('new_page', NULL, [], 1, $main, $new_page, NULL); 118 $bloc_new_page = new Node('new_page', NULL, [], 1, $main, $new_page, NULL);
119 119
120 /* -- table presentation -- */ 120 /* -- table presentation -- */
121 $list = new Presentation('list'); 121 $fullwidth = new Presentation('fullwidth');
122 $grid = new Presentation('grid'); 122 $grid = new Presentation('grid');
123 $mosaic = new Presentation('mosaic');
124 $carousel = new Presentation('carousel');
123 125
124 /* -- table image -- */ 126 /* -- table image -- */
125 // paramètres: file_name, file_path, file_path_mini, mime_type, alt 127 // paramètres: file_name, file_path, file_path_mini, mime_type, alt
@@ -169,8 +171,10 @@ function makeStartPage(EntityManager $entityManager){
169 $entityManager->persist($bloc_new_page); 171 $entityManager->persist($bloc_new_page);
170 172
171 /* -- table presentation -- */ 173 /* -- table presentation -- */
172 $entityManager->persist($list); 174 $entityManager->persist($fullwidth);
173 $entityManager->persist($grid); 175 $entityManager->persist($grid);
176 $entityManager->persist($mosaic);
177 $entityManager->persist($carousel);
174 178
175 /* -- table image -- */ 179 /* -- table image -- */
176 $entityManager->persist($favicon); 180 $entityManager->persist($favicon);
diff --git a/src/model/Blocks.php b/src/model/Blocks.php
index f6475cd..a6fab45 100644
--- a/src/model/Blocks.php
+++ b/src/model/Blocks.php
@@ -3,10 +3,10 @@
3 3
4class Blocks{ 4class Blocks{
5 /*private array $types = ['blog', 'grid', 'calendar', 'galery', 'form'];*/ 5 /*private array $types = ['blog', 'grid', 'calendar', 'galery', 'form'];*/
6 static private array $types = ['post_block', 'news_block', 'calendar', 'galery', 'form']; 6 static private array $types = ['post_block', 'news_block', 'galery', 'calendar', 'form'];
7 7
8 /*private array $names = ['Blog', 'Grille', 'Calendrier', 'Galerie', 'Formulaire'];*/ 8 /*private array $names = ['Blog', 'Grille', 'Calendrier', 'Galerie', 'Formulaire'];*/
9 static private array $names = ['Articles libres', 'Actualités', 'Calendrier', 'Galerie', 'Formulaire']; 9 static private array $names = ['Articles libres', 'Actualités', 'Galerie', 'Calendrier', 'Formulaire'];
10 10
11 static public function getNameList(): array 11 static public function getNameList(): array
12 { 12 {
diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php
index 93363d3..7cf395c 100644
--- a/src/model/entities/Node.php
+++ b/src/model/entities/Node.php
@@ -161,6 +161,15 @@ class Node
161 { 161 {
162 return $this->children; 162 return $this->children;
163 } 163 }
164 public function getNodeByName(string $name): ?Node
165 {
166 foreach($this->children as $child){
167 if($child->getName() === $name){
168 return $child;
169 }
170 }
171 return null;
172 }
164 public function addChild(self $child): void 173 public function addChild(self $child): void
165 { 174 {
166 $this->children[] = $child; 175 $this->children[] = $child;
diff --git a/src/model/entities/NodeData.php b/src/model/entities/NodeData.php
index c835727..3688e4a 100644
--- a/src/model/entities/NodeData.php
+++ b/src/model/entities/NodeData.php
@@ -24,12 +24,15 @@ class NodeData
24 #[ORM\JoinColumn(name: "node_id", referencedColumnName: "id_node", onDelete: "CASCADE")] 24 #[ORM\JoinColumn(name: "node_id", referencedColumnName: "id_node", onDelete: "CASCADE")]
25 private Node $node; 25 private Node $node;
26 26
27 #[ORM\Column(type: "json")]
28 private array $data;
29
27 #[ORM\ManyToOne(targetEntity: Presentation::class)] 30 #[ORM\ManyToOne(targetEntity: Presentation::class)]
28 #[ORM\JoinColumn(name: "presentation_id", referencedColumnName: "id_presentation", nullable: true)] 31 #[ORM\JoinColumn(name: "presentation_id", referencedColumnName: "id_presentation", nullable: true)]
29 private Presentation $presentation; 32 private ?Presentation $presentation;
30 33
31 #[ORM\Column(type: "json")] 34 #[ORM\Column(type: "integer", length: 255, nullable: true)]
32 private array $data; 35 private ?int $grid_cols_min_width = null; // pour le mode grille
33 36
34 // liaison avec table intermédiaire 37 // liaison avec table intermédiaire
35 #[ORM\ManyToMany(targetEntity: Image::class, inversedBy: "node_data")] 38 #[ORM\ManyToMany(targetEntity: Image::class, inversedBy: "node_data")]
@@ -40,25 +43,20 @@ class NodeData
40 )] 43 )]
41 private Collection $images; 44 private Collection $images;
42 45
43 public function __construct(array $data, Node $node, Collection $images = new ArrayCollection) 46 public function __construct(array $data, Node $node, Collection $images = new ArrayCollection, Presentation $presentation = null)
44 { 47 {
45 $this->data = $data; 48 $this->data = $data;
46 $this->node = $node; 49 $this->node = $node;
47 $this->images = $images; 50 $this->images = $images;
51 if(!empty($presentation) && $presentation->getName() === 'grid'){
52 $this->grid_cols_min_width = 250;
53 }
48 } 54 }
49 55
50 public function getId(): int 56 public function getId(): int
51 { 57 {
52 return $this->id_node_data; 58 return $this->id_node_data;
53 } 59 }
54 public function getPresentation(): Presentation
55 {
56 return $this->presentation;
57 }
58 public function setPresentation(Presentation $presentation): void
59 {
60 $this->presentation = $presentation;
61 }
62 public function getData(): array 60 public function getData(): array
63 { 61 {
64 return $this->data; 62 return $this->data;
@@ -77,6 +75,24 @@ class NodeData
77 unset($this->data[$key]); 75 unset($this->data[$key]);
78 } 76 }
79 } 77 }
78 public function getPresentation(): ?Presentation
79 {
80 return $this->presentation;
81 }
82 public function setPresentation(Presentation $presentation): void
83 {
84 $this->presentation = $presentation;
85 }
86 public function getColsMinWidth(): int
87 {
88 $default = 320; // pixels
89 return $this->grid_cols_min_width === null ? $default : $this->grid_cols_min_width;
90 }
91 public function setColsMinWidth(int $columns): void
92 {
93 $this->grid_cols_min_width = $columns;
94 }
95
80 /*public function setNode(Node $node): void 96 /*public function setNode(Node $node): void
81 { 97 {
82 $this->node = $node; 98 $this->node = $node;
diff --git a/src/model/entities/Presentation.php b/src/model/entities/Presentation.php
index 73b6a6a..6ada565 100644
--- a/src/model/entities/Presentation.php
+++ b/src/model/entities/Presentation.php
@@ -5,27 +5,43 @@ declare(strict_types=1);
5 5
6namespace App\Entity; 6namespace App\Entity;
7 7
8use Doctrine\ORM\EntityManager;
8use Doctrine\ORM\Mapping as ORM; 9use Doctrine\ORM\Mapping as ORM;
9 10
10#[ORM\Entity] 11#[ORM\Entity]
11#[ORM\Table(name: TABLE_PREFIX . "presentation")] 12#[ORM\Table(name: TABLE_PREFIX . "presentation")]
12class Presentation 13class Presentation
13{ 14{
15 static public array $option_list = ['fullwidth' => 'Pleine largeur', 'grid' => 'Grille', 'mosaic' => 'Mosaïque', 'carousel' => 'Carrousel'];
16
14 #[ORM\Id] 17 #[ORM\Id]
15 #[ORM\GeneratedValue] 18 #[ORM\GeneratedValue]
16 #[ORM\Column(type: "integer")] 19 #[ORM\Column(type: "integer")]
17 private int $id_presentation; 20 private int $id_presentation;
18 21
19 #[ORM\Column(type: "string", length: 255)] 22 #[ORM\Column(type: "string", length: 255)]
20 private string $name_presentation; 23 private string $name;
21 24
22 public function __construct(string $name) 25 public function __construct(string $name)
23 { 26 {
24 $this->name_presentation = $name; 27 $this->name = array_keys(self::$option_list)[0]; // = fullwidth, sécurité option inconnue
28 foreach(self::$option_list as $key => $value){
29 if($name === $key){
30 $this->name = $name;
31 }
32 }
25 } 33 }
26 34
27 public function getName(): string 35 public function getName(): string
28 { 36 {
29 return $this->name_presentation; 37 return $this->name;
38 }
39
40 static public function findPresentation(EntityManager $entityManager, string $name): ?self
41 {
42 return $entityManager
43 ->createQuery('SELECT p FROM App\Entity\Presentation p WHERE p.name = :name')
44 ->setParameter('name', $name)
45 ->getOneOrNullResult();
30 } 46 }
31} \ No newline at end of file 47} \ No newline at end of file
diff --git a/src/router.php b/src/router.php
index 92dccb6..326a637 100644
--- a/src/router.php
+++ b/src/router.php
@@ -21,8 +21,7 @@ if($_SERVER['REQUEST_METHOD'] === 'GET'){
21 } 21 }
22 22
23 // bouton déconnexion 23 // bouton déconnexion
24 if($request->query->has('action') && $request->query->get('action') === 'deconnection') 24 if($request->query->has('action') && $request->query->get('action') === 'deconnection'){
25 {
26 UserController::disconnect($entityManager); 25 UserController::disconnect($entityManager);
27 } 26 }
28 27
@@ -40,6 +39,7 @@ if($_SERVER['REQUEST_METHOD'] === 'GET'){
40 39
41 // construction d'une page 40 // construction d'une page
42 $response = (new ViewController)->buildView($entityManager, $request); // utilise Director 41 $response = (new ViewController)->buildView($entityManager, $request); // utilise Director
42 // parenthèses nécéssaires autour de l'instanciation pour PHP < 8.4
43} 43}
44 44
45 45
@@ -47,8 +47,7 @@ elseif($_SERVER['REQUEST_METHOD'] === 'POST'){
47 /* -- contrôleurs appellables par tout le monde -- */ 47 /* -- contrôleurs appellables par tout le monde -- */
48 48
49 // table "user" vide 49 // table "user" vide
50 if(!UserController::existUsers($entityManager)) 50 if(!UserController::existUsers($entityManager)){
51 {
52 UserController::createUser($entityManager); 51 UserController::createUser($entityManager);
53 } 52 }
54 53
@@ -179,14 +178,18 @@ elseif($_SERVER['REQUEST_METHOD'] === 'POST'){
179 // partie "blocs" 178 // partie "blocs"
180 elseif($request->query->has('bloc_edit')) 179 elseif($request->query->has('bloc_edit'))
181 { 180 {
182 // renommage d'un bloc
183 if($request->query->get('bloc_edit') === 'rename_page_bloc'){ 181 if($request->query->get('bloc_edit') === 'rename_page_bloc'){
184 PageManagementController::renameBloc($entityManager, $json); 182 PageManagementController::renameBloc($entityManager, $json);
185 } 183 }
186 // inversion des positions de deux blocs
187 elseif($request->query->get('bloc_edit') === 'switch_blocs_positions'){ 184 elseif($request->query->get('bloc_edit') === 'switch_blocs_positions'){
188 PageManagementController::SwitchBlocsPositions($entityManager, $json); 185 PageManagementController::SwitchBlocsPositions($entityManager, $json);
189 } 186 }
187 elseif($request->query->get('bloc_edit') === 'change_presentation'){
188 PageManagementController::changePresentation($entityManager, $json);
189 }
190 elseif($request->query->get('bloc_edit') === 'change_cols_min_width'){
191 PageManagementController::changeColsMinWidth($entityManager, $json);
192 }
190 } 193 }
191 } 194 }
192 195
@@ -206,7 +209,7 @@ elseif($_SERVER['REQUEST_METHOD'] === 'POST'){
206 /* -- envoi formulaire HTML -- */ 209 /* -- envoi formulaire HTML -- */
207 elseif($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') 210 elseif($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded')
208 { 211 {
209 if($_GET['action'] === 'delete_article' && isset($_GET['id'])){ 212 if($request->query->has('action') && $request->query->get('action') === 'delete_article' && isset($_GET['id'])){
210 $response = ArticleController::deleteArticle($entityManager, $_GET); // version formulaire 213 $response = ArticleController::deleteArticle($entityManager, $_GET); // version formulaire
211 } 214 }
212 215
@@ -303,13 +306,13 @@ else{
303 306
304/* -- utilisation de la réponse -- */ 307/* -- utilisation de la réponse -- */
305if(isset($response)){ 308if(isset($response)){
306 if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') 309 if($request->isMethod('GET') && $response->getStatusCode() == 302){ // 302 redirection temporaire
307 { 310 // ne gère pour l'instant que les mauvais id de la page article
311 header('Location: ' . new URL(['page' => !empty($_GET['from']) ? $_GET['from'] : 'accueil']));
312 }
313 elseif($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded'){
308 $response_data = json_decode(($response)->getContent(), true); 314 $response_data = json_decode(($response)->getContent(), true);
309 $url = new URL; 315 $url = new URL(['page' => !empty($_GET['from']) ? $_GET['from'] : 'accueil']);
310 if(isset($_GET['from'])){
311 $url->addParams(['page' => $_GET['from']]);
312 }
313 $url->addParams(['success' => $response_data['success'], 'message' => $response_data['message']]); 316 $url->addParams(['success' => $response_data['success'], 'message' => $response_data['message']]);
314 header('Location: ' . $url); 317 header('Location: ' . $url);
315 } 318 }
@@ -318,8 +321,7 @@ if(isset($response)){
318 } 321 }
319} 322}
320else{ 323else{
321 if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') 324 if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded'){
322 {
323 header("Location: " . new URL(['error' => 'erreur côté serveur'])); 325 header("Location: " . new URL(['error' => 'erreur côté serveur']));
324 } 326 }
325 else{ 327 else{
diff --git a/src/view/FooterBuilder.php b/src/view/FooterBuilder.php
index eda5be1..cf88476 100644
--- a/src/view/FooterBuilder.php
+++ b/src/view/FooterBuilder.php
@@ -24,21 +24,16 @@ class FooterBuilder extends AbstractBuilder
24 24
25 // zone admin 25 // zone admin
26 $empty_admin_zone = ''; 26 $empty_admin_zone = '';
27 //$zone_admin = '';
28 if($_SESSION['admin']) 27 if($_SESSION['admin'])
29 { 28 {
30 $empty_admin_zone = 'empty_admin_zone'; 29 $empty_admin_zone = 'empty_admin_zone';
31 $link_edit_page = CURRENT_PAGE === 'article' ? new URL(['page' => 'accueil']) : new URL(['page' => CURRENT_PAGE]);
32 if(MainBuilder::$modif_mode){ 30 if(MainBuilder::$modif_mode){
33 $mode = 'modification de page'; 31 $mode = 'modification de page';
34 $div_admin = 'logged_in modif_mode'; 32 $div_admin = 'logged_in modif_mode';
35 $link_edit_label = 'Sortir du mode modification';
36 } 33 }
37 else{ 34 else{
38 $mode = 'administrateur'; 35 $mode = 'administrateur';
39 $div_admin = 'logged_in'; 36 $div_admin = 'logged_in';
40 $link_edit_page->addParams(['action' => 'modif_page']);
41 $link_edit_label = 'Modifier la page';
42 } 37 }
43 $link_new_page = new URL(['page' => 'nouvelle_page']); 38 $link_new_page = new URL(['page' => 'nouvelle_page']);
44 $link_change_paths = new URL(['page' => 'menu_chemins']); 39 $link_change_paths = new URL(['page' => 'menu_chemins']);
@@ -51,9 +46,9 @@ class FooterBuilder extends AbstractBuilder
51 46
52 $zone_admin = '<div class="admin_buttons_zone"> 47 $zone_admin = '<div class="admin_buttons_zone">
53 <p>Vous êtes en mode ' . $mode . ".</p>\n" . 48 <p>Vous êtes en mode ' . $mode . ".</p>\n" .
54 '<div><a href="' . $link_new_page . '"><button>Nouvelle page</button></a></div>' . "\n" . 49 '<div><a href="' . $link_new_page . '"><button>Nouvelle page</button></a></div>' . "\n";
55 '<div><a href="' . $link_edit_page . '"><button>' . $link_edit_label . '</button></a></div>' . "\n" . 50 $zone_admin .= $this->makePageModifModeButton();
56 '<div><a href="' . $link_change_paths . '"><button>Menu et chemins</button></a></div>' . "\n" . 51 $zone_admin .= '<div><a href="' . $link_change_paths . '"><button>Menu et chemins</button></a></div>' . "\n" .
57 '<div><a href="' . $link_change_password . '"><button>Mon compte</button></a></div>' . "\n" . 52 '<div><a href="' . $link_change_password . '"><button>Mon compte</button></a></div>' . "\n" .
58 '<div><a href="' . $link_logout . '"><button>Déconnexion</button></a></div>' . "\n" . 53 '<div><a href="' . $link_logout . '"><button>Déconnexion</button></a></div>' . "\n" .
59 '</div>' . "\n"; 54 '</div>' . "\n";
@@ -73,4 +68,22 @@ class FooterBuilder extends AbstractBuilder
73 $this->html = ob_get_clean(); 68 $this->html = ob_get_clean();
74 } 69 }
75 } 70 }
71
72 private function makePageModifModeButton(): string
73 {
74 $link_edit_page = new URL(['page' => CURRENT_PAGE]);
75 if(CURRENT_PAGE !== 'article'){
76 if(MainBuilder::$modif_mode){
77 $link_edit_label = 'Sortir du mode modification';
78 }
79 else{
80 $link_edit_page->addParams(['mode' => 'page_modif']);
81 $link_edit_label = 'Modifier la page';
82 }
83 return '<div><a href="' . $link_edit_page . '"><button>' . $link_edit_label . '</button></a></div>' . "\n";
84 }
85 else{
86 return '';
87 }
88 }
76} \ No newline at end of file 89} \ No newline at end of file
diff --git a/src/view/MainBuilder.php b/src/view/MainBuilder.php
index d7a0dfa..fc80cd1 100644
--- a/src/view/MainBuilder.php
+++ b/src/view/MainBuilder.php
@@ -5,10 +5,11 @@ declare(strict_types=1);
5 5
6use App\Entity\Article; 6use App\Entity\Article;
7use App\Entity\Node; 7use App\Entity\Node;
8use App\Entity\Presentation;
8 9
9class MainBuilder extends AbstractBuilder 10class MainBuilder extends AbstractBuilder
10{ 11{
11 static bool $modif_mode = false; 12 static public bool $modif_mode = false;
12 13
13 public function __construct(Node $node) 14 public function __construct(Node $node)
14 { 15 {
@@ -52,7 +53,8 @@ class MainBuilder extends AbstractBuilder
52 // mode modification de page uniquement 53 // mode modification de page uniquement
53 private function viewEditBlocks($node): void 54 private function viewEditBlocks($node): void
54 { 55 {
55 $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; // mode modification uniquement 56 //$viewFile = self::VIEWS_PATH . $node->getName() . '.php'; // mode modification uniquement
57 $viewFile = self::VIEWS_PATH . 'modify_page.php'; // mode modification uniquement
56 $blocks = Blocks::getTypeNamePairs(); 58 $blocks = Blocks::getTypeNamePairs();
57 59
58 $options = ''; 60 $options = '';
@@ -71,25 +73,62 @@ class MainBuilder extends AbstractBuilder
71 73
72 $bloc_edit = ''; 74 $bloc_edit = '';
73 foreach($node->getChildren() as $child_node){ 75 foreach($node->getChildren() as $child_node){
76 // mettre tout ça dans une vue modify_block.php
77 // => pourrait être déplacé au niveau des articles
78
74 // renommage d'un bloc 79 // renommage d'un bloc
75 $bloc_edit .= '<div id="bloc_edit_' . $child_node->getId() . '"> 80 $bloc_edit .= '<div class="modify_one_block" id="bloc_edit_' . $child_node->getId() . '">
76 <p><label for="bloc_rename_' . $child_node->getId() . '"><b>' . Blocks::getNameFromType($child_node->getName()) . '</b></label> 81 <div class="block_options">
77 <input type="text" id="bloc_rename_' . $child_node->getId() . '" name="bloc_rename_title" value="' . $child_node->getNodeData()->getdata()['title'] . '" required> 82 <label for="bloc_rename_' . $child_node->getId() . '">Type <b>' . Blocks::getNameFromType($child_node->getName()) . '</b></label>
78 <button onclick="renamePageBloc(' . $child_node->getId() . ')">Renommer</button>'. "\n"; 83 <p>
84 <input type="text" id="bloc_rename_' . $child_node->getId() . '" name="bloc_rename_title" value="' . $child_node->getNodeData()->getdata()['title'] . '" required>
85 <button onclick="renamePageBloc(' . $child_node->getId() . ')">Renommer</button>
86 </p>'. "\n";
79 // déplacement d'un bloc 87 // déplacement d'un bloc
80 $bloc_edit .= '<img class="action_icon" onclick="switchBlocsPositions(' . $child_node->getId() . ', \'up\', \'' . CURRENT_PAGE . '\')" src="assets/arrow-up.svg"> 88 $bloc_edit .= '<div style="display: flex; flex-wrap: wrap;">
81 <img class="action_icon" onclick="switchBlocsPositions(' . $child_node->getId() . ', \'down\', \'' . CURRENT_PAGE . '\')" src="assets/arrow-down.svg">' . "\n"; 89 <p>
90 <img class="action_icon" onclick="switchBlocsPositions(' . $child_node->getId() . ', \'up\', \'' . CURRENT_PAGE . '\')" src="assets/arrow-up.svg">
91 <img class="action_icon" onclick="switchBlocsPositions(' . $child_node->getId() . ', \'down\', \'' . CURRENT_PAGE . '\')" src="assets/arrow-down.svg">
92 </p>' . "\n";
82 // suppression d'un bloc 93 // suppression d'un bloc
83 $bloc_edit .= '<form method="post" action="' . new URL(['page' => CURRENT_PAGE]) . '"> 94 $bloc_edit .= '<form method="post" action="' . new URL(['page' => CURRENT_PAGE]) . '">
84 <input type="hidden" name="delete_bloc_id" value="' . $child_node->getId() . '"> 95 <input type="hidden" name="delete_bloc_id" value="' . $child_node->getId() . '">
85 <input type="hidden" name="delete_bloc_hidden"> 96 <input type="hidden" name="delete_bloc_hidden">
86 <input type="submit" value="Supprimer" onclick="return confirm(\'Voulez-vous vraiment supprimer ce bloc?\');"></p> 97 <input type="submit" value="Supprimer" onclick="return confirm(\'Voulez-vous vraiment supprimer ce bloc?\');">
87 </form> 98 </form>
99 </div>
88 </div>'. "\n"; 100 </div>'. "\n";
101 if($child_node->getNodeData()->getPresentation() !== null){
102 // select mode de présentation
103 $bloc_edit .= '<div class="grid_options"><p>
104 <label for="presentation_select_' . $child_node->getId() . '">Présentation</label>
105 <select id="presentation_select_' . $child_node->getId() . '" onchange="changePresentation(' . $child_node->getId() . ')">';
106 $bloc_edit .= $this->makePresentationOptions($child_node->getNodeData()->getPresentation()->getName());
107 $bloc_edit .= '</select>';
108 // select largeur minimale colonnes mode grid
109 $bloc_edit .= '<div id="cols_min_width_edit_' . $child_node->getId() . '" class="' . ($child_node->getNodeData()->getPresentation()->getName() === 'grid' ? '' : 'hidden') . '">
110 <label for="cols_min_width_select_' . $child_node->getId() . '">Largeur minimum </label>';
111 $bloc_edit .= '<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() . '">';
112 /*$bloc_edit .= '<select id="cols_min_width_select_' . $child_node->getId() . '" onchange="changeColsMinWidth(' . $child_node->getId() . ')">'
113 . $this->makeColsMinWidthOptions($child_node->getNodeData()->getColsMinWidth())
114 . '</select>';*/
115 $bloc_edit .= ' pixels</div>
116 </div>';
117 }
118 $bloc_edit .= "</div>\n";
89 } 119 }
90 120
91 ob_start(); 121 ob_start();
92 require $viewFile; 122 require $viewFile;
93 $this->html .= ob_get_clean(); 123 $this->html .= ob_get_clean();
94 } 124 }
125
126 private function makePresentationOptions(string $presentation): string
127 {
128 $options = '';
129 foreach(Presentation::$option_list as $key => $value){
130 $options .= '<option value="' . $key . '" ' . ($presentation === $key ? 'selected' : '') . '>' . $value . '</option>';
131 }
132 return $options;
133 }
95} \ No newline at end of file 134} \ No newline at end of file
diff --git a/src/view/NewBuilder.php b/src/view/NewBuilder.php
index 2d30d32..2d66238 100644
--- a/src/view/NewBuilder.php
+++ b/src/view/NewBuilder.php
@@ -7,6 +7,8 @@ use App\Entity\Node;
7 7
8class NewBuilder extends AbstractBuilder 8class NewBuilder extends AbstractBuilder
9{ 9{
10 static public bool $new_article_mode = false;
11
10 public function __construct(Node $node, ) 12 public function __construct(Node $node, )
11 { 13 {
12 $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; 14 $viewFile = self::VIEWS_PATH . $node->getName() . '.php';
@@ -39,7 +41,6 @@ class NewBuilder extends AbstractBuilder
39 $content = $node->getArticle()->getContent(); 41 $content = $node->getArticle()->getContent();
40 $from_to_button = '<p><a class="link_to_article" href="' . new URL(isset($_GET['from']) ? ['page' => $_GET['from']] : []) . '"><button>Page<br>précédente</button></a></p>'; 42 $from_to_button = '<p><a class="link_to_article" href="' . new URL(isset($_GET['from']) ? ['page' => $_GET['from']] : []) . '"><button>Page<br>précédente</button></a></p>';
41 } 43 }
42 // page d'accueil (avec des news)
43 else{ 44 else{
44 $from_to_button = '<p><a class="link_to_article" href="' . new URL(['page' => 'article', 'id' => $id, 'from' => CURRENT_PAGE]) . '"><button><img class="action_icon" src="assets/book-open.svg">Lire la suite</button></a></p>'; 45 $from_to_button = '<p><a class="link_to_article" href="' . new URL(['page' => 'article', 'id' => $id, 'from' => CURRENT_PAGE]) . '"><button><img class="action_icon" src="assets/book-open.svg">Lire la suite</button></a></p>';
45 } 46 }
@@ -101,7 +102,7 @@ class NewBuilder extends AbstractBuilder
101 $date_buttons = '<div class="button_zone">' . $modify_date . $close_editor_date . $submit_date . '</div>'; 102 $date_buttons = '<div class="button_zone">' . $modify_date . $close_editor_date . $submit_date . '</div>';
102 103
103 // mode nouvel article 104 // mode nouvel article
104 if($_GET['id'][0] != 'i'){ 105 if(self::$new_article_mode){
105 $delete_article = ''; 106 $delete_article = '';
106 // valider la création d'un nouvel article 107 // valider la création d'un nouvel article
107 $submit_js = 'onclick="submitArticle(\'' . $_GET['id'] . '\', \'' . Director::$page_path->getLast()->getEndOfPath() . '\')"'; 108 $submit_js = 'onclick="submitArticle(\'' . $_GET['id'] . '\', \'' . Director::$page_path->getLast()->getEndOfPath() . '\')"';
@@ -109,8 +110,7 @@ class NewBuilder extends AbstractBuilder
109 } 110 }
110 // mode article existant 111 // mode article existant
111 else{ 112 else{
112 // supprimer article existant 113 $url = new URL(['action' => 'delete_article', 'id' => $_GET['id'], 'from' => $_GET['from'] ?? '']);
113 $url = new URL(['action' => 'delete_article', 'id' => $_GET['id'], 'from' => $_GET['from']]);
114 $delete_article = '<form id="delete-' . $id . '" method="post" onsubmit="return confirm(\'Voulez-vous vraiment supprimer cet article ?\');" action="' . $url . '"> 114 $delete_article = '<form id="delete-' . $id . '" method="post" onsubmit="return confirm(\'Voulez-vous vraiment supprimer cet article ?\');" action="' . $url . '">
115 <p><button type="submit"> 115 <p><button type="submit">
116 <img class="action_icon" src="assets/delete-bin.svg"> 116 <img class="action_icon" src="assets/delete-bin.svg">
@@ -122,7 +122,7 @@ class NewBuilder extends AbstractBuilder
122 122
123 $admin_buttons = $delete_article . $from_to_button . $submit_article; 123 $admin_buttons = $delete_article . $from_to_button . $submit_article;
124 } 124 }
125 // page d'accueil 125 // autre page
126 else{ 126 else{
127 $modify_article = '<p id="edit-' . $id . '"></p>' . "\n"; 127 $modify_article = '<p id="edit-' . $id . '"></p>' . "\n";
128 128
@@ -143,6 +143,9 @@ class NewBuilder extends AbstractBuilder
143 $admin_buttons = $from_to_button . $modify_article . $up_button . $down_button . $delete_article . $close_editor . $submit_article; 143 $admin_buttons = $from_to_button . $modify_article . $up_button . $down_button . $delete_article . $close_editor . $submit_article;
144 } 144 }
145 } 145 }
146 else{
147 $admin_buttons = $from_to_button;
148 }
146 149
147 ob_start(); 150 ob_start();
148 require($viewFile); 151 require($viewFile);
diff --git a/src/view/NewsBlockBuilder.php b/src/view/NewsBlockBuilder.php
index 6b54196..861949a 100644
--- a/src/view/NewsBlockBuilder.php
+++ b/src/view/NewsBlockBuilder.php
@@ -21,11 +21,12 @@ class NewsBlockBuilder extends AbstractBuilder
21 extract($node->getNodeData()->getData()); 21 extract($node->getNodeData()->getData());
22 } 22 }
23 23
24 $presentation = $node->getNodeData()->getPresentation()->getName(); // affichage list ou grid 24 // stratégie d'affichage du contenu (utilisation de méthodes ou de classe List, GridPresentation, etc)
25 25 $section_class = $node->getNodeData()->getPresentation()->getName(); // = list, grid , mosaic ou carousel
26 // exécution de la stratégie (utilisation de méthodes ou de classe List, Grid, CarouselPresentation) 26 if($section_class === 'grid'){
27 $section_class = $presentation; 27 $min_width = (string)$node->getNodeData()->getColsMinWidth();
28 $section_child_class = $presentation === 'grid' ? 'grid_columns' : ''; 28 $cols_min_width = 'grid-template-columns: repeat(auto-fit, minmax(' . $min_width . 'px, 1fr));';
29 }
29 30
30 // ajouter un article 31 // ajouter un article
31 $new_article = ''; 32 $new_article = '';
diff --git a/src/view/PostBlockBuilder.php b/src/view/PostBlockBuilder.php
index 6ec91f7..8ad0498 100644
--- a/src/view/PostBlockBuilder.php
+++ b/src/view/PostBlockBuilder.php
@@ -21,11 +21,12 @@ class PostBlockBuilder extends AbstractBuilder
21 extract($node->getNodeData()->getData()); 21 extract($node->getNodeData()->getData());
22 } 22 }
23 23
24 $presentation = $node->getNodeData()->getPresentation()->getName(); // affichage list ou grid 24 // stratégie d'affichage du contenu (utilisation de méthodes ou de classe List, GridPresentation, etc)
25 25 $section_class = $node->getNodeData()->getPresentation()->getName(); // = list, grid , mosaic ou carousel
26 // exécution de la stratégie (utilisation de méthodes ou de classe List, Grid, CarouselPresentation) 26 if($section_class === 'grid'){
27 $section_class = $presentation; 27 $min_width = (string)$node->getNodeData()->getColsMinWidth();
28 $section_child_class = $presentation === 'grid' ? 'grid_columns' : ''; 28 $cols_min_width = 'grid-template-columns: repeat(auto-fit, minmax(' . $min_width . 'px, 1fr));';
29 }
29 30
30 // ajouter un article 31 // ajouter un article
31 $new_article = ''; 32 $new_article = '';
diff --git a/src/view/templates/main.php b/src/view/templates/modify_page.php
index 48ada5f..5ab1a95 100644
--- a/src/view/templates/main.php
+++ b/src/view/templates/modify_page.php
@@ -31,8 +31,8 @@
31 <input type="submit" value="Supprimer" onclick="return confirm('Voulez-vous vraiment supprimer cette page?');"> 31 <input type="submit" value="Supprimer" onclick="return confirm('Voulez-vous vraiment supprimer cette page?');">
32 </form> 32 </form>
33 </div> 33 </div>
34 <div class="edit_bloc_zone"> 34 <div class="edit_block_zone">
35 <div class="new_bloc"> 35 <div class="new_block">
36 <p>Ajouter un bloc de page</p> 36 <p>Ajouter un bloc de page</p>
37 <form method="post" action="<?= new URL(['page' => CURRENT_PAGE]) ?>"> 37 <form method="post" action="<?= new URL(['page' => CURRENT_PAGE]) ?>">
38 <p><label for="bloc_title">Titre</label> 38 <p><label for="bloc_title">Titre</label>
@@ -45,7 +45,7 @@
45 <input type="submit" value="Valider"></p> 45 <input type="submit" value="Valider"></p>
46 </form> 46 </form>
47 </div> 47 </div>
48 <div class="modify_bloc"> 48 <div class="modify_block">
49 <p>Modifier un bloc</p> 49 <p>Modifier un bloc</p>
50 <?= $bloc_edit ?> 50 <?= $bloc_edit ?>
51 </div> 51 </div>
diff --git a/src/view/templates/news_block.php b/src/view/templates/news_block.php
index d88d780..9d01513 100644
--- a/src/view/templates/news_block.php
+++ b/src/view/templates/news_block.php
@@ -5,7 +5,7 @@
5 <script> 5 <script>
6 var clone<?= $this->id_node ?> = document.currentScript.previousElementSibling.cloneNode(true); 6 var clone<?= $this->id_node ?> = document.currentScript.previousElementSibling.cloneNode(true);
7 </script> 7 </script>
8 <div class="<?= $section_child_class ?>"> 8 <div class="section_child" style="<?= $cols_min_width ?>">
9<?= $content ?> 9<?= $content ?>
10 </div> 10 </div>
11</section> \ No newline at end of file 11</section> \ No newline at end of file
diff --git a/src/view/templates/post_block.php b/src/view/templates/post_block.php
index d88d780..9d01513 100644
--- a/src/view/templates/post_block.php
+++ b/src/view/templates/post_block.php
@@ -5,7 +5,7 @@
5 <script> 5 <script>
6 var clone<?= $this->id_node ?> = document.currentScript.previousElementSibling.cloneNode(true); 6 var clone<?= $this->id_node ?> = document.currentScript.previousElementSibling.cloneNode(true);
7 </script> 7 </script>
8 <div class="<?= $section_child_class ?>"> 8 <div class="section_child" style="<?= $cols_min_width ?>">
9<?= $content ?> 9<?= $content ?>
10 </div> 10 </div>
11</section> \ No newline at end of file 11</section> \ No newline at end of file