From 0f497d215de8e16739263e2718bd39640a6cc4d8 Mon Sep 17 00:00:00 2001 From: polo Date: Thu, 8 May 2025 22:58:04 +0200 Subject: modif page, renommage et suppression, du responsive design, modif dans Director, notif toast --- src/controller/Director.php | 26 ++++++++++++++++---------- src/controller/ajax.php | 39 +++++++++++++++++++++++++++++++++++++-- src/controller/post.php | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 83 insertions(+), 16 deletions(-) (limited to 'src/controller') diff --git a/src/controller/Director.php b/src/controller/Director.php index 56a90cb..b154432 100644 --- a/src/controller/Director.php +++ b/src/controller/Director.php @@ -36,6 +36,7 @@ class Director return $this->article; } + // affichage d'une page ordinaire public function makeRootNode(string $id = ''): void { // on récupère toutes les entrées @@ -91,6 +92,12 @@ class Director } } + // le basique + public function findNodeById(int $id): void + { + $this->node = $this->entityManager->find('App\Entity\Node', $id); + } + // récupération d'un article pour modification public function makeArticleNode(string $id = '', bool $get_section = false): bool { @@ -112,7 +119,8 @@ class Director if($get_section){ $this->article = $bulk_data[0]; - $this->makeSectionNode($bulk_data[0]->getParent()->getId()); + $this->findNodeById($bulk_data[0]->getParent()->getId()); + $this->makeSectionNode(); } else{ $this->article = $bulk_data[0]; @@ -122,31 +130,30 @@ class Director } // récupération des articles d'un bloc
à la création d'un article - public function makeSectionNode(int $section_id): bool + public function makeSectionNode(): bool { - $section = $this->entityManager->find('App\Entity\Node', (string)$section_id); - $bulk_data = $this->entityManager ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.parent = :parent') - ->setParameter('parent', $section) + ->setParameter('parent', $this->node) ->getResult(); foreach($bulk_data as $article){ - $section->addChild($article); // pas de flush, on ne va pas écrire dans la BDD à chaque nouvelle page + $this->node->addChild($article); // pas de flush, on ne va pas écrire dans la BDD à chaque nouvelle page } - $this->node = $section; return true; } - public function findNodeByName(string $name): void + public function findUniqueNodeByName(string $name): void // = unique en BDD, donc sans "page" associée { $bulk_data = $this->entityManager ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.name_node = :name') ->setParameter('name', $name) ->getResult(); $this->node = $bulk_data[0]; - echo $this->page->getPageName() . ' '; + } + public function findItsChildren(): void + { $bulk_data = $this->entityManager ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.parent = :parent AND n.page = :page') ->setParameter('parent', $this->node) @@ -154,7 +161,6 @@ class Director ->getResult(); foreach($bulk_data as $child){ $this->node->addChild($child); - echo $child->getName() . ' '; } } } diff --git a/src/controller/ajax.php b/src/controller/ajax.php index a20bd87..a6786d9 100644 --- a/src/controller/ajax.php +++ b/src/controller/ajax.php @@ -35,7 +35,8 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['action'])) if($id[0] === 'n') { $section_id = (int)substr($id, 1); // id du bloc
- $director->makeSectionNode($section_id); + $director->findNodeById($section_id); + $director->makeSectionNode(); $node = $director->getNode(); // =
if(is_array($content)){ @@ -205,6 +206,8 @@ if(strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false && isset($_ die; } + +/* -- page Menu et chemins -- */ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit'])) { // récupération des données @@ -347,7 +350,39 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit'])) } } -// détection des requêtes de type XHR?, pas d'utilité pour l'instant + +/* -- mode Modification d'une page -- */ +if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['bloc_edit'])) +{ + // récupération des données + $data = file_get_contents('php://input'); + $json = json_decode($data, true); + + // renommage d'un bloc + if($_GET['bloc_edit'] === 'rename_page_bloc') + { + if(isset($json['bloc_title']) && $json['bloc_title'] !== null && isset($json['bloc_id']) && is_int($json['bloc_id'])){ + $director = new Director($entityManager); + $director->findNodeById($json['bloc_id']); + + // le titre (du JSON en BDD) est récupéré sous forme de tableau, modifié et renvoyé + $data = $director->getNode()->getNodeData()->getData(); + $data['title'] = htmlspecialchars($json['bloc_title']); + $director->getNode()->getNodeData()->setData($data); + + $entityManager->flush(); + echo json_encode(['success' => true, 'title' => $data['title']]); + } + else{ + echo json_encode(['success' => false]); + } + die; + } + +} + + +// détection des requêtes de type XHR?, pas d'utilité à priori /*elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){ echo "requête XHR reçue par le serveur"; die; diff --git a/src/controller/post.php b/src/controller/post.php index 76ac72b..d437423 100644 --- a/src/controller/post.php +++ b/src/controller/post.php @@ -15,10 +15,13 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) /* -- mode Modification d'une page -- */ // ajout d'un bloc dans une page - if(isset($_POST['bloc_title']) && isset($_POST['bloc_select'])){ + if(isset($_POST['bloc_title']) && $_POST['bloc_title'] !== null && isset($_POST['bloc_select']) && $_POST['bloc_select'] !== null + && isset($_POST['bloc_title_hidden']) && $_POST['bloc_title_hidden'] === '') // contrôle anti-robot avec input hidden + { $director = new Director($entityManager, true); // on a besoin de page_path qui dépend de menu_data $page = Director::$page_path->getLast(); - $director->findNodeByName('main'); + $director->findUniqueNodeByName('main'); + $director->findItsChildren(); $main = $director->getNode(); $position = count($main->getChildren()) + 1; // position dans la fraterie @@ -37,7 +40,30 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) $entityManager->flush(); header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); } + // suppression d'un bloc de page + elseif(isset($_POST['delete_bloc_id']) && $_POST['delete_bloc_id'] !== null + && isset($_POST['delete_bloc_hidden']) && $_POST['delete_bloc_hidden'] === '') // contrôle anti-robot avec input hidden + { + $director = new Director($entityManager, true); + $director->findUniqueNodeByName('main'); + $director->findItsChildren(); + //$director->findNodeById((int)$_POST['delete_bloc_id']); + $main = $director->getNode(); + $bloc; + foreach($main->getChildren() as $child){ + if($child->getId() === (int)$_POST['delete_bloc_id']){ + $bloc = $child; + break; + } + } + $main->removeChild($bloc); // réindex le tableau $children au passage + $main->reindexPositions(); + $entityManager->remove($bloc); // suppression en BDD + $entityManager->flush(); + header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); + } + /* -- page Menu et chemins -- */ @@ -60,7 +86,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) $parent = Director::$menu_data; } $parent->addChild($page); // true pour réindexer les positions en BDD - $parent->reindex(); + $parent->reindexPositions(); $entityManager->persist($page); $entityManager->flush(); @@ -76,7 +102,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) } $parent->removeChild($page); // suppression de $children avant de trier - $parent->reindex(); + $parent->reindexPositions(); $entityManager->remove($page); // suppression en BDD $entityManager->flush(); -- cgit v1.2.3