app/Customize/Controller/Contact2Controller.php line 61

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\Contact2Type;
  18. use Eccube\Repository\PageRepository;
  19. use Customize\Service\MailService;
  20. use Eccube\Entity\ProductClass;
  21. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use Symfony\Component\Routing\Annotation\Route;
  24. class Contact2Controller 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("/contact2", name="contact2", methods={"GET", "POST"})
  51.      * @Route("/contact2", name="contact2_confirm", methods={"GET", "POST"})
  52.      * @Template("Contact2/index.twig")
  53.      */
  54.     public function index(Request $request)
  55.     {
  56.         $builder $this->formFactory->createBuilder(Contact2Type::class);
  57.         if ($this->isGranted('ROLE_USER')) {
  58.             /** @var Customer $user */
  59.             $user $this->getUser();
  60.             $builder->setData(
  61.                 [
  62.                     'company_name' => getCompanyName(),
  63.                     'name01' => $user->getName01(),
  64.                     'name02' => $user->getName02(),
  65.                     'kana01' => $user->getKana01(),
  66.                     'kana02' => $user->getKana02(),
  67.                     'postal_code' => $user->getPostalCode(),
  68.                     'pref' => $user->getPref(),
  69.                     'addr01' => $user->getAddr01(),
  70.                     'addr02' => $user->getAddr02(),
  71.                     'phone_number' => $user->getPhoneNumber(),
  72.                     'saleType' => $ProductClass->getSaleType(),
  73.                     'adDetail' => getAdDetail(),
  74.                     'landArea' => getLandArea(),
  75.                     'buildArea'=> getBuildArea(),
  76.                     'year'=> getYear(),
  77.                     'chimoku'=> getChimoku(),
  78.                     'meiginin'=> getMeiginin(),
  79.                     'salePrice' => getSalePrice(),
  80.                     'email' => $user->getEmail(),
  81.                 ]
  82.             );
  83.         }
  84.         // FRONT_CONTACT_INDEX_INITIALIZE
  85.         $event = new EventArgs(
  86.             [
  87.                 'builder' => $builder,
  88.             ],
  89.             $request
  90.         );
  91.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_CONTACT_INDEX_INITIALIZE);
  92.         $form $builder->getForm();
  93.         $form->handleRequest($request);
  94.         if ($form->isSubmitted() && $form->isValid()) {
  95.             switch ($request->get('mode')) {
  96.                 case 'confirm':
  97.                     return $this->render('Contact2/confirm.twig', [
  98.                         'form' => $form->createView(),
  99.                         'Page' => $this->pageRepository->getPageByRoute('contact_confirm'),
  100.                     ]);
  101.                 case 'complete':
  102.                     $data $form->getData();
  103.                     $event = new EventArgs(
  104.                         [
  105.                             'form' => $form,
  106.                             'data' => $data,
  107.                         ],
  108.                         $request
  109.                     );
  110.                     $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_CONTACT_INDEX_COMPLETE);
  111.                     $data $event->getArgument('data');
  112.                     // メール送信
  113.                     $this->mailService->sendContactMail($data);
  114.                     return $this->redirect($this->generateUrl('contact2_complete'));
  115.             }
  116.         }
  117.         return [
  118.             'form' => $form->createView(),
  119.         ];
  120.     }
  121.     /**
  122.      * お問い合わせ完了画面.
  123.      *
  124.      * @Route("/contact2/complete", name="contact2_complete", methods={"GET"})
  125.      * @Template("Contact/complete.twig")
  126.      */
  127.     public function complete()
  128.     {
  129.         return [];
  130.     }
  131. }