From b76547767ae897b6de752c56e2cef6079ca4abcb Mon Sep 17 00:00:00 2001 From: polo Date: Thu, 11 Jun 2026 01:35:57 +0200 Subject: =?UTF-8?q?classe=20EmailForm=20=C3=A0=20Email=20et=20d=C3=A9tacha?= =?UTF-8?q?ble=20de=20Node?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/ContactFormController.php | 27 +++++++++++---------------- src/controller/PageManagementController.php | 17 +++++++++++++---- src/controller/UserController.php | 6 +++--- 3 files changed, 27 insertions(+), 23 deletions(-) (limited to 'src/controller') diff --git a/src/controller/ContactFormController.php b/src/controller/ContactFormController.php index 6b89161..cbc1837 100644 --- a/src/controller/ContactFormController.php +++ b/src/controller/ContactFormController.php @@ -4,13 +4,15 @@ declare(strict_types=1); use Doctrine\ORM\EntityManager; +use App\Entity\EmailForm; +use App\Entity\Email; use Symfony\Component\HttpFoundation\JsonResponse; class ContactFormController { static public function keepEmails(EntityManager $entityManager, array $json): JsonResponse { - $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); + $form_data = $entityManager->find(EmailForm::class, $json['id']); $form_data->updateData('keep_emails', $json['checked'] ? true : false); $entityManager->persist($form_data); $entityManager->flush(); @@ -18,7 +20,7 @@ class ContactFormController } static public function setEmailsRetentionPeriod(EntityManager $entityManager, array $json): JsonResponse { - $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); + $form_data = $entityManager->find(EmailForm::class, $json['id']); $form_data->updateData($json['field'], (int)$json['months']); $entityManager->persist($form_data); $entityManager->flush(); @@ -28,22 +30,15 @@ class ContactFormController { $form = new FormValidation($json, 'email_params'); - $error = ''; if($form->validate()){ - $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); + $form_data = $entityManager->find(EmailForm::class, $json['id']); $form_data->updateData($json['what_param'], trim($json['value'])); - $entityManager->persist($form_data); + $entityManager->persist($form_data); // ?? $entityManager->flush(); - } - else{ - $error = $form->getErrors()[0]; // la 1ère erreur sera affichée - } - - if(empty($error)){ return new JsonResponse(['success' => true]); } else{ - return new JsonResponse(['success' => false, 'error' => $error]); + return new JsonResponse(['success' => false, 'error' => $form->getErrors()[0]]); // la 1ère erreur sera affichée } } @@ -55,7 +50,7 @@ class ContactFormController $error = ''; if($form->validate()){ // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur - $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); + $form_data = $entityManager->find(EmailForm::class, $json['id']); if($form_data === null){ return new JsonResponse(['success' => false, 'error' => 'server_error'], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); // code 500 } @@ -78,7 +73,7 @@ class ContactFormController static public function sendTestEmail(EntityManager $entityManager, array $json): JsonResponse { // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur - $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); + $form_data = $entityManager->find(EmailForm::class, $json['id']); if($form_data === null){ return new JsonResponse(['success' => false, 'error' => 'server_error'], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); } @@ -92,14 +87,14 @@ class ContactFormController } static public function deleteEmail(EntityManager $entityManager, array $json): JsonResponse { - $email = $entityManager->find('App\Entity\Email', $json['id']); + $email = $entityManager->find(Email::class, $json['id']); $entityManager->remove($email); $entityManager->flush(); return new JsonResponse(['success' => true]); } static public function toggleSensitiveEmail(EntityManager $entityManager, array $json): JsonResponse { - $email = $entityManager->find('App\Entity\Email', $json['id']); + $email = $entityManager->find(Email::class, $json['id']); $email->makeSensitive($json['checked']); $entityManager->flush(); return new JsonResponse(['success' => true, 'checked' => $json['checked'], 'deletion_date' => $email->getDeletionDate()->format('d/m/Y')]); diff --git a/src/controller/PageManagementController.php b/src/controller/PageManagementController.php index a43f36c..c575077 100644 --- a/src/controller/PageManagementController.php +++ b/src/controller/PageManagementController.php @@ -6,6 +6,7 @@ declare(strict_types=1); use App\Entity\Page; use App\Entity\Node; use App\Entity\NodeData; +use App\Entity\EmailForm; //use App\Entity\Image; use Doctrine\ORM\EntityManager; use Symfony\Component\HttpFoundation\InputBag; @@ -144,7 +145,9 @@ class PageManagementController } $block = new Node($request->request->get("bloc_select"), $position, $main, $page); - $data = new NodeData(['title' => trim(htmlspecialchars($request->request->get("bloc_title")))], $block); + + $DataClass = $request->request->get("bloc_select") === 'form' ? EmailForm::class : NodeData::class; // cas particulier avec bloc 'email_form' + $data = new $DataClass(['title' => trim(htmlspecialchars($request->request->get("bloc_title")))], $block); // valeurs par défaut if($request->request->get("bloc_select") === 'post_block'){ @@ -200,8 +203,15 @@ class PageManagementController if(isset($page)){ $entityManager->persist($page); } + $block->getNodeData()->setNode(null); $entityManager->remove($block); - $entityManager->flush(); + try{ + $entityManager->flush(); + } + catch(Exception $e){ + // utiliser une flash error + return new RedirectResponse((string)new URL(['page' => $request->query->get('page'), 'mode' => 'page_modif', 'error' => $e->getMessage()])); + } } return new RedirectResponse((string)new URL(['page' => $request->query->get('page'), 'mode' => 'page_modif'])); @@ -277,8 +287,7 @@ class PageManagementController $chrono_order = false; } else{ - echo json_encode(['success' => false]); - die; + return new JsonResponse(['success' => false]); } $model->getNode()->getNodeData()->setChronoOrder($chrono_order); $entityManager->flush(); diff --git a/src/controller/UserController.php b/src/controller/UserController.php index ddba33a..03686ee 100644 --- a/src/controller/UserController.php +++ b/src/controller/UserController.php @@ -122,7 +122,7 @@ class UserController $url = new URL; isset($_GET['from']) ? $url->addParams(['page' => $_GET['from']]) : ''; isset($_GET['id']) ? $url->addParams(['id' => $_GET['id']]) : ''; - return new RedirectResponse('Location: ' . $url); + return new RedirectResponse((string)$url); } // user @@ -161,7 +161,7 @@ class UserController sleep(1); $url->addParams(['error_username' => $error]); } - return new RedirectResponse('Location: ' . $url); + return new RedirectResponse((string)$url); } // user @@ -200,7 +200,7 @@ class UserController sleep(1); $url->addParams(['error_password' => $error]); } - return new RedirectResponse('Location: ' . $url); + return new RedirectResponse((string)$url); } // dans une classe mère ou un trait après découpage de UserController? -- cgit v1.2.3