From f477314613beb26b0ce4c61ec0b1900df1de1cb1 Mon Sep 17 00:00:00 2001 From: polo Date: Mon, 1 Sep 2025 18:52:17 +0200 Subject: =?UTF-8?q?renommage=20des=20pr=C3=A9sentations,modif=20pr=C3=A9se?= =?UTF-8?q?ntation=20des=20blocs=20et=20largeur=20min=20(donc=20nb=20de=20?= =?UTF-8?q?colonnes)=20en=20mode=20grid,=20corrections=20de=20bugs=20et=20?= =?UTF-8?q?erreurs=20404,=20le=20param=20page=5Fmodif=20n'est=20plus=20une?= =?UTF-8?q?=20action,=20l=C3=A9g=C3=A8re=20symfonyfication=20du=20routeur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/css/body.css | 28 +++-------- public/css/modif_page.css | 46 +++++++++++++----- public/js/modif_page.js | 75 +++++++++++++++++++++++------ src/controller/ArticleController.php | 5 +- src/controller/Director.php | 11 +++-- src/controller/PageManagementController.php | 65 ++++++++++++++++++++----- src/controller/ViewController.php | 24 +++++++-- src/installation.php | 8 ++- src/model/Blocks.php | 4 +- src/model/entities/Node.php | 9 ++++ src/model/entities/NodeData.php | 40 ++++++++++----- src/model/entities/Presentation.php | 22 +++++++-- src/router.php | 32 ++++++------ src/view/FooterBuilder.php | 29 ++++++++--- src/view/MainBuilder.php | 63 +++++++++++++++++++----- src/view/NewBuilder.php | 13 +++-- src/view/NewsBlockBuilder.php | 11 +++-- src/view/PostBlockBuilder.php | 11 +++-- src/view/templates/main.php | 53 -------------------- src/view/templates/modify_page.php | 53 ++++++++++++++++++++ src/view/templates/news_block.php | 2 +- src/view/templates/post_block.php | 2 +- 22 files changed, 414 insertions(+), 192 deletions(-) delete mode 100644 src/view/templates/main.php create mode 100644 src/view/templates/modify_page.php 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 background-color: #E3F3FF; padding: 15px 0; } +.hidden +{ + display: none; +} section > h3 { padding: 15px; @@ -62,28 +66,10 @@ section > h3 padding: 15px; } -.grid_columns +.grid > .section_child { - display: grid; - grid-template-columns: repeat(3, 1fr); -} -@media screen and (max-width: 800px) -{ - .grid_columns - { - grid-template-columns: repeat(2, 1fr); - } -} -@media screen and (max-width: 600px) -{ - article - { - /*margin: 5px;*/ - } - .grid_columns - { - display: block; - } + display: grid; /* et c'est tout */ + /*grid-template-columns: repeat(auto-fit, minmax(' . $min_width . 'px, 1fr)); */ /* dans PostBlockBuilder et NewsBlockBuilder */ } .galery_photos { 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 @@ padding: 10px; margin: 10px 15px; } -.page_modification form select, .page_modification form input[type=submit] +.page_modification select, .page_modification input[type=submit] { color: #ff1d04; font-size: medium; @@ -17,7 +17,7 @@ { cursor: pointer; }*/ -.page_modification form input[type=submit]:hover +.page_modification input[type=submit]:hover { background-color: yellow; border-radius: 4px; @@ -29,10 +29,10 @@ flex-wrap: wrap; justify-content: space-evenly; } -.edit_page_zone, .edit_bloc_zone, .delete_page_zone +.edit_page_zone, .edit_block_zone, .delete_page_zone { background-color: #f0f0f0f0; - margin: 5px; + margin: 8px 5px; padding: 10px; } #edit_description @@ -47,32 +47,54 @@ { vertical-align: top; } -.edit_bloc_zone +.edit_block_zone { display: flex; justify-content: space-evenly; flex-wrap: wrap; } -.edit_page_zone p, .edit_bloc_zone p, .edit_page_zone form +.edit_page_zone p, .edit_block_zone p, .edit_page_zone form { margin: 5px; } -.new_bloc #bloc_title +.new_block #bloc_title { width: 70%; max-width: 300px; } -.modify_bloc > div + +.modify_block img +{ + vertical-align: middle; +} +.delete_page_zone +{ + text-align: center; +} +.modify_one_block +{ + background-color: white; + margin: 8px 0; + padding: 5px; +} +.modify_one_block > * +{ + /*text-wrap: nowrap;*/ +} +.modify_one_block > div { display: flex; align-items: baseline; } -.modify_bloc img +.block_options > * { - vertical-align: middle; + /*display: flex; + flex-wrap: wrap;*/ + text-wrap: nowrap; } -.delete_page_zone +.grid_options { - text-align: center; + /*text-wrap: nowrap;*/ /* saut de la div grid_options */ + flex-wrap: wrap; /* éléments à l'intérieur de grid_options lorsque lui-même dépasse la largeur dispo (téléphone) */ } \ 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){ fetch('index.php?page_edit=page_title', { method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, + headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({title: page_name.value, page_id: page_id}) }) .then(response => response.json()) @@ -49,9 +47,7 @@ function changePageTitle(page_id){ fetch('index.php?page_edit=page_menu_path', { method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, + headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({page_menu_path: page_name_path.value, page_id: page_id}) }) .then(response => response.json()) @@ -88,9 +84,7 @@ function changeDescription(node_data_id){ fetch('index.php?page_edit=page_description', { method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, + headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({description: textarea.value, node_data_id: node_data_id}) }) .then(response => response.json()) @@ -117,9 +111,7 @@ function renamePageBloc(bloc_id){ fetch('index.php?bloc_edit=rename_page_bloc', { method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, + headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({bloc_title: input.value, bloc_id: bloc_id}) }) .then(response => response.json()) @@ -159,9 +151,7 @@ function switchBlocsPositions(bloc_id, direction, current_page) { fetch('index.php?page=' + current_page + '&bloc_edit=switch_blocs_positions', { method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, + headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id1: bloc_id, id2: parseInt(other_bloc.id) }) }) .then(response => response.json()) @@ -187,4 +177,59 @@ function switchBlocsPositions(bloc_id, direction, current_page) { .catch(error => { console.error('Erreur:', error); }); +} + +function changePresentation(bloc_id){ + const presentation = document.getElementById('presentation_select_' + bloc_id).value; + + fetch('index.php?bloc_edit=change_presentation', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ id: bloc_id, presentation: presentation }) + }) + .then(response => response.json()) + .then(data => { + if(data.success){ + document.getElementById(bloc_id).className = presentation; + document.getElementById('cols_min_width_edit_' + bloc_id).className = presentation === 'grid' ? '' : 'hidden'; + console.log('changement de présentation'); + } + else{ + console.log('Erreur au changement de présentation côté serveur'); + } + }) + .catch(error => { + console.error('Erreur:', error); + }); +} + +function changeColsMinWidth(bloc_id){ + const cols_min_width_input = document.getElementById('cols_min_width_select_' + bloc_id); + + if(cols_min_width_input.value < 150){ + cols_min_width_input.value = 150; + } + else if(cols_min_width_input.value > 500){ + cols_min_width_input.value = 500; + } + + fetch('index.php?bloc_edit=change_cols_min_width', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ id: bloc_id, cols_min_width: cols_min_width_input.value }) + }) + .then(response => response.json()) + .then(data => { + if(data.success){ + document.getElementById(bloc_id).className = 'grid'; + document.getElementById(bloc_id).querySelector(".section_child").style.gridTemplateColumns = 'repeat(auto-fit, minmax(' + data.cols_min_width + 'px, 1fr))'; + console.log('changement de la largeur minimum en mode grille'); + } + else{ + console.log('Erreur au changement du nb de colonnes en mode grille côté serveur'); + } + }) + .catch(error => { + console.error('Erreur:', error); + }); } \ 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 if($id[0] === 'n') { $section_id = (int)substr($id, 1); // id du bloc
- $director->findNodeById($section_id); + if(!$director->findNodeById($section_id)){ + echo json_encode(['success' => false, 'error' => 'article_not_saved']); + die; + } $director->makeSectionNode(); $node = $director->getNode(); // =
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 static public Menu $menu_data; // pour NavBuilder static public ?Path $page_path = null; // pour $current dans NavBuilder et pour BreadcrumbBuilder private Page $page; - private Node $node; + private ?Node $node; private Node $article; public function __construct(EntityManager $entityManager, bool $get_menu = false) @@ -82,8 +82,10 @@ class Director $node->getParent()->addChild($node); // spécifique page article - if($node->getName() === 'new' && $this->page->getEndOfPath() == 'article'){ - $new = $node; + if($this->page->getEndOfPath() == 'article'){ + if($node->getName() === 'new'){ + $new = $node; + } } } } @@ -93,9 +95,10 @@ class Director } // le basique - public function findNodeById(int $id): void + public function findNodeById(int $id): bool { $this->node = $this->entityManager->find('App\Entity\Node', $id); + return $this->node === null ? false : true; } // 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 } } $entityManager->flush(); - header("Location: " . new URL(['page' => $page->getPagePath(), 'action' => 'modif_page'])); + header("Location: " . new URL(['page' => $page->getPagePath(), 'mode' => 'page_modif'])); die; } @@ -104,7 +104,7 @@ class PageManagementController $entityManager->flush(); // page créée, direction la page en mode modification pour ajouter des blocs - header("Location: " . new URL(['page' => $page->getPagePath(), 'action' => 'modif_page'])); + header("Location: " . new URL(['page' => $page->getPagePath(), 'mode' => 'page_modif'])); die; } @@ -146,10 +146,10 @@ class PageManagementController if($_POST["bloc_select"] === 'calendar' || $_POST["bloc_select"] === 'form'){ $dql = 'SELECT n FROM App\Entity\Node n WHERE n.page = :page AND n.name_node = :name'; // noeud 'head' de la page $bulk_data = $entityManager - ->createQuery($dql) - ->setParameter('page', $page) - ->setParameter('name', 'head') - ->getResult(); + ->createQuery($dql) + ->setParameter('page', $page) + ->setParameter('name', 'head') + ->getResult(); if(count($bulk_data) != 1){ // 1 head par page header("Location: " . new URL(['page' => $_GET['page'], 'error' => 'head_node_not_found'])); @@ -175,16 +175,20 @@ class PageManagementController // valeurs par défaut if($_POST["bloc_select"] === 'post_block'){ - $data->setPresentation($entityManager->find('App\Entity\Presentation', 1)); // pas génial l'utilisation de l'index dans la table + $data->setPresentation(Presentation::findPresentation($entityManager, 'fullwidth')); // pas génial l'utilisation de l'index dans la table } elseif($_POST["bloc_select"] === 'news_block'){ - $data->setPresentation($entityManager->find('App\Entity\Presentation', 2)); + $data->setPresentation(Presentation::findPresentation($entityManager, 'grid')); + } + elseif($_POST["bloc_select"] === 'galery'){ + $data->setPresentation(Presentation::findPresentation($entityManager, 'mosaic')); // mieux que carousel pour commencer } + // else = null par défaut $entityManager->persist($block); $entityManager->persist($data); $entityManager->flush(); - header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); + header("Location: " . new URL(['page' => $_GET['page'], 'mode' => 'page_modif'])); die; } @@ -208,7 +212,8 @@ class PageManagementController $entityManager->remove($bloc); // suppression en BDD $entityManager->flush(); } - header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); + + header("Location: " . new URL(['page' => $_GET['page'], 'mode' => 'page_modif'])); die; } @@ -235,7 +240,7 @@ class PageManagementController static public function SwitchBlocsPositions(EntityManager $entityManager, array $json): void { if(isset($json['id1']) && is_int($json['id1']) && isset($json['id2']) && is_int($json['id2']) && isset($_GET['page'])){ - $director = new Director($entityManager, true); + $director = new Director($entityManager, true); // true pour $director->findItsChildren(); $director->findUniqueNodeByName('main'); $director->findItsChildren(); $main = $director->getNode(); @@ -269,4 +274,42 @@ class PageManagementController } die; } + + static public function changePresentation(EntityManager $entityManager, array $json): void + { + if(isset($json['id']) && isset($json['presentation'])){ + $director = new Director($entityManager, false); + $director->findNodeById($json['id']); + + $presentation = Presentation::findPresentation($entityManager, $json['presentation']); + if($presentation !== null){ + $director->getNode()->getNodeData()->setPresentation($presentation); + + $entityManager->flush(); + echo json_encode(['success' => true, 'presentation' => $json['presentation'], 'cols_min_width' => $director->getNode()->getNodeData()->getColsMinWidth()]); + } + else{ + echo json_encode(['success' => false]); + } + } + else{ + echo json_encode(['success' => false]); + } + die; + } + static public function changeColsMinWidth(EntityManager $entityManager, array $json): void + { + if(isset($json['id']) && isset($json['cols_min_width'])){ + $director = new Director($entityManager, false); + $director->findNodeById($json['id']); + $director->getNode()->getNodeData()->setColsMinWidth((int)$json['cols_min_width']); // attention conversion? + + $entityManager->flush(); + echo json_encode(['success' => true, 'cols_min_width' => $json['cols_min_width']]); + } + else{ + echo json_encode(['success' => false]); + } + die; + } } \ 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 @@ declare(strict_types=1); +use App\Entity\Article; use App\Entity\Node; use Doctrine\ORM\EntityManager; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -class ViewController extends AbstractBuilder +class ViewController extends AbstractBuilder // ViewController est aussi le premier Builder { static public Node $root_node; - public function __construct(){} + public function __construct(){} // surcharge celui de AbstractBuilder public function buildView(EntityManager $entityManager, Request $request): Response { @@ -25,13 +26,28 @@ class ViewController extends AbstractBuilder // mode modification d'une page activé if($_SESSION['admin'] && $request->query->has('page') - && $request->query->has('action') && $request->query->get('action') === 'modif_page' + && $request->query->has('mode') && $request->query->get('mode') === 'page_modif' && $request->query->get('page') !== 'connexion' && $request->query->get('page') !== 'article' && $request->query->get('page') !== 'nouvelle_page' && $request->query->get('page') !== 'menu_chemins'){ // les contrôles de la 2è ligne devraient utiliser un tableau MainBuilder::$modif_mode = true; } - // construction de la page + // page article: mode création et erreurs d'id + if($_SESSION['admin'] && $request->query->has('page') && $request->query->get('page') === 'article'){ + if(!$request->query->has('id')){ + return new Response($this->html, 302); + } + else{ + if($request->query->get('id')[0] === 'n'){ // mode création d'article (vérification de l'id du bloc dans ArticleController) + NewBuilder::$new_article_mode = true; + } + elseif(self::$root_node->getNodeByName('main')->getAdoptedChild() === null){ // id inconnu + return new Response($this->html, 302); + } + } + } + + //début de la construction de la page $this->useChildrenBuilder(self::$root_node); 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){ $bloc_new_page = new Node('new_page', NULL, [], 1, $main, $new_page, NULL); /* -- table presentation -- */ - $list = new Presentation('list'); + $fullwidth = new Presentation('fullwidth'); $grid = new Presentation('grid'); + $mosaic = new Presentation('mosaic'); + $carousel = new Presentation('carousel'); /* -- table image -- */ // paramètres: file_name, file_path, file_path_mini, mime_type, alt @@ -169,8 +171,10 @@ function makeStartPage(EntityManager $entityManager){ $entityManager->persist($bloc_new_page); /* -- table presentation -- */ - $entityManager->persist($list); + $entityManager->persist($fullwidth); $entityManager->persist($grid); + $entityManager->persist($mosaic); + $entityManager->persist($carousel); /* -- table image -- */ $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 @@ class Blocks{ /*private array $types = ['blog', 'grid', 'calendar', 'galery', 'form'];*/ - static private array $types = ['post_block', 'news_block', 'calendar', 'galery', 'form']; + static private array $types = ['post_block', 'news_block', 'galery', 'calendar', 'form']; /*private array $names = ['Blog', 'Grille', 'Calendrier', 'Galerie', 'Formulaire'];*/ - static private array $names = ['Articles libres', 'Actualités', 'Calendrier', 'Galerie', 'Formulaire']; + static private array $names = ['Articles libres', 'Actualités', 'Galerie', 'Calendrier', 'Formulaire']; static public function getNameList(): array { 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 { return $this->children; } + public function getNodeByName(string $name): ?Node + { + foreach($this->children as $child){ + if($child->getName() === $name){ + return $child; + } + } + return null; + } public function addChild(self $child): void { $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 #[ORM\JoinColumn(name: "node_id", referencedColumnName: "id_node", onDelete: "CASCADE")] private Node $node; + #[ORM\Column(type: "json")] + private array $data; + #[ORM\ManyToOne(targetEntity: Presentation::class)] #[ORM\JoinColumn(name: "presentation_id", referencedColumnName: "id_presentation", nullable: true)] - private Presentation $presentation; + private ?Presentation $presentation; - #[ORM\Column(type: "json")] - private array $data; + #[ORM\Column(type: "integer", length: 255, nullable: true)] + private ?int $grid_cols_min_width = null; // pour le mode grille // liaison avec table intermédiaire #[ORM\ManyToMany(targetEntity: Image::class, inversedBy: "node_data")] @@ -40,25 +43,20 @@ class NodeData )] private Collection $images; - public function __construct(array $data, Node $node, Collection $images = new ArrayCollection) + public function __construct(array $data, Node $node, Collection $images = new ArrayCollection, Presentation $presentation = null) { $this->data = $data; $this->node = $node; $this->images = $images; + if(!empty($presentation) && $presentation->getName() === 'grid'){ + $this->grid_cols_min_width = 250; + } } public function getId(): int { return $this->id_node_data; } - public function getPresentation(): Presentation - { - return $this->presentation; - } - public function setPresentation(Presentation $presentation): void - { - $this->presentation = $presentation; - } public function getData(): array { return $this->data; @@ -77,6 +75,24 @@ class NodeData unset($this->data[$key]); } } + public function getPresentation(): ?Presentation + { + return $this->presentation; + } + public function setPresentation(Presentation $presentation): void + { + $this->presentation = $presentation; + } + public function getColsMinWidth(): int + { + $default = 320; // pixels + return $this->grid_cols_min_width === null ? $default : $this->grid_cols_min_width; + } + public function setColsMinWidth(int $columns): void + { + $this->grid_cols_min_width = $columns; + } + /*public function setNode(Node $node): void { $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); namespace App\Entity; +use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] #[ORM\Table(name: TABLE_PREFIX . "presentation")] class Presentation { + static public array $option_list = ['fullwidth' => 'Pleine largeur', 'grid' => 'Grille', 'mosaic' => 'Mosaïque', 'carousel' => 'Carrousel']; + #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: "integer")] private int $id_presentation; #[ORM\Column(type: "string", length: 255)] - private string $name_presentation; + private string $name; public function __construct(string $name) { - $this->name_presentation = $name; + $this->name = array_keys(self::$option_list)[0]; // = fullwidth, sécurité option inconnue + foreach(self::$option_list as $key => $value){ + if($name === $key){ + $this->name = $name; + } + } } public function getName(): string { - return $this->name_presentation; + return $this->name; + } + + static public function findPresentation(EntityManager $entityManager, string $name): ?self + { + return $entityManager + ->createQuery('SELECT p FROM App\Entity\Presentation p WHERE p.name = :name') + ->setParameter('name', $name) + ->getOneOrNullResult(); } } \ 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'){ } // bouton déconnexion - if($request->query->has('action') && $request->query->get('action') === 'deconnection') - { + if($request->query->has('action') && $request->query->get('action') === 'deconnection'){ UserController::disconnect($entityManager); } @@ -40,6 +39,7 @@ if($_SERVER['REQUEST_METHOD'] === 'GET'){ // construction d'une page $response = (new ViewController)->buildView($entityManager, $request); // utilise Director + // parenthèses nécéssaires autour de l'instanciation pour PHP < 8.4 } @@ -47,8 +47,7 @@ elseif($_SERVER['REQUEST_METHOD'] === 'POST'){ /* -- contrôleurs appellables par tout le monde -- */ // table "user" vide - if(!UserController::existUsers($entityManager)) - { + if(!UserController::existUsers($entityManager)){ UserController::createUser($entityManager); } @@ -179,14 +178,18 @@ elseif($_SERVER['REQUEST_METHOD'] === 'POST'){ // partie "blocs" elseif($request->query->has('bloc_edit')) { - // renommage d'un bloc if($request->query->get('bloc_edit') === 'rename_page_bloc'){ PageManagementController::renameBloc($entityManager, $json); } - // inversion des positions de deux blocs elseif($request->query->get('bloc_edit') === 'switch_blocs_positions'){ PageManagementController::SwitchBlocsPositions($entityManager, $json); } + elseif($request->query->get('bloc_edit') === 'change_presentation'){ + PageManagementController::changePresentation($entityManager, $json); + } + elseif($request->query->get('bloc_edit') === 'change_cols_min_width'){ + PageManagementController::changeColsMinWidth($entityManager, $json); + } } } @@ -206,7 +209,7 @@ elseif($_SERVER['REQUEST_METHOD'] === 'POST'){ /* -- envoi formulaire HTML -- */ elseif($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') { - if($_GET['action'] === 'delete_article' && isset($_GET['id'])){ + if($request->query->has('action') && $request->query->get('action') === 'delete_article' && isset($_GET['id'])){ $response = ArticleController::deleteArticle($entityManager, $_GET); // version formulaire } @@ -303,13 +306,13 @@ else{ /* -- utilisation de la réponse -- */ if(isset($response)){ - if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') - { + if($request->isMethod('GET') && $response->getStatusCode() == 302){ // 302 redirection temporaire + // ne gère pour l'instant que les mauvais id de la page article + header('Location: ' . new URL(['page' => !empty($_GET['from']) ? $_GET['from'] : 'accueil'])); + } + elseif($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded'){ $response_data = json_decode(($response)->getContent(), true); - $url = new URL; - if(isset($_GET['from'])){ - $url->addParams(['page' => $_GET['from']]); - } + $url = new URL(['page' => !empty($_GET['from']) ? $_GET['from'] : 'accueil']); $url->addParams(['success' => $response_data['success'], 'message' => $response_data['message']]); header('Location: ' . $url); } @@ -318,8 +321,7 @@ if(isset($response)){ } } else{ - if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') - { + if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded'){ header("Location: " . new URL(['error' => 'erreur côté serveur'])); } 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 // zone admin $empty_admin_zone = ''; - //$zone_admin = ''; if($_SESSION['admin']) { $empty_admin_zone = 'empty_admin_zone'; - $link_edit_page = CURRENT_PAGE === 'article' ? new URL(['page' => 'accueil']) : new URL(['page' => CURRENT_PAGE]); if(MainBuilder::$modif_mode){ $mode = 'modification de page'; $div_admin = 'logged_in modif_mode'; - $link_edit_label = 'Sortir du mode modification'; } else{ $mode = 'administrateur'; $div_admin = 'logged_in'; - $link_edit_page->addParams(['action' => 'modif_page']); - $link_edit_label = 'Modifier la page'; } $link_new_page = new URL(['page' => 'nouvelle_page']); $link_change_paths = new URL(['page' => 'menu_chemins']); @@ -51,9 +46,9 @@ class FooterBuilder extends AbstractBuilder $zone_admin = '

Vous êtes en mode ' . $mode . ".

\n" . - '
' . "\n" . - '
' . "\n" . - '
' . "\n" . + '
' . "\n"; + $zone_admin .= $this->makePageModifModeButton(); + $zone_admin .= '
' . "\n" . '
' . "\n" . '
' . "\n" . '
' . "\n"; @@ -73,4 +68,22 @@ class FooterBuilder extends AbstractBuilder $this->html = ob_get_clean(); } } + + private function makePageModifModeButton(): string + { + $link_edit_page = new URL(['page' => CURRENT_PAGE]); + if(CURRENT_PAGE !== 'article'){ + if(MainBuilder::$modif_mode){ + $link_edit_label = 'Sortir du mode modification'; + } + else{ + $link_edit_page->addParams(['mode' => 'page_modif']); + $link_edit_label = 'Modifier la page'; + } + return '
' . "\n"; + } + else{ + return ''; + } + } } \ 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); use App\Entity\Article; use App\Entity\Node; +use App\Entity\Presentation; class MainBuilder extends AbstractBuilder { - static bool $modif_mode = false; + static public bool $modif_mode = false; public function __construct(Node $node) { @@ -52,7 +53,8 @@ class MainBuilder extends AbstractBuilder // mode modification de page uniquement private function viewEditBlocks($node): void { - $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; // mode modification uniquement + //$viewFile = self::VIEWS_PATH . $node->getName() . '.php'; // mode modification uniquement + $viewFile = self::VIEWS_PATH . 'modify_page.php'; // mode modification uniquement $blocks = Blocks::getTypeNamePairs(); $options = ''; @@ -71,25 +73,62 @@ class MainBuilder extends AbstractBuilder $bloc_edit = ''; foreach($node->getChildren() as $child_node){ + // mettre tout ça dans une vue modify_block.php + // => pourrait être déplacé au niveau des articles + // renommage d'un bloc - $bloc_edit .= '
-

- - '. "\n"; + $bloc_edit .= '

+
+ +

+ + +

'. "\n"; // déplacement d'un bloc - $bloc_edit .= ' - ' . "\n"; + $bloc_edit .= '
+

+ + +

' . "\n"; // suppression d'un bloc $bloc_edit .= '
- - -

-
+ + + + +
'. "\n"; + if($child_node->getNodeData()->getPresentation() !== null){ + // select mode de présentation + $bloc_edit .= '

+ + '; + // select largeur minimale colonnes mode grid + $bloc_edit .= '

+ '; + $bloc_edit .= ''; + /*$bloc_edit .= '';*/ + $bloc_edit .= ' pixels
+
'; + } + $bloc_edit .= "
\n"; } ob_start(); require $viewFile; $this->html .= ob_get_clean(); } + + private function makePresentationOptions(string $presentation): string + { + $options = ''; + foreach(Presentation::$option_list as $key => $value){ + $options .= ''; + } + return $options; + } } \ 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; class NewBuilder extends AbstractBuilder { + static public bool $new_article_mode = false; + public function __construct(Node $node, ) { $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; @@ -39,7 +41,6 @@ class NewBuilder extends AbstractBuilder $content = $node->getArticle()->getContent(); $from_to_button = '

'; } - // page d'accueil (avec des news) else{ $from_to_button = '

'; } @@ -101,7 +102,7 @@ class NewBuilder extends AbstractBuilder $date_buttons = '
' . $modify_date . $close_editor_date . $submit_date . '
'; // mode nouvel article - if($_GET['id'][0] != 'i'){ + if(self::$new_article_mode){ $delete_article = ''; // valider la création d'un nouvel article $submit_js = 'onclick="submitArticle(\'' . $_GET['id'] . '\', \'' . Director::$page_path->getLast()->getEndOfPath() . '\')"'; @@ -109,8 +110,7 @@ class NewBuilder extends AbstractBuilder } // mode article existant else{ - // supprimer article existant - $url = new URL(['action' => 'delete_article', 'id' => $_GET['id'], 'from' => $_GET['from']]); + $url = new URL(['action' => 'delete_article', 'id' => $_GET['id'], 'from' => $_GET['from'] ?? '']); $delete_article = '

-

- - - - - -
-
-
- -
- - -
-
- -
-
- - - - -
-
-
-
-

Ajouter un bloc de page

-
-

-

-

- - -

-
-
-
-

Modifier un bloc

- -
-
-
\ No newline at end of file diff --git a/src/view/templates/modify_page.php b/src/view/templates/modify_page.php new file mode 100644 index 0000000..5ab1a95 --- /dev/null +++ b/src/view/templates/modify_page.php @@ -0,0 +1,53 @@ + +
+

Modification de la page

+
+
+

+ + + +

+
+ + + + +
+
+
+ +
+ + +
+
+
+
+
+ + + + +
+
+
+
+

Ajouter un bloc de page

+
+

+

+

+ + +

+
+
+
+

Modifier un bloc

+ +
+
+
\ No newline at end of file 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 @@ -
+
\ 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 @@ -
+
\ No newline at end of file -- cgit v1.2.3