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.                     //'contact_type' => $user->getType(),
  61.                     //'order_number' => $user->getOrder(),
  62.                     'name01' => $user->getName01(),
  63.                     'name02' => $user->getName02(),
  64.                     'kana01' => $user->getKana01(),
  65.                     'kana02' => $user->getKana02(),
  66.                     'postal_code' => $user->getPostalCode(),
  67.                     'pref' => $user->getPref(),
  68.                     'addr01' => $user->getAddr01(),
  69.                     'addr02' => $user->getAddr02(),
  70.                     'phone_number' => $user->getPhoneNumber(),
  71.                     'email' => $user->getEmail(),
  72.                 ],
  73.             );
  74.         }
  75.         // FRONT_CONTACT_INDEX_INITIALIZE
  76.         $event = new EventArgs(
  77.             [
  78.                 'builder' => $builder,
  79.             ],
  80.             $request
  81.         );
  82.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_CONTACT_INDEX_INITIALIZE);
  83.         $form $builder->getForm();
  84.         $form->handleRequest($request);
  85.         if ($form->isSubmitted() && $form->isValid()) {
  86.             switch ($request->get('mode')) {
  87.                 case 'confirm':
  88.                     return $this->render('Contact/confirm.twig', [
  89.                         'form' => $form->createView(),
  90.                         'Page' => $this->pageRepository->getPageByRoute('contact_confirm'),
  91.                     ]);
  92.                 case 'complete':
  93.                     $data $form->getData();
  94.                     $event = new EventArgs(
  95.                         [
  96.                             'form' => $form,
  97.                             'data' => $data,
  98.                         ],
  99.                         $request
  100.                     );
  101.                     $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_CONTACT_INDEX_COMPLETE);
  102.                     $data $event->getArgument('data');
  103.                     // メール送信
  104.                     $this->mailService->sendContactMail($data);
  105.                     return $this->redirect($this->generateUrl('contact_complete'));
  106.             }
  107.         }
  108.         return [
  109.             'form' => $form->createView(),
  110.         ];
  111.     }
  112.     /**
  113.      * お問い合わせ完了画面.
  114.      *
  115.      * @Route("/contact/complete", name="contact_complete", methods={"GET"})
  116.      * @Template("Contact/complete.twig")
  117.      */
  118.     public function complete()
  119.     {
  120.         return [];
  121.     }
  122. }