diff options
| author | polo <ordipolo@gmx.fr> | 2025-11-02 20:08:52 +0100 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2025-11-02 20:08:52 +0100 |
| commit | 28d300b48ded1d472d3593f3afc0c71c4fd2e0aa (patch) | |
| tree | e8c3a19c3d6d45126837275eee412ef44e046f96 | |
| parent | b9a5dd61e04ba09be0ffba300bd1da49e4de090c (diff) | |
| download | cms-28d300b48ded1d472d3593f3afc0c71c4fd2e0aa.tar.gz cms-28d300b48ded1d472d3593f3afc0c71c4fd2e0aa.tar.bz2 cms-28d300b48ded1d472d3593f3afc0c71c4fd2e0aa.zip | |
blocage suppression dernière page, page par défaut = première entrée du menu et non plus "accueil"
| -rw-r--r-- | public/index.php | 2 | ||||
| -rw-r--r-- | src/controller/PageManagementController.php | 45 | ||||
| -rw-r--r-- | src/installation.php | 4 | ||||
| -rw-r--r-- | src/model/Path.php | 23 | ||||
| -rw-r--r-- | src/view/FooterBuilder.php | 6 | ||||
| -rw-r--r-- | src/view/templates/modify_page.php | 2 |
6 files changed, 48 insertions, 34 deletions
diff --git a/public/index.php b/public/index.php index 61fa01f..b5b1f7e 100644 --- a/public/index.php +++ b/public/index.php | |||
| @@ -62,5 +62,5 @@ if($_SESSION['admin'] === false || empty($_SESSION['user'])){ // OUT !! | |||
| 62 | 62 | ||
| 63 | /* -- partie 2: routage et contrôleurs -- */ | 63 | /* -- partie 2: routage et contrôleurs -- */ |
| 64 | 64 | ||
| 65 | define('CURRENT_PAGE', htmlspecialchars($request->query->get('page') ?? 'accueil')); | 65 | define('CURRENT_PAGE', htmlspecialchars($request->query->get('page') ?? '')); |
| 66 | require '../src/router.php'; \ No newline at end of file | 66 | require '../src/router.php'; \ No newline at end of file |
diff --git a/src/controller/PageManagementController.php b/src/controller/PageManagementController.php index 45c6027..7078866 100644 --- a/src/controller/PageManagementController.php +++ b/src/controller/PageManagementController.php | |||
| @@ -88,20 +88,37 @@ class PageManagementController | |||
| 88 | 88 | ||
| 89 | static public function deletePage(EntityManager $entityManager): void | 89 | static public function deletePage(EntityManager $entityManager): void |
| 90 | { | 90 | { |
| 91 | $page = $entityManager->find('App\Entity\Page', (int)$_POST['page_id']); | 91 | $menu = new Menu($entityManager); |
| 92 | $nodes = $entityManager->getRepository('App\Entity\Node')->findBy(['page' => $page]); | 92 | $page = $menu->findPageById((int)$_POST['page_id']); |
| 93 | $data = []; | 93 | $url = new URL; |
| 94 | foreach($nodes as $node){ | 94 | |
| 95 | $data[] = $entityManager->getRepository('App\Entity\NodeData')->findOneBy(['node' => $node]); | 95 | // test dernière page |
| 96 | $entityManager->remove($node); | 96 | // => $menu a un enfant et pas de petits enfants |
| 97 | } | 97 | // => $menu->getChildren()->isEmpty() n'est théoriquement pas possible |
| 98 | foreach($data as $one_data){ | 98 | if($menu->getChildren()->isEmpty() || (count($menu->getChildren()) === 1 && $menu->getChildren()[0]->getChildren()->isEmpty())){ |
| 99 | $entityManager->remove($one_data); | 99 | $url->addParams(['page' => $page->getEndOfPath(), 'error' => 'you_tried_to_remove_the_last_page']); |
| 100 | } | 100 | } |
| 101 | $entityManager->remove($page); // suppression en BDD | 101 | else{ |
| 102 | 102 | $nodes = $entityManager->getRepository('App\Entity\Node')->findBy(['page' => $page]); | |
| 103 | $entityManager->flush(); | 103 | $data = []; |
| 104 | header("Location: " . new URL); | 104 | foreach($nodes as $node){ |
| 105 | $data[] = $entityManager->getRepository('App\Entity\NodeData')->findOneBy(['node' => $node]); | ||
| 106 | $entityManager->remove($node); | ||
| 107 | } | ||
| 108 | foreach($data as $one_data){ | ||
| 109 | $entityManager->remove($one_data); | ||
| 110 | } | ||
| 111 | $entityManager->remove($page); // suppression en BDD | ||
| 112 | $entityManager->flush(); | ||
| 113 | |||
| 114 | // destination vers la première page dispo | ||
| 115 | // traite les cas prévus dans le if plus haut | ||
| 116 | $menu->removeChild($page); | ||
| 117 | $next_page = $menu->getChildren()->isEmpty() ? $next_page = $page->getChildren()[0] : $menu->getChildren()[0]; | ||
| 118 | $url->addParams(['page' => $next_page->getEndOfPath()]); | ||
| 119 | } | ||
| 120 | |||
| 121 | header("Location: " . $url); | ||
| 105 | die; | 122 | die; |
| 106 | } | 123 | } |
| 107 | 124 | ||
diff --git a/src/installation.php b/src/installation.php index b87b988..3d75449 100644 --- a/src/installation.php +++ b/src/installation.php | |||
| @@ -94,10 +94,10 @@ function fillStartingDatabase(EntityManager $entityManager){ | |||
| 94 | $article = new Page('Article', 'article', "", true, false, false, NULL, NULL); | 94 | $article = new Page('Article', 'article', "", true, false, false, NULL, NULL); |
| 95 | $connection = new Page('Connexion', 'connection', "Connexion", true, false, false, NULL, NULL); | 95 | $connection = new Page('Connexion', 'connection', "Connexion", true, false, false, NULL, NULL); |
| 96 | $my_account = new Page('Mon compte', 'user_edit', "Mon compte", true, false, false, NULL, NULL); | 96 | $my_account = new Page('Mon compte', 'user_edit', "Mon compte", true, false, false, NULL, NULL); |
| 97 | $menu_paths = new Page("Menu et chemins", 'menu_chemins', "Menu et chemins", true, false, false, NULL, NULL); | 97 | $menu_paths = new Page("Menu et chemins", 'menu_paths', "Menu et chemins", true, false, false, NULL, NULL); |
| 98 | $menu_paths->addCSS('menu'); | 98 | $menu_paths->addCSS('menu'); |
| 99 | $menu_paths->addJS('menu'); | 99 | $menu_paths->addJS('menu'); |
| 100 | $new_page = new Page('Nouvelle page', 'nouvelle_page', "Nouvelle page", true, false, false, NULL, NULL); | 100 | $new_page = new Page('Nouvelle page', 'new_page', "Nouvelle page", true, false, false, NULL, NULL); |
| 101 | $new_page->addCSS('new_page'); | 101 | $new_page->addCSS('new_page'); |
| 102 | $new_page->addJS('new_page'); | 102 | $new_page->addJS('new_page'); |
| 103 | 103 | ||
diff --git a/src/model/Path.php b/src/model/Path.php index 8ef9100..0b4bb67 100644 --- a/src/model/Path.php +++ b/src/model/Path.php | |||
| @@ -25,27 +25,22 @@ class Path extends Page | |||
| 25 | // produit un tableau de Page en comparant le chemin demandé avec les données dans Menu | 25 | // produit un tableau de Page en comparant le chemin demandé avec les données dans Menu |
| 26 | // succès => une exception est lancée pour sortir des fonctions imbriquées | 26 | // succès => une exception est lancée pour sortir des fonctions imbriquées |
| 27 | // echec => redirection vers la page erreur 404 | 27 | // echec => redirection vers la page erreur 404 |
| 28 | private function findPage(Page|Menu $menu, array $path_array) | 28 | private function findPage(Page|Menu $menu, array $path_array): void |
| 29 | { | 29 | { |
| 30 | // recherche dans les autres pages | 30 | // recherche dans les autres pages |
| 31 | if($menu instanceof Menu){ | 31 | if($menu instanceof Menu){ |
| 32 | foreach($menu->getOtherPages() as $page) | 32 | foreach($menu->getOtherPages() as $page){ |
| 33 | { | 33 | if($path_array[0] === $page->getEndOfPath()){ |
| 34 | if($path_array[0] === $page->getEndOfPath()) | ||
| 35 | { | ||
| 36 | $this->current_page[] = $page; | 34 | $this->current_page[] = $page; |
| 37 | throw new Exception(); | 35 | throw new Exception(); |
| 38 | } | 36 | } |
| 39 | } | 37 | } |
| 40 | } | 38 | } |
| 41 | // recherche dans le menu | 39 | // recherche dans le menu |
| 42 | foreach($menu->getChildren() as $page) | 40 | foreach($menu->getChildren() as $page){ |
| 43 | { | 41 | if($path_array[0] === $page->getEndOfPath()){ |
| 44 | if($path_array[0] === $page->getEndOfPath()) | ||
| 45 | { | ||
| 46 | $this->current_page[] = $page; | 42 | $this->current_page[] = $page; |
| 47 | if(count($path_array) > 1) | 43 | if(count($path_array) > 1){ |
| 48 | { | ||
| 49 | array_shift($path_array); // $this->path_array n'est pas modifié, un tableau PHP est passé à une fonction par copie | 44 | array_shift($path_array); // $this->path_array n'est pas modifié, un tableau PHP est passé à une fonction par copie |
| 50 | $this->findPage($page, $path_array); | 45 | $this->findPage($page, $path_array); |
| 51 | } | 46 | } |
| @@ -54,9 +49,11 @@ class Path extends Page | |||
| 54 | } | 49 | } |
| 55 | } | 50 | } |
| 56 | } | 51 | } |
| 52 | |||
| 57 | // rien trouvé | 53 | // rien trouvé |
| 58 | URL::setPath('erreur404.html'); | 54 | // pas parfait, échoue si le premier enfant de "children" n'est pas au premier niveau |
| 59 | header('Location: '. new URL); | 55 | // est-ce que ça peut arriver? |
| 56 | header('Location: '. new URL(['page' => Model::$menu->getChildren()[0]->getEndOfPath()])); | ||
| 60 | die; | 57 | die; |
| 61 | } | 58 | } |
| 62 | 59 | ||
diff --git a/src/view/FooterBuilder.php b/src/view/FooterBuilder.php index d810170..8d24f25 100644 --- a/src/view/FooterBuilder.php +++ b/src/view/FooterBuilder.php | |||
| @@ -58,8 +58,8 @@ class FooterBuilder extends AbstractBuilder | |||
| 58 | $mode = 'administrateur'; | 58 | $mode = 'administrateur'; |
| 59 | $div_admin = 'logged_in'; | 59 | $div_admin = 'logged_in'; |
| 60 | } | 60 | } |
| 61 | $link_new_page = new URL(['page' => 'nouvelle_page']); | 61 | $link_new_page = new URL(['page' => 'new_page']); |
| 62 | $link_change_paths = new URL(['page' => 'menu_chemins']); | 62 | $link_change_paths = new URL(['page' => 'menu_paths']); |
| 63 | 63 | ||
| 64 | $link_change_password = new URL(['page' => 'user_edit', 'from' => CURRENT_PAGE]); | 64 | $link_change_password = new URL(['page' => 'user_edit', 'from' => CURRENT_PAGE]); |
| 65 | isset($_GET['id']) ? $link_change_password->addParams(['id' => $_GET['id']]) : ''; | 65 | isset($_GET['id']) ? $link_change_password->addParams(['id' => $_GET['id']]) : ''; |
| @@ -100,7 +100,7 @@ class FooterBuilder extends AbstractBuilder | |||
| 100 | private function makePageModifModeButton(): string | 100 | private function makePageModifModeButton(): string |
| 101 | { | 101 | { |
| 102 | $link_edit_page = new URL(['page' => CURRENT_PAGE]); | 102 | $link_edit_page = new URL(['page' => CURRENT_PAGE]); |
| 103 | if(!in_array(CURRENT_PAGE, ['article', 'nouvelle_page', 'menu_chemins'])) // ajouter 'user_edit' et 'connection' le jour où ces pages auront un footer | 103 | if(!in_array(CURRENT_PAGE, ['article', 'new_page', 'menu_paths'])) // ajouter 'user_edit' et 'connection' le jour où ces pages auront un footer |
| 104 | { | 104 | { |
| 105 | if(MainBuilder::$modif_mode){ | 105 | if(MainBuilder::$modif_mode){ |
| 106 | $link_edit_label = 'Sortir du mode modification'; | 106 | $link_edit_label = 'Sortir du mode modification'; |
diff --git a/src/view/templates/modify_page.php b/src/view/templates/modify_page.php index ecacb02..d32179c 100644 --- a/src/view/templates/modify_page.php +++ b/src/view/templates/modify_page.php | |||
| @@ -24,7 +24,7 @@ | |||
| 24 | </div> | 24 | </div> |
| 25 | </div> | 25 | </div> |
| 26 | <div class="delete_page_zone"> | 26 | <div class="delete_page_zone"> |
| 27 | <form method="post" action="<?= new URL ?>"> | 27 | <form method="post" action="<?= new URL(['page' => CURRENT_PAGE]) ?>"> |
| 28 | <label>Supprimer cette page</label> | 28 | <label>Supprimer cette page</label> |
| 29 | <input type="hidden" name="page_id" value="<?= Model::$page_path->getLast()->getId() ?>"> | 29 | <input type="hidden" name="page_id" value="<?= Model::$page_path->getLast()->getId() ?>"> |
| 30 | <input type="hidden" name="submit_hidden"> | 30 | <input type="hidden" name="submit_hidden"> |
