From f0d1cd5d68579b462cf01a4a9f7d558a231bc072 Mon Sep 17 00:00:00 2001 From: polo Date: Thu, 9 Oct 2025 14:40:54 +0200 Subject: =?UTF-8?q?description=20de=20page=20d=C3=A9plac=C3=A9e=20dans=20l?= =?UTF-8?q?a=20table=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/modif_page.js | 4 ++-- src/controller/ArticleController.php | 4 ++-- src/controller/PageManagementController.php | 17 ++++++++-------- src/installation.php | 30 ++++++++++++++--------------- src/model/entities/Page.php | 14 +++++++++++++- src/router.php | 2 +- src/view/HeadBuilder.php | 8 +------- src/view/MainBuilder.php | 8 -------- src/view/templates/modify_page.php | 4 ++-- 9 files changed, 45 insertions(+), 46 deletions(-) diff --git a/public/js/modif_page.js b/public/js/modif_page.js index 15f3598..aad53e9 100644 --- a/public/js/modif_page.js +++ b/public/js/modif_page.js @@ -79,13 +79,13 @@ function changePageTitle(page_id){ console.error('Erreur:', error); }); }*/ -function changeDescription(node_data_id){ +function changeDescription(page_id){ const textarea = document.getElementById("description_textarea"); fetch('index.php?page_edit=page_description', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({description: textarea.value, node_data_id: node_data_id}) + body: JSON.stringify({description: textarea.value, page_id: page_id}) }) .then(response => response.json()) .then(data => { diff --git a/src/controller/ArticleController.php b/src/controller/ArticleController.php index 8bbef19..fabd997 100644 --- a/src/controller/ArticleController.php +++ b/src/controller/ArticleController.php @@ -151,10 +151,10 @@ class ArticleController die; } - static public function deleteArticle(EntityManager $entityManager, array $json): Response + static public function deleteArticle(EntityManager $entityManager, array $data): Response // $data peut être un $_GET ou du JSON { $director = new Director($entityManager); - if(!$director->makeArticleNode($json['id'], true)){ + if(!$director->makeArticleNode($data['id'], true)){ return new Response( '{"success": false, "message": "Erreur: pas d\'article à supprimer"}', Response::HTTP_INTERNAL_SERVER_ERROR); // 500 diff --git a/src/controller/PageManagementController.php b/src/controller/PageManagementController.php index 8efcb79..e6886b1 100644 --- a/src/controller/PageManagementController.php +++ b/src/controller/PageManagementController.php @@ -45,25 +45,26 @@ class PageManagementController static public function setPageDescription(EntityManager $entityManager, array $json): void { - $node_data = $entityManager->find('App\Entity\NodeData', $json['node_data_id']); - $node_data->updateData('description', htmlspecialchars($json['description'])); + $page = $entityManager->find('App\Entity\Page', $json['page_id']); + $page->setDescription(htmlspecialchars($json['description'])); $entityManager->flush(); - echo json_encode(['success' => true, 'description' => $node_data->getData()['description']]); + echo json_encode(['success' => true, 'description' => $page->getDescription()]); die; } - static public function newPage(EntityManager $entityManager): void + static public function newPage(EntityManager $entityManager, array $post): void { // titre et chemin $director = new Director($entityManager); $director->makeMenuAndPaths(); //Director::$menu_data = new Menu($entityManager); - $previous_page = Director::$menu_data->findPageById((int)$_POST["page_location"]); // (int) à cause de declare(strict_types=1); + $previous_page = Director::$menu_data->findPageById((int)$post["page_location"]); // (int) à cause de declare(strict_types=1); $parent = $previous_page->getParent(); $page = new Page( - trim(htmlspecialchars($_POST["page_name"])), - trim(htmlspecialchars($_POST["page_name_path"])), + trim(htmlspecialchars($post["page_name"])), + trim(htmlspecialchars($post["page_name_path"])), + trim(htmlspecialchars($post["page_description"])), true, true, false, $previous_page->getPosition(), $parent); // peut et DOIT être null si on est au 1er niveau @@ -86,7 +87,7 @@ class PageManagementController $page); $node->useDefaultAttributes(); // fichiers CSS et JS - $data = new NodeData(['description' => trim(htmlspecialchars($_POST["page_description"]))], $node); + $data = new NodeData([], $node); $bulk_data = $entityManager ->createQuery('SELECT n FROM App\Entity\Image n WHERE n.file_name LIKE :name') diff --git a/src/installation.php b/src/installation.php index 452df60..dd0ca77 100644 --- a/src/installation.php +++ b/src/installation.php @@ -90,13 +90,13 @@ HTACCESS; function makeStartPage(EntityManager $entityManager){ /* -- table page -- */ // paramètres: name_page, end_of_path, reachable, in_menu, hidden, position, parent - $accueil = new Page('Accueil', 'accueil', true, true, false, 1, NULL); - $article = new Page('Article', 'article', true, false, false, NULL, NULL); - $connection = new Page('Connexion', 'connection', true, false, false, NULL, NULL); - $my_account = new Page('Mon compte', 'user_edit', true, false, false, NULL, NULL); - $menu_paths = new Page("Menu et chemins", 'menu_chemins', true, false, false, NULL, NULL); - //$edit_page = new Page("Modification d'une page", 'modif_page', true, false, false, NULL, NULL); // pas de page "Modification de la page" - $new_page = new Page('Nouvelle page', 'nouvelle_page', true, false, false, NULL, NULL); + $accueil = new Page('Accueil', 'accueil', "Page d'accueil", true, true, false, 1, NULL); + $article = new Page('Article', 'article', "", true, false, false, NULL, NULL); + $connection = new Page('Connexion', 'connection', "Connexion", true, false, false, NULL, NULL); + $my_account = new Page('Mon compte', 'user_edit', "Mon compte", true, false, false, NULL, NULL); + $menu_paths = new Page("Menu et chemins", 'menu_chemins', "Menu et chemins", true, false, false, NULL, NULL); + //$edit_page = new Page("Modification d'une page", 'modif_page', '', true, false, false, NULL, NULL); // hypothétique page "Modification de la page" + $new_page = new Page('Nouvelle page', 'nouvelle_page', "Nouvelle page", true, false, false, NULL, NULL); /* -- table node -- */ // paramètres: name_node, article_timestamp, attributes, position, parent, page, article @@ -126,15 +126,15 @@ function makeStartPage(EntityManager $entityManager){ /* -- table node_data -- */ // paramètres: data, node, images - $head_accueil_data = new NodeData(["description" => "Page d'accueil"], $head_accueil, new ArrayCollection([$favicon])); - $head_login_data = new NodeData(["description" => "Connexion"], $head_login, new ArrayCollection([$favicon])); - $head_my_account_data = new NodeData(["description" => "Mon compte"], $head_my_account, new ArrayCollection([$favicon])); - $head_article_data = new NodeData(["description" => ""], $head_article, new ArrayCollection([$favicon])); - $head_edit_menu_data = new NodeData(["description" => "Menu et chemins"], $head_edit_menu, new ArrayCollection([$favicon])); - $head_new_page_data = new NodeData(["description" => "Nouvelle page"], $head_new_page, new ArrayCollection([$favicon])); + $head_accueil_data = new NodeData([], $head_accueil, new ArrayCollection([$favicon])); + $head_login_data = new NodeData([], $head_login, new ArrayCollection([$favicon])); + $head_my_account_data = new NodeData([], $head_my_account, new ArrayCollection([$favicon])); + $head_article_data = new NodeData([], $head_article, new ArrayCollection([$favicon])); + $head_edit_menu_data = new NodeData([], $head_edit_menu, new ArrayCollection([$favicon])); + $head_new_page_data = new NodeData([], $head_new_page, new ArrayCollection([$favicon])); $header_data = new NodeData(["title" => "Titre", "description" => "Sous-titre", "header_logo" => "assets/logo-nb-et-ffn.png", "header_background" => "assets/fond-piscine.jpg", "social" => ["facebook" => "https://www.facebook.com", "instagram" => "https://www.instagram.com", "linkedin" => "https://www.linkedin.com"]], - $header, new ArrayCollection([$facebook, $instagram, $linkedin, $github])); + $header, new ArrayCollection([$facebook, $instagram, $linkedin, $github])); $footer_data = new NodeData(["contact_nom" => "Nom", "adresse" => "adresse", "e_mail" => "e-mail", "footer_logo" => "assets/logo-nb-et-ffn.png"], $footer); /* -- table page -- */ @@ -143,7 +143,7 @@ function makeStartPage(EntityManager $entityManager){ $entityManager->persist($connection); $entityManager->persist($my_account); $entityManager->persist($menu_paths); - //$entityManager->persist($edit_page); // pas de page "Modification de la page" + //$entityManager->persist($edit_page); // hypothétique page "Modification de la page" $entityManager->persist($new_page); /* -- table node -- */ diff --git a/src/model/entities/Page.php b/src/model/entities/Page.php index bcf49db..5b54ae6 100644 --- a/src/model/entities/Page.php +++ b/src/model/entities/Page.php @@ -28,6 +28,9 @@ class Page private string $page_path = ''; + #[ORM\Column(type: "text")] + private string $description; + #[ORM\Column(type: "boolean")] private bool $reachable; @@ -50,10 +53,11 @@ class Page /*#[ORM\Column(type: "json", nullable: true)] private ?array $metadata = null;*/ - public function __construct(string $name, string $eop, bool $reachable, bool $in_menu, bool $hidden, ?int $position, ?Page $parent) + public function __construct(string $name, string $eop, string $description, bool $reachable, bool $in_menu, bool $hidden, ?int $position, ?Page $parent) { $this->name_page = $name; $this->end_of_path = $eop; + $this->description = $description; $this->reachable = $reachable; $this->in_menu = $in_menu; $this->hidden = $hidden; @@ -91,6 +95,14 @@ class Page { $this->end_of_path = $end_of_path; } + public function getDescription(): string + { + return $this->description; + } + public function setDescription(string $description): void + { + $this->description = $description; + } public function isReachable(): bool { return $this->reachable; diff --git a/src/router.php b/src/router.php index 8d19e49..c11a4e0 100644 --- a/src/router.php +++ b/src/router.php @@ -232,7 +232,7 @@ elseif($request->getMethod() === 'POST'){ && isset($_POST['page_description']) && $_POST['page_description'] !== null && isset($_POST['new_page_hidden']) && $_POST['new_page_hidden'] === '') { - PageManagementController::newPage($entityManager); + PageManagementController::newPage($entityManager, $_POST); } /* -- suppression d'une page -- */ diff --git a/src/view/HeadBuilder.php b/src/view/HeadBuilder.php index 06a1301..b2f3386 100644 --- a/src/view/HeadBuilder.php +++ b/src/view/HeadBuilder.php @@ -47,14 +47,8 @@ class HeadBuilder extends AbstractBuilder $js .= '' . "\n"; } - // titre $title = Director::$page_path->getLast()->getPageName(); - - // description - if(!empty($node->getNodeData()->getData())) - { - extract($node->getNodeData()->getData()); - } + $description = Director::$page_path->getLast()->getDescription(); // favicon foreach($node->getNodeData()->getImages() as $image) diff --git a/src/view/MainBuilder.php b/src/view/MainBuilder.php index a04130a..d677971 100644 --- a/src/view/MainBuilder.php +++ b/src/view/MainBuilder.php @@ -59,14 +59,6 @@ class MainBuilder extends AbstractBuilder foreach(Blocks::$blocks as $key => $value){ $options .= '\n"; } - - $head_node = null; - foreach(ViewController::$root_node->getChildren() as $first_level_node){ - if($first_level_node->getName() === 'head'){ - $head_node = $first_level_node; // normalement c'est le 1er enfant - break; - } - } // ceci pourrait être déplacé au début des blocs $bloc_edit = ''; diff --git a/src/view/templates/modify_page.php b/src/view/templates/modify_page.php index b799df2..c9da4a4 100644 --- a/src/view/templates/modify_page.php +++ b/src/view/templates/modify_page.php @@ -18,8 +18,8 @@
- - + +
-- cgit v1.2.3