app/Customize/Controller/ContactController.php line 62

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