src/Controller/EmailController.php line 49

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Client;
  4. use App\Entity\Emails;
  5. use App\Form\EmailsType;
  6. use App\Services\CallApiServices;
  7. use App\Services\QuestionMailService;
  8. use PharIo\Manifest\Email;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. class EmailController extends AbstractController
  15. {
  16.     private $callApiServices;
  17.     private $questionMailService;
  18.     public function __construct(CallApiServices $callApiServicesQuestionMailService $questionMailService)
  19.     {
  20.         $this->callApiServices $callApiServices;
  21.         $this->questionMailService $questionMailService;
  22.     }
  23.     /**
  24.      * @Route("/email", name="app_email")
  25.      */
  26.     public function index(): Response
  27.     {
  28.         $client $this->getUser();
  29.         $client $this->questionMailService->getEmail($this->callApiServices$client);
  30.         // dd($client);
  31.         return $this->render('email/email.html.twig');
  32.     }
  33.     /**
  34.      * @Route("/receptionMail", name="reception_mail")
  35.      */
  36.     public function reception(CallApiServices $callApiServices): Response
  37.     {
  38.         return $this->render('email/reception.html.twig');
  39.     }
  40.     /**
  41.      * @Route("/send", name="envoie_mail")
  42.      */
  43.     public function send(): Response
  44.     {
  45.         return $this->render('email/envoie.html.twig');
  46.     }
  47.     /**
  48.      * @Route("/mailView/{id}", name="mail_view")
  49.      */
  50.     public function mailView(EntityManagerInterface $em$id): Response
  51.     {
  52.         $client $this->getUser();
  53.         if ($client instanceof Client) {
  54.             $mail $client->getEmailsSend();
  55.         }
  56.         foreach ($mail as $key => $mailId) {
  57.             $previous array_key_exists($key 1$mail) ? $mail[$key 1] : false;
  58.             $next array_key_exists($key 1$mail) ? $mail[$key 1] : false;
  59.             $last array_key_last($mail);
  60.             $first array_key_first($mail);
  61.             if ($previous == false) {
  62.                 $previous $last;
  63.             } else {
  64.                 $previous $key 1;
  65.             }
  66.             if ($next == false) {
  67.                 $next $first;
  68.             } else {
  69.                 $next $key 1;
  70.             }
  71.             $newMail[$key] = [
  72.                 'previous' => $previous,
  73.                 'current' => $key,
  74.                 'next' => $next
  75.             ];
  76.         }
  77.         return $this->render('email/mailView.html.twig', [
  78.             "mail" => $mail[$id],
  79.             "current" => $newMail[$id],
  80.             "previous" => $newMail[$id]['previous'],
  81.             "next" => $newMail[$id]['next']
  82.         ]);
  83.     }
  84.     /**
  85.      * @Route("/receivedMail/{id}", name="app_receivedMail")
  86.      */
  87.     public function receivedMail(EntityManagerInterface $em$idCallApiServices $callApiServices): Response
  88.     {
  89.         $client $this->getUser();
  90.         $client $this->questionMailService->getEmail($this->callApiServices$client);
  91.         if ($client instanceof Client) {
  92.             $mail $client->getEmailsRecieved();
  93.         }
  94.         foreach ($mail as $key => $mailId) {
  95.             $previous array_key_exists($key 1$mail) ? $mail[$key 1] : false;
  96.             $next array_key_exists($key 1$mail) ? $mail[$key 1] : false;
  97.             $last array_key_last($mail);
  98.             $first array_key_first($mail);
  99.             if ($previous == false) {
  100.                 $previous $last;
  101.             } else {
  102.                 $previous $key 1;
  103.             }
  104.             if ($next == false) {
  105.                 $next $first;
  106.             } else {
  107.                 $next $key 1;
  108.             }
  109.             $newMail[$key] = [
  110.                 'previous' => $previous,
  111.                 'current' => $key,
  112.                 'next' => $next
  113.             ];
  114.             $isRead $mail[$key]['isRead'] = true;
  115.             $callApiServices->questionsMailMajMessage($mail[$key]['serviceId'], $mail[$key]['clientId'], $mail[$key]['complementId'], $mail[$key]['id'], $mail[$key]['answered'], $isRead);
  116.         }
  117.         return $this->render('email/receivedMailView.html.twig', [
  118.             "mail" => $mail[$id],
  119.             "current" => $newMail[$id],
  120.             "previous" => $newMail[$id]['previous'],
  121.             "next" => $newMail[$id]['next']
  122.         ]);
  123.     }
  124.     /**
  125.      * @Route("/delete/{id}", name="delete")
  126.      */
  127.     public function delete(Emails $emailEntityManagerInterface $em): Response
  128.     {
  129.         $em->remove($email);
  130.         $em->flush();
  131.         return $this->redirectToRoute("reception_mail");
  132.     }
  133.     /**
  134.      * @Route("/questionMail/{id}", name="question_mail")
  135.      */
  136.     public function questionMail(Request $requestEntityManagerInterface $em$idCallApiServices $callApiServicesQuestionMailService $questionMailService): Response
  137.     {
  138.         $serviceId $this->getParameter('app.serviceId');
  139.         $accountId $this->getParameter('app.accountId');
  140.         
  141.         $conseiller $callApiServices->conseillerEtPlanning($id$serviceId);
  142.         $email = new Emails();
  143.         $form $this->createForm(EmailsType::class, $email);
  144.         $form->handleRequest($request);
  145.         if ($form->isSubmitted() && $form->isValid()) {
  146.             $email->setSender($this->getUser());
  147.             $sender $email->getSender();
  148.             $emailSend $callApiServices->questionsMailEnvoiMessage($serviceId$sender->getClientId(), $conseiller[0]['complementId'], $email->getTitle(), $email->getContent(), $email->getDate());
  149.             if (isset($emailSend['responseCode'])) {
  150.                 $this->addFlash("messageErreur""Votre message n'a pas été envoyé car vous ne disposé pas de credit suffisant.");
  151.                 return $this->render('email/questionMail.html.twig', [
  152.                     "mailForm" => $form->createView(),
  153.                     "conseiller" => $conseiller
  154.                 ]);
  155.             } else {
  156.                 if (isset($conseiller[0]['userMail'])){
  157.                     $questionMailService->sendEmail($conseiller$request);
  158.                     $this->addFlash("message""Votre message a été envoyé avec succès.");
  159.                     return $this->redirectToRoute("app_email");
  160.                 }
  161.                
  162.             }
  163.         }
  164.         return $this->render('email/questionMail.html.twig', [
  165.             "mailForm" => $form->createView(),
  166.             "conseiller" => $conseiller
  167.         ]);
  168.     }
  169. }