app/Customize/Controller/TopController.php line 43

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Customize\Controller;
  13. use Customize\Event\EccubeEvents;
  14. use Customize\Form\Type\ContactType;
  15. use Eccube\Controller\AbstractController;
  16. use Eccube\Event\EventArgs;
  17. use Eccube\Service\MailService;
  18. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\Routing\Annotation\Route;
  21. class TopController extends AbstractController
  22. {
  23.     /**
  24.      * @var MailService
  25.      */
  26.     protected $mailService;
  27.     /**
  28.      * ContactController constructor.
  29.      *
  30.      * @param MailService $mailService
  31.      */
  32.     public function __construct(MailService $mailService)
  33.     {
  34.         $this->mailService $mailService;
  35.     }
  36.     /**
  37.      * @Route("/", name="homepage", methods={"GET","POST"})
  38.      */
  39.     public function index(Request $request)
  40.     {
  41.         if ($this->isGranted('ROLE_USER')) {
  42.             $socketHostUrl getenv('SOCKET_HOST_URL');
  43.             $Customer $this->getUser();
  44.             $customerId $Customer->getId();
  45.             $randomBytes random_bytes(32);
  46.             $token hash('sha256'$randomBytes);
  47.             $hashedToken hash('sha256'$token);
  48.             $Customer->setToken($hashedToken);
  49.             $this->entityManager->persist($Customer);
  50.             $this->entityManager->flush();
  51.             return $this->render('index.twig', [
  52.                 'socketHostUrl' => $socketHostUrl,
  53.                 'customerId' => $customerId,
  54.                 'token' => $token,
  55.             ]);
  56.         } else {
  57.             // 未ログインの場合、LPを表示
  58.             $builder $this->formFactory->createNamedBuilder(''ContactType::class);
  59.             $event = new EventArgs(
  60.                 [
  61.                     'builder' => $builder,
  62.                 ],
  63.                 $request
  64.             );
  65.             $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_TOP_INDEX_INITIALIZE);
  66.             $form $builder->getForm();
  67.             $form->handleRequest($request);
  68.             $formResult "";
  69.             // フォームサブミット
  70.             if ($form->isSubmitted() && $form->isValid()) {
  71.                     $data $form->getData();
  72.                     $event = new EventArgs(
  73.                         [
  74.                             'form' => $form,
  75.                             'data' => $data,
  76.                         ],
  77.                         $request
  78.                     );
  79.                     $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_CONTACT_INDEX_COMPLETE);
  80.                     $data $event->getArgument('data');
  81.                     // メール送信
  82.                     $this->mailService->sendContactMail($data);
  83.                     $formResult "お問い合わせを送信しました。";
  84.             }
  85.             return $this->render('landing_page.twig', [
  86.                 'form' => $form->createView(),
  87.                 'formResult' => $formResult
  88.             ]);
  89.         }
  90.     }
  91. }