src/Eccube/Controller/ContactController.php line 59

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 Eccube\Controller;
  13. use Eccube\Entity\Customer;
  14. use Eccube\Event\EccubeEvents;
  15. use Eccube\Event\EventArgs;
  16. use Eccube\Form\Type\Front\ContactType;
  17. use Eccube\Repository\PageRepository;
  18. use Eccube\Service\MailService;
  19. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. class ContactController extends AbstractController
  23. {
  24.     /**
  25.      * @var MailService
  26.      */
  27.     protected $mailService;
  28.     /**
  29.      * @var PageRepository
  30.      */
  31.     private $pageRepository;
  32.     /**
  33.      * ContactController constructor.
  34.      *
  35.      * @param MailService $mailService
  36.      * @param PageRepository $pageRepository
  37.      */
  38.     public function __construct(
  39.         MailService $mailService,
  40.         PageRepository $pageRepository)
  41.     {
  42.         $this->mailService $mailService;
  43.         $this->pageRepository $pageRepository;
  44.     }
  45.     /**
  46.      * お問い合わせ画面.
  47.      *
  48.      * @Route("/contact", name="contact", methods={"GET", "POST"})
  49.      * @Route("/contact", name="contact_confirm", methods={"GET", "POST"})
  50.      * @Template("Contact/index.twig")
  51.      */
  52.     public function index(Request $request)
  53.     {
  54.         $builder $this->formFactory->createBuilder(ContactType::class);
  55.         if ($this->isGranted('ROLE_USER')) {
  56.             /** @var Customer $user */
  57.             $user $this->getUser();
  58.             $builder->setData(
  59.                 [
  60.                     'company_name' => $user->getCompanyName(),
  61.                     'company_kana' => $user->getCompanyKana(),
  62.                     'shop_name' => $user->getShopName(),
  63.                     'shop_kana' => $user->getShopKana(),
  64.                     'name01' => $user->getName01(),
  65.                     'name02' => $user->getName02(),
  66.                     'kana01' => $user->getKana01(),
  67.                     'kana02' => $user->getKana02(),
  68.                     'postal_code' => $user->getPostalCode(),
  69.                     'pref' => $user->getPref(),
  70.                     'addr01' => $user->getAddr01(),
  71.                     'addr02' => $user->getAddr02(),
  72.                     'phone_number' => $user->getPhoneNumber(),
  73.                     'email' => $user->getEmail(),
  74.                 ]
  75.             );
  76.         }
  77.         // FRONT_CONTACT_INDEX_INITIALIZE
  78.         $event = new EventArgs(
  79.             [
  80.                 'builder' => $builder,
  81.             ],
  82.             $request
  83.         );
  84.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_CONTACT_INDEX_INITIALIZE);
  85.         $form $builder->getForm();
  86.         $form->handleRequest($request);
  87.         if ($form->isSubmitted() && $form->isValid()) {
  88.             switch ($request->get('mode')) {
  89.                 case 'confirm':
  90.                     return $this->render('Contact/confirm.twig', [
  91.                         'form' => $form->createView(),
  92.                         'Page' => $this->pageRepository->getPageByRoute('contact_confirm'),
  93.                     ]);
  94.                 case 'complete':
  95.                     $data $form->getData();
  96.                     $event = new EventArgs(
  97.                         [
  98.                             'form' => $form,
  99.                             'data' => $data,
  100.                         ],
  101.                         $request
  102.                     );
  103.                     $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_CONTACT_INDEX_COMPLETE);
  104.                     $data $event->getArgument('data');
  105.                     // メール送信
  106.                     $this->mailService->sendContactMail($data);
  107.                     return $this->redirect($this->generateUrl('contact_complete'));
  108.             }
  109.         }
  110.         return [
  111.             'form' => $form->createView(),
  112.         ];
  113.     }
  114.     /**
  115.      * お問い合わせ完了画面.
  116.      *
  117.      * @Route("/contact/complete", name="contact_complete", methods={"GET"})
  118.      * @Template("Contact/complete.twig")
  119.      */
  120.     public function complete()
  121.     {
  122.         return [];
  123.     }
  124. }