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