diff options
Diffstat (limited to 'src/controller/post.php')
| -rw-r--r-- | src/controller/post.php | 82 |
1 files changed, 79 insertions, 3 deletions
diff --git a/src/controller/post.php b/src/controller/post.php index 926a5ae..8924686 100644 --- a/src/controller/post.php +++ b/src/controller/post.php | |||
| @@ -5,13 +5,89 @@ declare(strict_types=1); | |||
| 5 | 5 | ||
| 6 | if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | 6 | if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) |
| 7 | { | 7 | { |
| 8 | // requêtes AJAX | 8 | /* -- requêtes non AJAX -- */ |
| 9 | // page Menu et chemin | ||
| 10 | /*if(isset($_POST['menu_edit_post']) && isset($_POST['id'])) | ||
| 11 | { | ||
| 12 | // <= flèche gauche: le parent devient le grand-parent position = position du parent + 1, recalculer les positions des enfants restants | ||
| 13 | if($_POST['menu_edit_post'] == 'move_one_level_up'){ | ||
| 14 | Director::$menu_data = new Menu($entityManager); | ||
| 15 | $page = Director::$menu_data->findPageById((int)$_POST['id']); | ||
| 16 | |||
| 17 | $parent = $page->getParent(); // peut être null | ||
| 18 | if($parent === null){ | ||
| 19 | // 1er niveau: ne rien faire | ||
| 20 | header('Location: ' . new URL(['page' => 'menu_chemins'])); | ||
| 21 | die; | ||
| 22 | } | ||
| 23 | else{ | ||
| 24 | $page->setPosition($parent->getPosition() + 1); // nouvelle position | ||
| 25 | |||
| 26 | // 2ème niveau: le parent devient $menu_data, puis null après tri | ||
| 27 | if($parent->getParent() === null){ | ||
| 28 | // connexion dans les deux sens | ||
| 29 | $page->setParent(Director::$menu_data); // => pour la persistance | ||
| 30 | Director::$menu_data->addChild($page); // => pour sortChildren | ||
| 31 | |||
| 32 | //Director::$menu_data->sortChildren(true); // positions décaléees des nouveaux petits frères | ||
| 33 | $page->getParent()->sortChildren(true); // positions décaléees des nouveaux petits frères | ||
| 34 | |||
| 35 | $page->setParent(null); | ||
| 36 | } | ||
| 37 | // 3ème niveau et plus | ||
| 38 | else{ | ||
| 39 | $page->setParent($parent->getParent()); // nouveau parent | ||
| 40 | $page->getParent()->sortChildren(true); // positions décaléees des nouveaux petits frères | ||
| 41 | } | ||
| 42 | //$parent->sortChildren(true); // positions des enfants restants, inutile si la fonction est récursive? | ||
| 43 | echo $page->getPosition(); | ||
| 44 | //die; | ||
| 45 | } | ||
| 46 | $entityManager->flush(); | ||
| 47 | |||
| 48 | header('Location: ' . new URL(['page' => 'menu_chemins'])); | ||
| 49 | die; | ||
| 50 | } | ||
| 51 | // => flèche droite: l'élément précédent devient le parent, position = nombre d'éléments de la fraterie + 1 | ||
| 52 | elseif($_POST['menu_edit_post'] == 'move_one_level_down') | ||
| 53 | { | ||
| 54 | Director::$menu_data = new Menu($entityManager); | ||
| 55 | $page = Director::$menu_data->findPageById((int)$_POST['id']); | ||
| 56 | |||
| 57 | $parent = $page->getParent(); // peut être null | ||
| 58 | if($parent == null){ | ||
| 59 | $parent = Director::$menu_data; | ||
| 60 | } | ||
| 61 | |||
| 62 | $parent->sortChildren(true); // trie et réindexe par sécurité: 1, 2, 3... | ||
| 63 | if($page->getPosition() > 1){ | ||
| 64 | foreach($parent->getChildren() as $child){ | ||
| 65 | echo $child->getPageName(); | ||
| 66 | if($child->getPosition() === $page->getPosition() - 1){ | ||
| 67 | $page->setParent($child); | ||
| 68 | break; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | $page->setPosition(count($page->getParent()->getChildren()) + 1); | ||
| 72 | } | ||
| 73 | $entityManager->flush(); | ||
| 74 | |||
| 75 | header('Location: ' . new URL(['page' => 'menu_chemins'])); | ||
| 76 | die; | ||
| 77 | } | ||
| 78 | else{ | ||
| 79 | // you talking to me? | ||
| 80 | die; | ||
| 81 | } | ||
| 82 | }*/ | ||
| 83 | |||
| 84 | /* -- requêtes AJAX -- */ | ||
| 9 | require '../src/controller/ajax.php'; | 85 | require '../src/controller/ajax.php'; |
| 10 | 86 | ||
| 11 | // formulaires HTML | 87 | // formulaires HTML |
| 12 | if(isset($_POST['from']) // page d'où vient la requête | 88 | /*if(isset($_POST['from']) // page d'où vient la requête |
| 13 | && isset($_POST)) // données | 89 | && isset($_POST)) // données |
| 14 | { | 90 | { |
| 15 | echo "requête envoyée en validant un formulaire"; | 91 | echo "requête envoyée en validant un formulaire"; |
| 16 | } | 92 | }*/ |
| 17 | } | 93 | } |
