diff options
Diffstat (limited to 'src/controller/post.php')
| -rw-r--r-- | src/controller/post.php | 34 |
1 files changed, 30 insertions, 4 deletions
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) | |||
| 15 | /* -- mode Modification d'une page -- */ | 15 | /* -- mode Modification d'une page -- */ |
| 16 | 16 | ||
| 17 | // ajout d'un bloc dans une page | 17 | // ajout d'un bloc dans une page |
| 18 | if(isset($_POST['bloc_title']) && isset($_POST['bloc_select'])){ | 18 | if(isset($_POST['bloc_title']) && $_POST['bloc_title'] !== null && isset($_POST['bloc_select']) && $_POST['bloc_select'] !== null |
| 19 | && isset($_POST['bloc_title_hidden']) && $_POST['bloc_title_hidden'] === '') // contrôle anti-robot avec input hidden | ||
| 20 | { | ||
| 19 | $director = new Director($entityManager, true); // on a besoin de page_path qui dépend de menu_data | 21 | $director = new Director($entityManager, true); // on a besoin de page_path qui dépend de menu_data |
| 20 | $page = Director::$page_path->getLast(); | 22 | $page = Director::$page_path->getLast(); |
| 21 | $director->findNodeByName('main'); | 23 | $director->findUniqueNodeByName('main'); |
| 24 | $director->findItsChildren(); | ||
| 22 | $main = $director->getNode(); | 25 | $main = $director->getNode(); |
| 23 | $position = count($main->getChildren()) + 1; // position dans la fraterie | 26 | $position = count($main->getChildren()) + 1; // position dans la fraterie |
| 24 | 27 | ||
| @@ -37,7 +40,30 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
| 37 | $entityManager->flush(); | 40 | $entityManager->flush(); |
| 38 | header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); | 41 | header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); |
| 39 | } | 42 | } |
| 43 | // suppression d'un bloc de page | ||
| 44 | elseif(isset($_POST['delete_bloc_id']) && $_POST['delete_bloc_id'] !== null | ||
| 45 | && isset($_POST['delete_bloc_hidden']) && $_POST['delete_bloc_hidden'] === '') // contrôle anti-robot avec input hidden | ||
| 46 | { | ||
| 47 | $director = new Director($entityManager, true); | ||
| 48 | $director->findUniqueNodeByName('main'); | ||
| 49 | $director->findItsChildren(); | ||
| 50 | //$director->findNodeById((int)$_POST['delete_bloc_id']); | ||
| 51 | $main = $director->getNode(); | ||
| 52 | $bloc; | ||
| 53 | foreach($main->getChildren() as $child){ | ||
| 54 | if($child->getId() === (int)$_POST['delete_bloc_id']){ | ||
| 55 | $bloc = $child; | ||
| 56 | break; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | $main->removeChild($bloc); // réindex le tableau $children au passage | ||
| 60 | $main->reindexPositions(); | ||
| 40 | 61 | ||
| 62 | $entityManager->remove($bloc); // suppression en BDD | ||
| 63 | $entityManager->flush(); | ||
| 64 | header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); | ||
| 65 | } | ||
| 66 | |||
| 41 | 67 | ||
| 42 | /* -- page Menu et chemins -- */ | 68 | /* -- page Menu et chemins -- */ |
| 43 | 69 | ||
| @@ -60,7 +86,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
| 60 | $parent = Director::$menu_data; | 86 | $parent = Director::$menu_data; |
| 61 | } | 87 | } |
| 62 | $parent->addChild($page); // true pour réindexer les positions en BDD | 88 | $parent->addChild($page); // true pour réindexer les positions en BDD |
| 63 | $parent->reindex(); | 89 | $parent->reindexPositions(); |
| 64 | 90 | ||
| 65 | $entityManager->persist($page); | 91 | $entityManager->persist($page); |
| 66 | $entityManager->flush(); | 92 | $entityManager->flush(); |
| @@ -76,7 +102,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
| 76 | } | 102 | } |
| 77 | 103 | ||
| 78 | $parent->removeChild($page); // suppression de $children avant de trier | 104 | $parent->removeChild($page); // suppression de $children avant de trier |
| 79 | $parent->reindex(); | 105 | $parent->reindexPositions(); |
| 80 | 106 | ||
| 81 | $entityManager->remove($page); // suppression en BDD | 107 | $entityManager->remove($page); // suppression en BDD |
| 82 | $entityManager->flush(); | 108 | $entityManager->flush(); |
