diff options
Diffstat (limited to 'src/controller/ContactFormController.php')
| -rw-r--r-- | src/controller/ContactFormController.php | 27 |
1 files changed, 11 insertions, 16 deletions
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 @@ | |||
| 4 | declare(strict_types=1); | 4 | declare(strict_types=1); |
| 5 | 5 | ||
| 6 | use Doctrine\ORM\EntityManager; | 6 | use Doctrine\ORM\EntityManager; |
| 7 | use App\Entity\EmailForm; | ||
| 8 | use App\Entity\Email; | ||
| 7 | use Symfony\Component\HttpFoundation\JsonResponse; | 9 | use Symfony\Component\HttpFoundation\JsonResponse; |
| 8 | 10 | ||
| 9 | class ContactFormController | 11 | class ContactFormController |
| 10 | { | 12 | { |
| 11 | static public function keepEmails(EntityManager $entityManager, array $json): JsonResponse | 13 | static public function keepEmails(EntityManager $entityManager, array $json): JsonResponse |
| 12 | { | 14 | { |
| 13 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); | 15 | $form_data = $entityManager->find(EmailForm::class, $json['id']); |
| 14 | $form_data->updateData('keep_emails', $json['checked'] ? true : false); | 16 | $form_data->updateData('keep_emails', $json['checked'] ? true : false); |
| 15 | $entityManager->persist($form_data); | 17 | $entityManager->persist($form_data); |
| 16 | $entityManager->flush(); | 18 | $entityManager->flush(); |
| @@ -18,7 +20,7 @@ class ContactFormController | |||
| 18 | } | 20 | } |
| 19 | static public function setEmailsRetentionPeriod(EntityManager $entityManager, array $json): JsonResponse | 21 | static public function setEmailsRetentionPeriod(EntityManager $entityManager, array $json): JsonResponse |
| 20 | { | 22 | { |
| 21 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); | 23 | $form_data = $entityManager->find(EmailForm::class, $json['id']); |
| 22 | $form_data->updateData($json['field'], (int)$json['months']); | 24 | $form_data->updateData($json['field'], (int)$json['months']); |
| 23 | $entityManager->persist($form_data); | 25 | $entityManager->persist($form_data); |
| 24 | $entityManager->flush(); | 26 | $entityManager->flush(); |
| @@ -28,22 +30,15 @@ class ContactFormController | |||
| 28 | { | 30 | { |
| 29 | $form = new FormValidation($json, 'email_params'); | 31 | $form = new FormValidation($json, 'email_params'); |
| 30 | 32 | ||
| 31 | $error = ''; | ||
| 32 | if($form->validate()){ | 33 | if($form->validate()){ |
| 33 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); | 34 | $form_data = $entityManager->find(EmailForm::class, $json['id']); |
| 34 | $form_data->updateData($json['what_param'], trim($json['value'])); | 35 | $form_data->updateData($json['what_param'], trim($json['value'])); |
| 35 | $entityManager->persist($form_data); | 36 | $entityManager->persist($form_data); // ?? |
| 36 | $entityManager->flush(); | 37 | $entityManager->flush(); |
| 37 | } | ||
| 38 | else{ | ||
| 39 | $error = $form->getErrors()[0]; // la 1ère erreur sera affichée | ||
| 40 | } | ||
| 41 | |||
| 42 | if(empty($error)){ | ||
| 43 | return new JsonResponse(['success' => true]); | 38 | return new JsonResponse(['success' => true]); |
| 44 | } | 39 | } |
| 45 | else{ | 40 | else{ |
| 46 | return new JsonResponse(['success' => false, 'error' => $error]); | 41 | return new JsonResponse(['success' => false, 'error' => $form->getErrors()[0]]); // la 1ère erreur sera affichée |
| 47 | } | 42 | } |
| 48 | } | 43 | } |
| 49 | 44 | ||
| @@ -55,7 +50,7 @@ class ContactFormController | |||
| 55 | $error = ''; | 50 | $error = ''; |
| 56 | if($form->validate()){ | 51 | if($form->validate()){ |
| 57 | // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur | 52 | // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur |
| 58 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); | 53 | $form_data = $entityManager->find(EmailForm::class, $json['id']); |
| 59 | if($form_data === null){ | 54 | if($form_data === null){ |
| 60 | return new JsonResponse(['success' => false, 'error' => 'server_error'], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); // code 500 | 55 | return new JsonResponse(['success' => false, 'error' => 'server_error'], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); // code 500 |
| 61 | } | 56 | } |
| @@ -78,7 +73,7 @@ class ContactFormController | |||
| 78 | static public function sendTestEmail(EntityManager $entityManager, array $json): JsonResponse | 73 | static public function sendTestEmail(EntityManager $entityManager, array $json): JsonResponse |
| 79 | { | 74 | { |
| 80 | // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur | 75 | // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur |
| 81 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); | 76 | $form_data = $entityManager->find(EmailForm::class, $json['id']); |
| 82 | if($form_data === null){ | 77 | if($form_data === null){ |
| 83 | return new JsonResponse(['success' => false, 'error' => 'server_error'], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); | 78 | return new JsonResponse(['success' => false, 'error' => 'server_error'], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); |
| 84 | } | 79 | } |
| @@ -92,14 +87,14 @@ class ContactFormController | |||
| 92 | } | 87 | } |
| 93 | static public function deleteEmail(EntityManager $entityManager, array $json): JsonResponse | 88 | static public function deleteEmail(EntityManager $entityManager, array $json): JsonResponse |
| 94 | { | 89 | { |
| 95 | $email = $entityManager->find('App\Entity\Email', $json['id']); | 90 | $email = $entityManager->find(Email::class, $json['id']); |
| 96 | $entityManager->remove($email); | 91 | $entityManager->remove($email); |
| 97 | $entityManager->flush(); | 92 | $entityManager->flush(); |
| 98 | return new JsonResponse(['success' => true]); | 93 | return new JsonResponse(['success' => true]); |
| 99 | } | 94 | } |
| 100 | static public function toggleSensitiveEmail(EntityManager $entityManager, array $json): JsonResponse | 95 | static public function toggleSensitiveEmail(EntityManager $entityManager, array $json): JsonResponse |
| 101 | { | 96 | { |
| 102 | $email = $entityManager->find('App\Entity\Email', $json['id']); | 97 | $email = $entityManager->find(Email::class, $json['id']); |
| 103 | $email->makeSensitive($json['checked']); | 98 | $email->makeSensitive($json['checked']); |
| 104 | $entityManager->flush(); | 99 | $entityManager->flush(); |
| 105 | return new JsonResponse(['success' => true, 'checked' => $json['checked'], 'deletion_date' => $email->getDeletionDate()->format('d/m/Y')]); | 100 | return new JsonResponse(['success' => true, 'checked' => $json['checked'], 'deletion_date' => $email->getDeletionDate()->format('d/m/Y')]); |
