app/Customize/Controller/EntryContactController.php line 136

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\EntryContactStatus;
  14. use Customize\Form\Type\EntryContactType;
  15. use Customize\Repository\EntryContactStatusRepository;
  16. use Eccube\Controller\AbstractController;
  17. use Eccube\Entity\BaseInfo;
  18. use Eccube\Entity\Master\CustomerStatus;
  19. use Eccube\Event\EccubeEvents;
  20. use Eccube\Event\EventArgs;
  21. use Eccube\Form\Type\Front\EntryType;
  22. use Eccube\Repository\BaseInfoRepository;
  23. use Eccube\Repository\CustomerRepository;
  24. use Eccube\Repository\Master\CustomerStatusRepository;
  25. use Eccube\Repository\PageRepository;
  26. use Eccube\Service\CartService;
  27. use Customize\Service\MailService;
  28. use Exception;
  29. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  30. use Symfony\Component\HttpFoundation\Request;
  31. use Symfony\Component\HttpKernel\Exception as HttpException;
  32. use Symfony\Component\Routing\Annotation\Route;
  33. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  34. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  35. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  36. use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
  37. use Symfony\Component\Validator\Constraints as Assert;
  38. use Symfony\Component\Validator\Validator\ValidatorInterface;
  39. class EntryContactController extends AbstractController
  40. {
  41.     /**
  42.      * @var CustomerStatusRepository
  43.      */
  44.     protected $customerStatusRepository;
  45.     /**
  46.      * @var ValidatorInterface
  47.      */
  48.     protected $recursiveValidator;
  49.     /**
  50.      * @var MailService
  51.      */
  52.     protected $mailService;
  53.     /**
  54.      * @var BaseInfo
  55.      */
  56.     protected $BaseInfo;
  57.     /**
  58.      * @var CustomerRepository
  59.      */
  60.     protected $customerRepository;
  61.     /**
  62.      * @var EncoderFactoryInterface
  63.      */
  64.     protected $encoderFactory;
  65.     /**
  66.      * @var TokenStorageInterface
  67.      */
  68.     protected $tokenStorage;
  69.     /**
  70.      * @var \Eccube\Service\CartService
  71.      */
  72.     protected $cartService;
  73.     /**
  74.      * @var PageRepository
  75.      */
  76.     protected $pageRepository;
  77.     protected EntryContactStatusRepository $entryContactStatusRepository;
  78.     /**
  79.      * EntryController constructor.
  80.      *
  81.      * @param CartService $cartService
  82.      * @param CustomerStatusRepository $customerStatusRepository
  83.      * @param MailService $mailService
  84.      * @param BaseInfoRepository $baseInfoRepository
  85.      * @param CustomerRepository $customerRepository
  86.      * @param EncoderFactoryInterface $encoderFactory
  87.      * @param ValidatorInterface $validatorInterface
  88.      * @param TokenStorageInterface $tokenStorage
  89.      * @param EntryContactStatusRepository $entryContactStatusRepository
  90.      */
  91.     public function __construct(
  92.         CartService $cartService,
  93.         CustomerStatusRepository $customerStatusRepository,
  94.         MailService $mailService,
  95.         BaseInfoRepository $baseInfoRepository,
  96.         CustomerRepository $customerRepository,
  97.         EncoderFactoryInterface $encoderFactory,
  98.         ValidatorInterface $validatorInterface,
  99.         TokenStorageInterface $tokenStorage,
  100.         PageRepository $pageRepository,
  101.         EntryContactStatusRepository $entryContactStatusRepository
  102.     ) {
  103.         $this->customerStatusRepository $customerStatusRepository;
  104.         $this->mailService $mailService;
  105.         $this->BaseInfo $baseInfoRepository->get();
  106.         $this->customerRepository $customerRepository;
  107.         $this->encoderFactory $encoderFactory;
  108.         $this->recursiveValidator $validatorInterface;
  109.         $this->tokenStorage $tokenStorage;
  110.         $this->cartService $cartService;
  111.         $this->pageRepository $pageRepository;
  112.         $this->entryContactStatusRepository $entryContactStatusRepository;
  113.     }
  114.     /**
  115.      * 会員登録画面.
  116.      *
  117.      * @Route("/entrycontact", name="entry_contact", methods={"GET", "POST"})
  118.      * @Route("/entrycontact", name="entry_contact_confirm", methods={"GET", "POST"})
  119.      * @Template("Entry/contact.twig")
  120.      */
  121.     public function index(Request $request)
  122.     {
  123.         if ($this->isGranted('ROLE_USER')) {
  124.             log_info('認証済のためログイン処理をスキップ');
  125.             return $this->redirectToRoute('mypage');
  126.         }
  127.         /** @var $Customer \Eccube\Entity\Customer */
  128.         $Customer $this->customerRepository->newCustomer();
  129.         /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  130.         $builder $this->formFactory->createBuilder(EntryContactType::class);
  131.         $event = new EventArgs(
  132.             [
  133.                 'builder' => $builder,
  134.                 'Customer' => $Customer,
  135.             ],
  136.             $request
  137.         );
  138.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_ENTRY_INDEX_INITIALIZE);
  139.         /* @var $form \Symfony\Component\Form\FormInterface */
  140.         $form $builder->getForm();
  141.         $form->handleRequest($request);
  142.         if ($form->isSubmitted() && $form->isValid()) {
  143.             switch ($request->get('mode')) {
  144.                 case 'confirm':
  145.                     log_info('会員登録確認開始');
  146.                     log_info('会員登録確認完了');
  147.                     return $this->render(
  148.                         'Entry/contact_confirm.twig',
  149.                         [
  150.                             'form' => $form->createView(),
  151.                             'Page' => $this->pageRepository->getPageByRoute('entry_contact_confirm'),
  152.                         ]
  153.                     );
  154.                 case 'complete':
  155.                     log_info("Entry contact complete START");
  156.                     /** @var \Customize\Entity\EntryContact $EntryContact */
  157.                     $EntryContact $form->getData();
  158.                     $EntryContactStatus $this->entryContactStatusRepository->find(EntryContactStatus::NO_SUPPORTED);
  159.                     if (!$EntryContactStatus) {
  160.                         throw new Exception("「エントリの連絡先ステータス」を null にすることはできません");
  161.                     }
  162.                     $EntryContact->setContactDate(new \DateTime());
  163.                     $EntryContact->setStatus($EntryContactStatus);
  164.                     $this->entityManager->persist($EntryContact);
  165.                     $this->entityManager->flush();
  166.                     $this->mailService->sendEntryContactMail($EntryContact);
  167.                     log_info("Entry contact complete END", [$EntryContact->getId()]);
  168.                     return $this->redirectToRoute('entry_contact_complete');
  169.             }
  170.         }
  171.         return [
  172.             'form' => $form->createView(),
  173.         ];
  174.     }
  175.     /**
  176.      * 会員登録完了画面.
  177.      *
  178.      * @Route("/entrycontact/complete", name="entry_contact_complete", methods={"GET"})
  179.      * @Template("Entry/contact_complete.twig")
  180.      */
  181.     public function complete()
  182.     {
  183.         return [];
  184.     }
  185. }