diff options
| author | polo <ordipolo@gmx.fr> | 2026-06-10 20:56:25 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-06-10 20:56:25 +0200 |
| commit | ae217a6e4b0c29346381e2a410fd7810cb33ce3f (patch) | |
| tree | 206f604c9297deabf78bb33f31a1e6b9303d2258 /src/controller/HeadFootController.php | |
| parent | 99d2616a08c98e7067cdb12f0bcbd4ac0cffaeb0 (diff) | |
| download | cms-ae217a6e4b0c29346381e2a410fd7810cb33ce3f.tar.gz cms-ae217a6e4b0c29346381e2a410fd7810cb33ce3f.tar.bz2 cms-ae217a6e4b0c29346381e2a410fd7810cb33ce3f.zip | |
Tous les contrôleurs retournent une Response!
Diffstat (limited to 'src/controller/HeadFootController.php')
| -rw-r--r-- | src/controller/HeadFootController.php | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/src/controller/HeadFootController.php b/src/controller/HeadFootController.php index df6d022..72487d8 100644 --- a/src/controller/HeadFootController.php +++ b/src/controller/HeadFootController.php | |||
| @@ -7,15 +7,15 @@ use App\Entity\NodeData; | |||
| 7 | use App\Entity\Asset; | 7 | use App\Entity\Asset; |
| 8 | use App\Entity\AssetEmployment; | 8 | use App\Entity\AssetEmployment; |
| 9 | use Doctrine\ORM\EntityManager; | 9 | use Doctrine\ORM\EntityManager; |
| 10 | use Symfony\Component\HttpFoundation\JsonResponse; | ||
| 10 | 11 | ||
| 11 | class HeadFootController | 12 | class HeadFootController |
| 12 | { | 13 | { |
| 13 | static public function setTextData(EntityManager $entityManager, string $request_params, array $json): void | 14 | static public function setTextData(EntityManager $entityManager, string $request_params, array $json): JsonResponse |
| 14 | { | 15 | { |
| 15 | $params_array = explode('_', $request_params); // header_title, header_description, footer_name, footer_address, footer_email | 16 | $params_array = explode('_', $request_params); // header_title, header_description, footer_name, footer_address, footer_email |
| 16 | if(count($params_array) !== 2){ | 17 | if(count($params_array) !== 2){ |
| 17 | echo json_encode(['success' => false]); | 18 | return new JsonResponse(['success' => false]); |
| 18 | die; | ||
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | $model = new Model($entityManager); | 21 | $model = new Model($entityManager); |
| @@ -34,18 +34,16 @@ class HeadFootController | |||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | $entityManager->flush(); | 36 | $entityManager->flush(); |
| 37 | echo json_encode(['success' => true]); | 37 | return new JsonResponse(['success' => true]); |
| 38 | } | 38 | } |
| 39 | else{ | 39 | else{ |
| 40 | echo json_encode(['success' => false]); | 40 | return new JsonResponse(['success' => false]); |
| 41 | } | 41 | } |
| 42 | die; | ||
| 43 | } | 42 | } |
| 44 | static public function uploadAsset(EntityManager $entityManager, string $request_params): void | 43 | static public function uploadAsset(EntityManager $entityManager, string $request_params): JsonResponse |
| 45 | { | 44 | { |
| 46 | if(empty($_FILES)){ | 45 | if(empty($_FILES)){ |
| 47 | http_response_code(400); | 46 | return new JsonResponse(['success' => false], JsonResponse::HTTP_BAD_REQUEST); // code 400 |
| 48 | echo json_encode(['success' => false]); | ||
| 49 | } | 47 | } |
| 50 | else{ | 48 | else{ |
| 51 | if(!is_dir(Asset::USER_PATH)){ | 49 | if(!is_dir(Asset::USER_PATH)){ |
| @@ -81,9 +79,8 @@ class HeadFootController | |||
| 81 | } | 79 | } |
| 82 | 80 | ||
| 83 | /* -- écriture du fichier sur le disque -- */ | 81 | /* -- écriture du fichier sur le disque -- */ |
| 84 | if(!ImageUploadController::imagickCleanAndWriteImage(file_get_contents($file['tmp_name']), Asset::USER_PATH . $name, $extension)){ // recréer l’image pour la nettoyer | 82 | if(!ImageUploadController::imagickCleanAndWriteImage(file_get_contents($file['tmp_name']), Asset::USER_PATH . $name)){ // recréer l’image pour la nettoyer |
| 85 | http_response_code(500); | 83 | return new JsonResponse(['success' => false, 'message' => "Erreur de l'enregistrement de l'image: problème de permission ou format non valide.", 'format' => $extension], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); // code 500 |
| 86 | echo json_encode(['success' => false, 'message' => "Erreur de l'enregistrement de l'image: problème de permission ou format non valide.", 'format' => $extension]); | ||
| 87 | } | 84 | } |
| 88 | else{ | 85 | else{ |
| 89 | $params_array = explode('_', $request_params); // head_favicon, header_logo, header_background, footer_logo | 86 | $params_array = explode('_', $request_params); // head_favicon, header_logo, header_background, footer_logo |
| @@ -111,23 +108,20 @@ class HeadFootController | |||
| 111 | $entityManager->persist($asset); | 108 | $entityManager->persist($asset); |
| 112 | } | 109 | } |
| 113 | $entityManager->flush(); | 110 | $entityManager->flush(); |
| 114 | echo json_encode(['success' => true, 'location' => Asset::USER_PATH . $name, 'mime_type' => $mime_type]); | 111 | return new JsonResponse(['success' => true, 'location' => Asset::USER_PATH . $name, 'mime_type' => $mime_type]); |
| 115 | } | 112 | } |
| 116 | else{ | 113 | else{ |
| 117 | http_response_code(500); | 114 | return new JsonResponse(['success' => false, 'message' => "Erreur noeud non trouvé, c'est pas du tout normal!"], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); // code 500 |
| 118 | echo json_encode(['success' => false, 'message' => "Erreur noeud non trouvé, c'est pas du tout normal!"]); | ||
| 119 | } | 115 | } |
| 120 | } | 116 | } |
| 121 | } | 117 | } |
| 122 | die; | ||
| 123 | } | 118 | } |
| 124 | 119 | ||
| 125 | static public function displaySocialNetwork(EntityManager $entityManager, string $request_params, array $json): void | 120 | static public function displaySocialNetwork(EntityManager $entityManager, string $request_params, array $json): JsonResponse |
| 126 | { | 121 | { |
| 127 | $params_array = explode('_', $request_params); | 122 | $params_array = explode('_', $request_params); |
| 128 | if(count($params_array) !== 2){ | 123 | if(count($params_array) !== 2){ |
| 129 | echo json_encode(['success' => false]); | 124 | return new JsonResponse(['success' => false]); |
| 130 | die; | ||
| 131 | } | 125 | } |
| 132 | 126 | ||
| 133 | $model = new Model($entityManager); | 127 | $model = new Model($entityManager); |
| @@ -138,11 +132,10 @@ class HeadFootController | |||
| 138 | $node_data->updateData('social_show', $social_show); | 132 | $node_data->updateData('social_show', $social_show); |
| 139 | 133 | ||
| 140 | $entityManager->flush(); | 134 | $entityManager->flush(); |
| 141 | echo json_encode(['success' => true, 'checked' => $json['checked']]); | 135 | return new JsonResponse(['success' => true, 'checked' => $json['checked']]); |
| 142 | } | 136 | } |
| 143 | else{ | 137 | else{ |
| 144 | echo json_encode(['success' => false]); | 138 | return new JsonResponse(['success' => false]); |
| 145 | } | 139 | } |
| 146 | die; | ||
| 147 | } | 140 | } |
| 148 | } \ No newline at end of file | 141 | } \ No newline at end of file |
