src/Controller/FrontController.php line 72

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Api\SalesforceRest\Controllers\ApiContactController;
  4. use App\Entity\ContactMail;
  5. use App\Service\AccountManager;
  6. use App\Service\ContactMailManager;
  7. use App\Service\ContactManager;
  8. use App\Service\LanguageManager;
  9. use App\Service\MailManager;
  10. use App\Service\NotificationManager;
  11. use App\Service\NotificationService;
  12. use App\Service\RequestManager;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use ReCaptcha\ReCaptcha;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\RequestStack;
  17. use Symfony\Component\HttpFoundation\Response;
  18. class FrontController extends EntityController
  19. {
  20.     private AccountManager $accountManager;
  21.     private ContactManager $contactManager;
  22.     private MailManager $mailManager;
  23.     private ContactMailManager $contactMailManager;
  24.     private RequestManager $requestManager;
  25.     /**
  26.      * FrontController constructor.
  27.      * @param EntityManagerInterface $entityManager
  28.      * @param NotificationManager $notificationManager
  29.      * @param RequestStack $request
  30.      * @param LanguageManager $languageManager
  31.      * @param AccountManager $accountManager
  32.      * @param ContactManager $contactManager
  33.      * @param MailManager $mailManager
  34.      * @param ContactMailManager $contactMailManager
  35.      */
  36.     public function __construct(EntityManagerInterface $entityManager,
  37.                                 NotificationManager $notificationManager,
  38.                                 RequestStack $request,
  39.                                 LanguageManager $languageManager,
  40.                                 AccountManager $accountManager,
  41.                                 ContactManager $contactManager,
  42.                                 MailManager $mailManager,
  43.                                 ContactMailManager $contactMailManager,
  44.                                 RequestManager $requestManager,
  45.                                 NotificationService $notificationService
  46.     )
  47.     {
  48. //<<<<<<< HEAD
  49. //        parent::__construct( $entityManager, $notificationManager, $request, $languageManager, $session, $notificationService);
  50. //=======
  51.         parent::__construct($entityManager$notificationManager$request$languageManager$notificationService);
  52. //>>>>>>> 92-achat-unique
  53.         $this->accountManager $accountManager;
  54.         $this->contactManager $contactManager;
  55.         $this->mailManager $mailManager;
  56.         $this->contactMailManager $contactMailManager;
  57.         $this->requestManager $requestManager;
  58.     }
  59.     /**
  60.      * The default page
  61.      * @return Response
  62.      */
  63.     public function indexNoLocale() : Response
  64.     {
  65.         $lang = ['_locale'=> 'fr'];
  66.         if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  67.             $browserLanguage substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 02);
  68.             if($browserLanguage == 'fr' || $browserLanguage == 'it') {
  69.                 $lang = ['_locale' => $browserLanguage];
  70.             }
  71.         }
  72.         return $this->redirectToRoute('Index'$lang);
  73.     }
  74.     /**
  75.      * The default page
  76.      * @return Response
  77.      */
  78.     public function index(Request $request) : Response
  79.     {
  80.         // check if the contact is connected first
  81.         // get the contact from session
  82.         $referent $request->getSession()->get('contact'null);
  83.         if(!is_null($referent)){
  84.             // if contact has accounts and is not null
  85.             if(count($referent->getAccounts()) > 0){
  86.                 // if the contact has only one account, we redirect to it
  87.                 $response $this->redirectToRoute('AccountIndex', ['salesforceAccountId' => $referent->getAccounts()[0]->getSalesforceId()]);
  88.             }
  89.             else{
  90.                 $response $this->redirectToRoute('Logout');
  91.             }
  92.         }
  93.         // If not connected, redirect to login route
  94.         else{
  95.             $response $this->redirectToRoute('PreLogin');
  96.         }
  97.         return $response;
  98.     }
  99.     /**
  100.      * To contact us
  101.      * @param Request $request
  102.      * @return Response
  103.      */
  104.     public function viewContactMail(Request $request) : Response
  105.     {
  106.         $contactFormSubmitted $request->request->get('submitContact'null);
  107.         // get the motives from Salesforce
  108.         $motives ApiContactController::getContactMotives();
  109.         // If the contact form has been submitted
  110.         if(!is_null($contactFormSubmitted)){
  111.             $recaptcha = new ReCaptcha($_ENV['G_RECAPTCHA_SECRET_KEY']);
  112.             $resp $recaptcha->verify($request->request->get('g-recaptcha-response'), $request->getClientIp());
  113.             if (!$resp->isSuccess()) {
  114.                 $this->notificationManager::addError('Le reCAPTCHA est incorrect. Veuillez réessayer.');
  115.             }
  116.             else {
  117.                 $motive $request->request->get('motive'null);
  118.                 $mailMessage $request->request->get('mailMessage'null);
  119.                 $email $request->request->get('email'null);
  120.                 $this->requestManager->saveNotConnectedRequest($motive$mailMessage$email$motives);
  121.             }
  122.         }
  123.         // get the motives from Salesforce
  124.         $this->addViewDataArray('motives'$motives);
  125.         $this->createFlashs();
  126.         // if the form is submitted
  127.         return $this->render('contact_us.html.twig'$this->viewData);
  128.     }
  129. }