diff options
Diffstat (limited to 'src/controller/MenuAndPathsController.php')
| -rw-r--r-- | src/controller/MenuAndPathsController.php | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/controller/MenuAndPathsController.php b/src/controller/MenuAndPathsController.php index 6bb098f..4d37f3d 100644 --- a/src/controller/MenuAndPathsController.php +++ b/src/controller/MenuAndPathsController.php | |||
| @@ -10,8 +10,8 @@ class MenuAndPathsController | |||
| 10 | { | 10 | { |
| 11 | static public function newUrlMenuEntry(EntityManager $entityManager): void | 11 | static public function newUrlMenuEntry(EntityManager $entityManager): void |
| 12 | { | 12 | { |
| 13 | Model::$menu_data = new Menu($entityManager); | 13 | Model::$menu = new Menu($entityManager); |
| 14 | $previous_page = Model::$menu_data->findPageById((int)$_POST["location"]); // (int) à cause de declare(strict_types=1); | 14 | $previous_page = Model::$menu->findPageById((int)$_POST["location"]); // (int) à cause de declare(strict_types=1); |
| 15 | $parent = $previous_page->getParent(); | 15 | $parent = $previous_page->getParent(); |
| 16 | 16 | ||
| 17 | $url_input = trim($_POST["url_input"]); // faire htmlspecialchars à l'affichage | 17 | $url_input = trim($_POST["url_input"]); // faire htmlspecialchars à l'affichage |
| @@ -31,7 +31,7 @@ class MenuAndPathsController | |||
| 31 | // addChild l'ajoute à la fin du tableau "children" puis on trie | 31 | // addChild l'ajoute à la fin du tableau "children" puis on trie |
| 32 | // exemple avec 2 comme position demandée: 1 2 3 4 2 devient 1 2 3 4 5 et la nouvelle entrée sera en 3è position | 32 | // exemple avec 2 comme position demandée: 1 2 3 4 2 devient 1 2 3 4 5 et la nouvelle entrée sera en 3è position |
| 33 | if(!$parent){ | 33 | if(!$parent){ |
| 34 | $parent = Model::$menu_data; | 34 | $parent = Model::$menu; |
| 35 | } | 35 | } |
| 36 | $parent->addChild($page); // true pour réindexer les positions en BDD | 36 | $parent->addChild($page); // true pour réindexer les positions en BDD |
| 37 | $parent->reindexPositions(); | 37 | $parent->reindexPositions(); |
| @@ -72,11 +72,11 @@ class MenuAndPathsController | |||
| 72 | 72 | ||
| 73 | static public function deleteUrlMenuEntry(EntityManager $entityManager): void | 73 | static public function deleteUrlMenuEntry(EntityManager $entityManager): void |
| 74 | { | 74 | { |
| 75 | Model::$menu_data = new Menu($entityManager); | 75 | Model::$menu = new Menu($entityManager); |
| 76 | $page = Model::$menu_data->findPageById((int)$_POST["delete"]); | 76 | $page = Model::$menu->findPageById((int)$_POST["delete"]); |
| 77 | $parent = $page->getParent(); | 77 | $parent = $page->getParent(); |
| 78 | if($parent == null){ | 78 | if($parent == null){ |
| 79 | $parent = Model::$menu_data; | 79 | $parent = Model::$menu; |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | $parent->removeChild($page); // suppression de $children avant de trier | 82 | $parent->removeChild($page); // suppression de $children avant de trier |
| @@ -91,7 +91,7 @@ class MenuAndPathsController | |||
| 91 | static public function MoveOneLevelUp(EntityManager $entityManager, array $json): void | 91 | static public function MoveOneLevelUp(EntityManager $entityManager, array $json): void |
| 92 | { | 92 | { |
| 93 | $id = $json['id']; | 93 | $id = $json['id']; |
| 94 | $page = Model::$menu_data->findPageById((int)$id); | 94 | $page = Model::$menu->findPageById((int)$id); |
| 95 | 95 | ||
| 96 | $parent = $page->getParent(); // peut être null | 96 | $parent = $page->getParent(); // peut être null |
| 97 | if($parent === null){ | 97 | if($parent === null){ |
| @@ -103,12 +103,12 @@ class MenuAndPathsController | |||
| 103 | else{ | 103 | else{ |
| 104 | $page->setPosition($parent->getPosition() + 1); // nouvelle position | 104 | $page->setPosition($parent->getPosition() + 1); // nouvelle position |
| 105 | 105 | ||
| 106 | // 2ème niveau: le parent devient $menu_data, puis null après tri | 106 | // 2ème niveau: le parent devient $menu, puis null après tri |
| 107 | if($parent->getParent() === null){ | 107 | if($parent->getParent() === null){ |
| 108 | // connexion dans les deux sens | 108 | // connexion dans les deux sens |
| 109 | $page->setParent(Model::$menu_data); // => pour la persistance | 109 | $page->setParent(Model::$menu); // => pour la persistance |
| 110 | 110 | ||
| 111 | //Model::$menu_data->addChild($page); // => pour sortChildren | 111 | //Model::$menu->addChild($page); // => pour sortChildren |
| 112 | $page->getParent()->addChild($page); // => pour sortChildren | 112 | $page->getParent()->addChild($page); // => pour sortChildren |
| 113 | $page->getParent()->sortChildren(true); // positions décaléees des nouveaux petits frères | 113 | $page->getParent()->sortChildren(true); // positions décaléees des nouveaux petits frères |
| 114 | $page->setParent(null); | 114 | $page->setParent(null); |
| @@ -138,11 +138,11 @@ class MenuAndPathsController | |||
| 138 | static public function MoveOneLevelDown(EntityManager $entityManager, array $json): void | 138 | static public function MoveOneLevelDown(EntityManager $entityManager, array $json): void |
| 139 | { | 139 | { |
| 140 | $id = $json['id']; | 140 | $id = $json['id']; |
| 141 | $page = Model::$menu_data->findPageById((int)$id); | 141 | $page = Model::$menu->findPageById((int)$id); |
| 142 | 142 | ||
| 143 | $parent = $page->getParent(); // peut être null | 143 | $parent = $page->getParent(); // peut être null |
| 144 | if($parent == null){ | 144 | if($parent == null){ |
| 145 | $parent = Model::$menu_data; | 145 | $parent = Model::$menu; |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | // BDD | 148 | // BDD |
| @@ -175,8 +175,8 @@ class MenuAndPathsController | |||
| 175 | $id2 = $json['id2']; | 175 | $id2 = $json['id2']; |
| 176 | 176 | ||
| 177 | // vérifier qu'ils ont le même parent | 177 | // vérifier qu'ils ont le même parent |
| 178 | $page1 = Model::$menu_data->findPageById((int)$id1); | 178 | $page1 = Model::$menu->findPageById((int)$id1); |
| 179 | $page2 = Model::$menu_data->findPageById((int)$id2); | 179 | $page2 = Model::$menu->findPageById((int)$id2); |
| 180 | 180 | ||
| 181 | // double le contrôle fait en JS | 181 | // double le contrôle fait en JS |
| 182 | if($page1->getParent() === $page2->getParent()) // comparaison stricte d'objet (même instance du parent?) | 182 | if($page1->getParent() === $page2->getParent()) // comparaison stricte d'objet (même instance du parent?) |
| @@ -185,7 +185,7 @@ class MenuAndPathsController | |||
| 185 | $tmp = $page1->getPosition(); | 185 | $tmp = $page1->getPosition(); |
| 186 | $page1->setPosition($page2->getPosition()); | 186 | $page1->setPosition($page2->getPosition()); |
| 187 | $page2->setPosition($tmp); | 187 | $page2->setPosition($tmp); |
| 188 | Model::$menu_data->sortChildren(true); // modifie tableau children | 188 | Model::$menu->sortChildren(true); // modifie tableau children |
| 189 | $entityManager->flush(); | 189 | $entityManager->flush(); |
| 190 | 190 | ||
| 191 | // nouveau menu | 191 | // nouveau menu |
| @@ -203,7 +203,7 @@ class MenuAndPathsController | |||
| 203 | $id = $json['id']; | 203 | $id = $json['id']; |
| 204 | $checked = $json['checked']; | 204 | $checked = $json['checked']; |
| 205 | 205 | ||
| 206 | $page = Model::$menu_data->findPageById((int)$id); | 206 | $page = Model::$menu->findPageById((int)$id); |
| 207 | if($page->isHidden() === $checked){ | 207 | if($page->isHidden() === $checked){ |
| 208 | $page->setHidden(!$checked); | 208 | $page->setHidden(!$checked); |
| 209 | $entityManager->flush(); | 209 | $entityManager->flush(); |
