From eb3e1eb8c8365d3b3d1d39f24314ba420255afc2 Mon Sep 17 00:00:00 2001 From: polo Date: Mon, 21 Apr 2025 20:36:10 +0200 Subject: page menu et chemin, partie1 --- src/controller/Director.php | 2 +- src/controller/ajax.php | 44 ++++++++++++++++++++++++++++++++++++++++- src/controller/installation.php | 10 ++++++++-- src/controller/password.php | 2 +- 4 files changed, 53 insertions(+), 5 deletions(-) (limited to 'src/controller') diff --git a/src/controller/Director.php b/src/controller/Director.php index b7be9b8..a2528ed 100644 --- a/src/controller/Director.php +++ b/src/controller/Director.php @@ -11,7 +11,7 @@ class Director { private EntityManager $entityManager; static public Menu $menu_data; // pour NavBuilder - static public Path $page_path; // pour BreadcrumbBuilder + static public ?Path $page_path = null; // pour $current dans NavBuilder et pour BreadcrumbBuilder private Page $page; private Node $node; private Node $article; diff --git a/src/controller/ajax.php b/src/controller/ajax.php index a4b61e4..c774bf3 100644 --- a/src/controller/ajax.php +++ b/src/controller/ajax.php @@ -6,7 +6,7 @@ declare(strict_types=1); use App\Entity\Article; use App\Entity\Node; -// détection des requêtes de tinymce +// détection des requêtes de tinymce ou touchant aux articles if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['action'])) { // récupération des données @@ -204,6 +204,48 @@ if(strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false && isset($_ die; } +if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit'])) +{ + // récupération des données + $data = file_get_contents('php://input'); + $json = json_decode($data, true); + + if($_GET['menu_edit'] === 'switch_positions' && isset($json['id1']) && isset($json['id2'])) + { + //$menu = new Menu($entityManager); + Director::$menu_data = new Menu($entityManager); + + $id1 = $json['id1']; + $id2 = $json['id2']; + + // vérifier qu'ils ont le même parent + $page1 = Director::$menu_data->findPageById((int)$id1); + $page2 = Director::$menu_data->findPageById((int)$id2); + + // double le contrôle fait en JS + if($page1->getParent() === $page2->getParent()) // comparaison stricte d'objet (même instance du parent?) + { + // inversion + $tmp = $page1->getPosition(); + $page1->setPosition($page2->getPosition()); + $page2->setPosition($tmp); + Director::$menu_data->sortChildren(true); // modifie tableau children + $entityManager->flush(); + + // menu utilisant les nouvelles données + //Director::$page_path = new Path(); + $nav_builder = new NavBuilder(); // builder appelé sans envoi du noeud correspondant + + echo json_encode(['success' => true, 'path1' => '', 'path2' => '', 'nav' => $nav_builder->render()]); + } + else{ + echo json_encode(['success' => false]); + } + + die; + } +} + // détection des requêtes de type XHR, pas d'utilité pour l'instant /*elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){ echo "requête XHR reçue par le serveur"; diff --git a/src/controller/installation.php b/src/controller/installation.php index c2b38fd..ff168eb 100644 --- a/src/controller/installation.php +++ b/src/controller/installation.php @@ -80,9 +80,9 @@ function makeStartPage(EntityManager $entityManager){ $accueil = new Page('Accueil', 'accueil', true, true, 1, NULL); $connection = new Page('Connexion', 'connexion', true, false, NULL, NULL); $article = new Page('Article', 'article', true, false, NULL, NULL); + $menu_paths = new Page("Menu et chemins", 'menu_chemins', true, false, NULL, NULL); $edit_page = new Page("Modification d'une page", 'modif_page', true, false, NULL, NULL); $new_page = new Page('Nouvelle page', 'nouvelle_page', true, false, NULL, NULL); - $edit_paths = new Page("Menu et chemins", 'menu_chemins', true, false, NULL, NULL); /* -- table node -- */ // paramètres: name_node, article_timestamp, attributes, position, parent, page, article @@ -95,6 +95,8 @@ function makeStartPage(EntityManager $entityManager){ $head_login = new Node('head', NULL, ["stop" => true, 'css_array' => ['body', 'head', 'nav', 'main'], 'js_array' => ['main']], 1, NULL, $connection, NULL); $login = new Node('login', NULL, [], 1, $main, $connection, NULL); $head_article = new Node('head', NULL, ['css_array' => ['body', 'head', 'nav', 'main', 'foot'], 'js_array' => ['main']], 1, NULL, $article, NULL); + $head_edit_menu = new Node('head', NULL, ['css_array' => ['body', 'head', 'nav', 'main', 'menu'], 'js_array' => ['main']], 1, NULL, $menu_paths, NULL); + $edit_menu = new Node('menu', NULL, [], 1, $main, $menu_paths, NULL); /* -- table image -- */ // paramètres: file_name, file_path, file_path_mini, mime_type, alt @@ -111,13 +113,14 @@ function makeStartPage(EntityManager $entityManager){ $footer_data = new NodeData(["adresse" => "17, rue Raymonde Folgoas Guillou, 29120 Pont-l’Abbé", "contact_nom" => "Les Nageurs Bigoudens", "e_mail" => "nb.secretariat@orange.fr", "logo_footer" => "assets/logo-nb-et-ffn.png"], $footer); $head_login_data = new NodeData(["description" => "Connexion", "title" => "Connexion"], $head_login, new ArrayCollection([$favicon])); $head_article_data = new NodeData(["description" => "", "title" => ""], $head_article, new ArrayCollection([$favicon])); + $head_edit_menu_data = new NodeData(["description" => "Menu et chemins", "title" => "Menu et chemins"], $head_edit_menu, new ArrayCollection([$favicon])); $entityManager->persist($accueil); $entityManager->persist($connection); $entityManager->persist($article); + $entityManager->persist($menu_paths); $entityManager->persist($edit_page); $entityManager->persist($new_page); - $entityManager->persist($edit_paths); $entityManager->persist($head_accueil); $entityManager->persist($header); $entityManager->persist($nav); @@ -127,6 +130,8 @@ function makeStartPage(EntityManager $entityManager){ $entityManager->persist($head_login); $entityManager->persist($login); $entityManager->persist($head_article); + $entityManager->persist($head_edit_menu); + $entityManager->persist($edit_menu); $entityManager->persist($favicon); $entityManager->persist($logo); $entityManager->persist($facebook); @@ -137,6 +142,7 @@ function makeStartPage(EntityManager $entityManager){ $entityManager->persist($footer_data); $entityManager->persist($head_login_data); $entityManager->persist($head_article_data); + $entityManager->persist($head_edit_menu_data); $entityManager->flush(); header('Location: ' . new URL); diff --git a/src/controller/password.php b/src/controller/password.php index 47db637..66a617a 100644 --- a/src/controller/password.php +++ b/src/controller/password.php @@ -307,7 +307,7 @@ function getUser(string $login, EntityManager $entityManager): ?User } -function disconnect(EntityManager $entityManager) +function disconnect() { // nettoyage complet $_SESSION = []; // mémoire vive -- cgit v1.2.3