diff options
Diffstat (limited to 'src/controller/ContactFormController.php')
| -rw-r--r-- | src/controller/ContactFormController.php | 102 |
1 files changed, 0 insertions, 102 deletions
diff --git a/src/controller/ContactFormController.php b/src/controller/ContactFormController.php deleted file mode 100644 index 82e9b17..0000000 --- a/src/controller/ContactFormController.php +++ /dev/null | |||
| @@ -1,102 +0,0 @@ | |||
| 1 | <?php | ||
| 2 | // src/controller/ContactFormController.php | ||
| 3 | |||
| 4 | declare(strict_types=1); | ||
| 5 | |||
| 6 | use Doctrine\ORM\EntityManager; | ||
| 7 | use App\Entity\EmailForm; | ||
| 8 | use App\Entity\Email; | ||
| 9 | use Symfony\Component\HttpFoundation\JsonResponse; | ||
| 10 | |||
| 11 | class ContactFormController | ||
| 12 | { | ||
| 13 | static public function keepEmails(EntityManager $entityManager, array $json): JsonResponse | ||
| 14 | { | ||
| 15 | $form_data = $entityManager->find(EmailForm::class, $json['id']); | ||
| 16 | $form_data->updateData('keep_emails', $json['checked'] ? true : false); | ||
| 17 | $entityManager->persist($form_data); | ||
| 18 | $entityManager->flush(); | ||
| 19 | return new JsonResponse(['success' => true, 'checked' => $json['checked']]); | ||
| 20 | } | ||
| 21 | static public function setEmailsRetentionPeriod(EntityManager $entityManager, array $json): JsonResponse | ||
| 22 | { | ||
| 23 | $form_data = $entityManager->find(EmailForm::class, $json['id']); | ||
| 24 | $form_data->updateData($json['field'], (int)$json['months']); | ||
| 25 | $entityManager->persist($form_data); | ||
| 26 | $entityManager->flush(); | ||
| 27 | return new JsonResponse(['success' => true, 'months' => $json['months']]); | ||
| 28 | } | ||
| 29 | static public function setEmailParam(EntityManager $entityManager, array $json): JsonResponse | ||
| 30 | { | ||
| 31 | $form = new FormValidation($json, ValidationStrategy::EmailParam); | ||
| 32 | |||
| 33 | if($form->validate()){ | ||
| 34 | $form_data = $entityManager->find(EmailForm::class, $json['id']); | ||
| 35 | $form_data->updateData($json['what_param'], trim($json['value'])); | ||
| 36 | $entityManager->persist($form_data); // ?? | ||
| 37 | $entityManager->flush(); | ||
| 38 | return new JsonResponse(['success' => true]); | ||
| 39 | } | ||
| 40 | else{ | ||
| 41 | return new JsonResponse(['success' => false, 'error' => $form->getError()]); | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | // les deux méthodes suivantes sont "factorisables", elles ne se distinguent que par la gestion ou non du formulaire rempli par le visiteur | ||
| 46 | static public function sendVisitorEmail(EntityManager $entityManager, array $json): JsonResponse | ||
| 47 | { | ||
| 48 | $form = new FormValidation($json, ValidationStrategy::EmailSend); | ||
| 49 | |||
| 50 | $error = ''; | ||
| 51 | if($form->validate()){ | ||
| 52 | // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur | ||
| 53 | $form_data = $entityManager->find(EmailForm::class, $json['id']); | ||
| 54 | if($form_data === null){ | ||
| 55 | return new JsonResponse(['success' => false, 'error' => 'server_error'], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); // code 500 | ||
| 56 | } | ||
| 57 | |||
| 58 | if(!EmailService::send($entityManager, $form_data, false, $form->getField('name'), $form->getField('email'), $form->getField('message'))){ | ||
| 59 | $error = 'email_not_sent'; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | else{ | ||
| 63 | $error = $form->getError(); | ||
| 64 | } | ||
| 65 | |||
| 66 | if(empty($error)){ | ||
| 67 | return new JsonResponse(['success' => true]); | ||
| 68 | } | ||
| 69 | else{ | ||
| 70 | return new JsonResponse(['success' => false, 'error' => $error]); | ||
| 71 | } | ||
| 72 | } | ||
| 73 | static public function sendTestEmail(EntityManager $entityManager, array $json): JsonResponse | ||
| 74 | { | ||
| 75 | // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur | ||
| 76 | $form_data = $entityManager->find(EmailForm::class, $json['id']); | ||
| 77 | if($form_data === null){ | ||
| 78 | return new JsonResponse(['success' => false, 'error' => 'server_error'], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); | ||
| 79 | } | ||
| 80 | |||
| 81 | if(EmailService::send($entityManager, $form_data, true, 'nom du visiteur', 'adresse@du_visiteur.fr', "TEST d'un envoi d'e-mail depuis le site web")){ | ||
| 82 | return new JsonResponse(['success' => true]); | ||
| 83 | } | ||
| 84 | else{ | ||
| 85 | return new JsonResponse(['success' => false, 'error' => 'email_not_sent']); | ||
| 86 | } | ||
| 87 | } | ||
| 88 | static public function deleteEmail(EntityManager $entityManager, array $json): JsonResponse | ||
| 89 | { | ||
| 90 | $email = $entityManager->find(Email::class, $json['id']); | ||
| 91 | $entityManager->remove($email); | ||
| 92 | $entityManager->flush(); | ||
| 93 | return new JsonResponse(['success' => true]); | ||
| 94 | } | ||
| 95 | static public function toggleSensitiveEmail(EntityManager $entityManager, array $json): JsonResponse | ||
| 96 | { | ||
| 97 | $email = $entityManager->find(Email::class, $json['id']); | ||
| 98 | $email->makeSensitive($json['checked']); | ||
| 99 | $entityManager->flush(); | ||
| 100 | return new JsonResponse(['success' => true, 'checked' => $json['checked'], 'deletion_date' => $email->getDeletionDate()->format('d/m/Y')]); | ||
| 101 | } | ||
| 102 | } \ No newline at end of file | ||
