diff options
Diffstat (limited to 'src/controller/MenuAndPathsController.php')
| -rw-r--r-- | src/controller/MenuAndPathsController.php | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/controller/MenuAndPathsController.php b/src/controller/MenuAndPathsController.php index d429287..5779b39 100644 --- a/src/controller/MenuAndPathsController.php +++ b/src/controller/MenuAndPathsController.php | |||
| @@ -14,9 +14,15 @@ class MenuAndPathsController | |||
| 14 | $previous_page = Director::$menu_data->findPageById((int)$_POST["location"]); // (int) à cause de declare(strict_types=1); | 14 | $previous_page = Director::$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 | ||
| 18 | if(!filter_var($url_input, FILTER_VALIDATE_URL) || !str_starts_with($url_input, 'http')){ | ||
| 19 | header("Location: " . new URL(['page' => $_GET['from'], 'error' => 'invalide_url'])); | ||
| 20 | die; | ||
| 21 | } | ||
| 22 | |||
| 17 | $page = new Page( | 23 | $page = new Page( |
| 18 | trim(htmlspecialchars($_POST["label_input"])), | 24 | trim(htmlspecialchars($_POST["label_input"])), |
| 19 | filter_var($_POST["url_input"], FILTER_VALIDATE_URL), | 25 | $url_input, |
| 20 | true, true, false, | 26 | true, true, false, |
| 21 | $previous_page->getPosition(), | 27 | $previous_page->getPosition(), |
| 22 | $parent); // peut et DOIT être null si on est au 1er niveau | 28 | $parent); // peut et DOIT être null si on est au 1er niveau |
| @@ -24,7 +30,7 @@ class MenuAndPathsController | |||
| 24 | // on a donné à la nouvelle entrée la même position qu'à la précédente, | 30 | // on a donné à la nouvelle entrée la même position qu'à la précédente, |
| 25 | // addChild l'ajoute à la fin du tableau "children" puis on trie | 31 | // addChild l'ajoute à la fin du tableau "children" puis on trie |
| 26 | // 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 |
| 27 | if($parent == null){ | 33 | if(!$parent){ |
| 28 | $parent = Director::$menu_data; | 34 | $parent = Director::$menu_data; |
| 29 | } | 35 | } |
| 30 | $parent->addChild($page); // true pour réindexer les positions en BDD | 36 | $parent->addChild($page); // true pour réindexer les positions en BDD |
| @@ -36,6 +42,25 @@ class MenuAndPathsController | |||
| 36 | die; | 42 | die; |
| 37 | } | 43 | } |
| 38 | 44 | ||
| 45 | static public function editUrlEntry(EntityManager $entityManager, array $json): void | ||
| 46 | { | ||
| 47 | $url_input = trim($json['url_input']); // faire htmlspecialchars à l'affichage | ||
| 48 | $page = $entityManager->find('App\Entity\Page', $json['id']); | ||
| 49 | |||
| 50 | if(!$page){ | ||
| 51 | echo json_encode(['success' => false, 'message' => "id invalide"]); | ||
| 52 | } | ||
| 53 | elseif(!filter_var($url_input, FILTER_VALIDATE_URL) || !str_starts_with($url_input, 'http')){ | ||
| 54 | echo json_encode(['success' => false, 'message' => "la chaîne envoyée n'est pas une URL valide"]); | ||
| 55 | } | ||
| 56 | else{ | ||
| 57 | $page->setEndOfPath($url_input); | ||
| 58 | $entityManager->flush(); | ||
| 59 | echo json_encode(['success' => true, 'url_input' => $url_input]); | ||
| 60 | } | ||
| 61 | die; | ||
| 62 | } | ||
| 63 | |||
| 39 | static public function deleteUrlMenuEntry(EntityManager $entityManager): void | 64 | static public function deleteUrlMenuEntry(EntityManager $entityManager): void |
| 40 | { | 65 | { |
| 41 | Director::$menu_data = new Menu($entityManager); | 66 | Director::$menu_data = new Menu($entityManager); |
| @@ -163,7 +188,6 @@ class MenuAndPathsController | |||
| 163 | else{ | 188 | else{ |
| 164 | echo json_encode(['success' => false]); | 189 | echo json_encode(['success' => false]); |
| 165 | } | 190 | } |
| 166 | |||
| 167 | die; | 191 | die; |
| 168 | } | 192 | } |
| 169 | 193 | ||
