diff options
Diffstat (limited to 'src/controller/MenuAndPathsController.php')
| -rw-r--r-- | src/controller/MenuAndPathsController.php | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/controller/MenuAndPathsController.php b/src/controller/MenuAndPathsController.php index a32b210..6bb098f 100644 --- a/src/controller/MenuAndPathsController.php +++ b/src/controller/MenuAndPathsController.php | |||
| @@ -42,21 +42,30 @@ class MenuAndPathsController | |||
| 42 | die; | 42 | die; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | static public function editUrlEntry(EntityManager $entityManager, array $json): void | 45 | // on pourrait utiliser FormValidation ici |
| 46 | static public function editUrl(EntityManager $entityManager, array $json): void | ||
| 46 | { | 47 | { |
| 47 | $url_input = trim($json['url_input']); // faire htmlspecialchars à l'affichage | 48 | $url_data = trim($json['input_data']); // garder htmlspecialchars pour l'affichage |
| 48 | $page = $entityManager->find('App\Entity\Page', $json['id']); | 49 | $page = $entityManager->find('App\Entity\Page', $json['id']); |
| 49 | 50 | ||
| 50 | if(!$page){ | 51 | if(!$page){ |
| 51 | echo json_encode(['success' => false, 'message' => "id invalide"]); | 52 | echo json_encode(['success' => false, 'message' => "id invalide"]); |
| 52 | } | 53 | } |
| 53 | elseif(!filter_var($url_input, FILTER_VALIDATE_URL) || !str_starts_with($url_input, 'http')){ | 54 | elseif(!in_array($json['field'], ['url_name', 'url_content'])){ |
| 55 | echo json_encode(['success' => false, 'message' => "champ invalide"]); | ||
| 56 | } | ||
| 57 | elseif($json['field'] === 'url_content' && (!filter_var($url_data, FILTER_VALIDATE_URL) || !str_starts_with($url_data, 'http'))){ | ||
| 54 | echo json_encode(['success' => false, 'message' => "la chaîne envoyée n'est pas une URL valide"]); | 58 | echo json_encode(['success' => false, 'message' => "la chaîne envoyée n'est pas une URL valide"]); |
| 55 | } | 59 | } |
| 56 | else{ | 60 | else{ |
| 57 | $page->setEndOfPath($url_input); | 61 | if($json['field'] === 'url_name'){ |
| 62 | $page->setPageName($url_data); | ||
| 63 | } | ||
| 64 | elseif($json['field'] === 'url_content'){ | ||
| 65 | $page->setEndOfPath($url_data); | ||
| 66 | } | ||
| 58 | $entityManager->flush(); | 67 | $entityManager->flush(); |
| 59 | echo json_encode(['success' => true, 'url_input' => $url_input]); | 68 | echo json_encode(['success' => true, 'url_data' => $url_data]); |
| 60 | } | 69 | } |
| 61 | die; | 70 | die; |
| 62 | } | 71 | } |
