app/Customize/Controller/ContactController.php line 93

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 Customize\Form\Type\Front\ContactType;
  18. use Eccube\Repository\PageRepository;
  19. use Customize\Service\MailService;
  20. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. class ContactController extends AbstractController
  24. {
  25.     /**
  26.      * @var MailService
  27.      */
  28.     protected $mailService;
  29.     /**
  30.      * @var PageRepository
  31.      */
  32.     private $pageRepository;
  33.     /**
  34.      * ContactController constructor.
  35.      *
  36.      * @param MailService $mailService
  37.      * @param PageRepository $pageRepository
  38.      */
  39.     public function __construct(
  40.         MailService $mailService,
  41.         PageRepository $pageRepository)
  42.     {
  43.         $this->mailService $mailService;
  44.         $this->pageRepository $pageRepository;
  45.     }
  46.     /**
  47.      * お問い合わせ画面.
  48.      *
  49.      * @Route("/contact", name="contact", methods={"GET", "POST"})
  50.      * @Route("/contact", name="contact_confirm", methods={"GET", "POST"})
  51.      * @Template("Contact/index.twig")
  52.      */
  53.     public function index(Request $request)
  54.     {
  55.         $builder $this->formFactory->createBuilder(ContactType::class);
  56.         $user null;
  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.                     'school' => $user->getSchool(),
  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$user);
  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. }