diff options
author | polo <ordipolo@gmx.fr> | 2025-09-01 18:52:17 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2025-09-01 18:52:17 +0200 |
commit | f477314613beb26b0ce4c61ec0b1900df1de1cb1 (patch) | |
tree | d41ace78a572a11887e7cfa2611c3f02fb04e51c /src/controller | |
parent | e642cd51d7e8599537f8514bef8d5d16096dddf8 (diff) | |
download | cms-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
Diffstat (limited to 'src/controller')
-rw-r--r-- | src/controller/ArticleController.php | 5 | ||||
-rw-r--r-- | src/controller/Director.php | 11 | ||||
-rw-r--r-- | src/controller/PageManagementController.php | 65 | ||||
-rw-r--r-- | src/controller/ViewController.php | 24 |
4 files changed, 85 insertions, 20 deletions
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 | ||
6 | declare(strict_types=1); | 6 | declare(strict_types=1); |
7 | 7 | ||
8 | use App\Entity\Article; | ||
8 | use App\Entity\Node; | 9 | use App\Entity\Node; |
9 | use Doctrine\ORM\EntityManager; | 10 | use Doctrine\ORM\EntityManager; |
10 | use Symfony\Component\HttpFoundation\Request; | 11 | use Symfony\Component\HttpFoundation\Request; |
11 | use Symfony\Component\HttpFoundation\Response; | 12 | use Symfony\Component\HttpFoundation\Response; |
12 | 13 | ||
13 | class ViewController extends AbstractBuilder | 14 | class 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); |