diff options
Diffstat (limited to 'src/controller/MenuAndPathsController.php')
| -rw-r--r-- | src/controller/MenuAndPathsController.php | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/controller/MenuAndPathsController.php b/src/controller/MenuAndPathsController.php index 3ff7d54..f0553ad 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 | Director::$menu_data = new Menu($entityManager); | 13 | Model::$menu_data = new Menu($entityManager); |
| 14 | $previous_page = Director::$menu_data->findPageById((int)$_POST["location"]); // (int) à cause de declare(strict_types=1); | 14 | $previous_page = Model::$menu_data->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 = Director::$menu_data; | 34 | $parent = Model::$menu_data; |
| 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(); |
| @@ -63,11 +63,11 @@ class MenuAndPathsController | |||
| 63 | 63 | ||
| 64 | static public function deleteUrlMenuEntry(EntityManager $entityManager): void | 64 | static public function deleteUrlMenuEntry(EntityManager $entityManager): void |
| 65 | { | 65 | { |
| 66 | Director::$menu_data = new Menu($entityManager); | 66 | Model::$menu_data = new Menu($entityManager); |
| 67 | $page = Director::$menu_data->findPageById((int)$_POST["delete"]); | 67 | $page = Model::$menu_data->findPageById((int)$_POST["delete"]); |
| 68 | $parent = $page->getParent(); | 68 | $parent = $page->getParent(); |
| 69 | if($parent == null){ | 69 | if($parent == null){ |
| 70 | $parent = Director::$menu_data; | 70 | $parent = Model::$menu_data; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | $parent->removeChild($page); // suppression de $children avant de trier | 73 | $parent->removeChild($page); // suppression de $children avant de trier |
| @@ -82,7 +82,7 @@ class MenuAndPathsController | |||
| 82 | static public function MoveOneLevelUp(EntityManager $entityManager, array $json): void | 82 | static public function MoveOneLevelUp(EntityManager $entityManager, array $json): void |
| 83 | { | 83 | { |
| 84 | $id = $json['id']; | 84 | $id = $json['id']; |
| 85 | $page = Director::$menu_data->findPageById((int)$id); | 85 | $page = Model::$menu_data->findPageById((int)$id); |
| 86 | 86 | ||
| 87 | $parent = $page->getParent(); // peut être null | 87 | $parent = $page->getParent(); // peut être null |
| 88 | if($parent === null){ | 88 | if($parent === null){ |
| @@ -97,9 +97,9 @@ class MenuAndPathsController | |||
| 97 | // 2ème niveau: le parent devient $menu_data, puis null après tri | 97 | // 2ème niveau: le parent devient $menu_data, puis null après tri |
| 98 | if($parent->getParent() === null){ | 98 | if($parent->getParent() === null){ |
| 99 | // connexion dans les deux sens | 99 | // connexion dans les deux sens |
| 100 | $page->setParent(Director::$menu_data); // => pour la persistance | 100 | $page->setParent(Model::$menu_data); // => pour la persistance |
| 101 | 101 | ||
| 102 | //Director::$menu_data->addChild($page); // => pour sortChildren | 102 | //Model::$menu_data->addChild($page); // => pour sortChildren |
| 103 | $page->getParent()->addChild($page); // => pour sortChildren | 103 | $page->getParent()->addChild($page); // => pour sortChildren |
| 104 | $page->getParent()->sortChildren(true); // positions décaléees des nouveaux petits frères | 104 | $page->getParent()->sortChildren(true); // positions décaléees des nouveaux petits frères |
| 105 | $page->setParent(null); | 105 | $page->setParent(null); |
| @@ -129,11 +129,11 @@ class MenuAndPathsController | |||
| 129 | static public function MoveOneLevelDown(EntityManager $entityManager, array $json): void | 129 | static public function MoveOneLevelDown(EntityManager $entityManager, array $json): void |
| 130 | { | 130 | { |
| 131 | $id = $json['id']; | 131 | $id = $json['id']; |
| 132 | $page = Director::$menu_data->findPageById((int)$id); | 132 | $page = Model::$menu_data->findPageById((int)$id); |
| 133 | 133 | ||
| 134 | $parent = $page->getParent(); // peut être null | 134 | $parent = $page->getParent(); // peut être null |
| 135 | if($parent == null){ | 135 | if($parent == null){ |
| 136 | $parent = Director::$menu_data; | 136 | $parent = Model::$menu_data; |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | // BDD | 139 | // BDD |
| @@ -166,8 +166,8 @@ class MenuAndPathsController | |||
| 166 | $id2 = $json['id2']; | 166 | $id2 = $json['id2']; |
| 167 | 167 | ||
| 168 | // vérifier qu'ils ont le même parent | 168 | // vérifier qu'ils ont le même parent |
| 169 | $page1 = Director::$menu_data->findPageById((int)$id1); | 169 | $page1 = Model::$menu_data->findPageById((int)$id1); |
| 170 | $page2 = Director::$menu_data->findPageById((int)$id2); | 170 | $page2 = Model::$menu_data->findPageById((int)$id2); |
| 171 | 171 | ||
| 172 | // double le contrôle fait en JS | 172 | // double le contrôle fait en JS |
| 173 | if($page1->getParent() === $page2->getParent()) // comparaison stricte d'objet (même instance du parent?) | 173 | if($page1->getParent() === $page2->getParent()) // comparaison stricte d'objet (même instance du parent?) |
| @@ -176,7 +176,7 @@ class MenuAndPathsController | |||
| 176 | $tmp = $page1->getPosition(); | 176 | $tmp = $page1->getPosition(); |
| 177 | $page1->setPosition($page2->getPosition()); | 177 | $page1->setPosition($page2->getPosition()); |
| 178 | $page2->setPosition($tmp); | 178 | $page2->setPosition($tmp); |
| 179 | Director::$menu_data->sortChildren(true); // modifie tableau children | 179 | Model::$menu_data->sortChildren(true); // modifie tableau children |
| 180 | $entityManager->flush(); | 180 | $entityManager->flush(); |
| 181 | 181 | ||
| 182 | // nouveau menu | 182 | // nouveau menu |
| @@ -194,7 +194,7 @@ class MenuAndPathsController | |||
| 194 | $id = $json['id']; | 194 | $id = $json['id']; |
| 195 | $checked = $json['checked']; | 195 | $checked = $json['checked']; |
| 196 | 196 | ||
| 197 | $page = Director::$menu_data->findPageById((int)$id); | 197 | $page = Model::$menu_data->findPageById((int)$id); |
| 198 | if($page->isHidden() === $checked){ | 198 | if($page->isHidden() === $checked){ |
| 199 | $page->setHidden(!$checked); | 199 | $page->setHidden(!$checked); |
| 200 | $entityManager->flush(); | 200 | $entityManager->flush(); |
