<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Customize\Controller;
use Customize\Entity\Inquiry;
use Customize\Form\Type\InquiryType;
use Eccube\Controller\AbstractController;
use Eccube\Entity\Customer;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Form\Type\Front\ContactType;
use Eccube\Repository\PageRepository;
use Customize\Service\MailService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class InquiryController extends AbstractController
{
/**
* @var MailService
*/
protected $mailService;
/**
* @var PageRepository
*/
private $pageRepository;
/**
* ContactController constructor.
*
* @param MailService $mailService
* @param PageRepository $pageRepository
*/
public function __construct(
MailService $mailService,
PageRepository $pageRepository)
{
$this->mailService = $mailService;
$this->pageRepository = $pageRepository;
}
/**
* お問い合わせ画面.
*
* @Route("/inquiry", name="inquiry", methods={"GET", "POST"})
* @Route("/inquiry", name="inquiry_confirm", methods={"GET", "POST"})
* @Template("Inquiry/index.twig")
*/
public function index(Request $request)
{
$Inquiry = new Inquiry();
$builder = $this->formFactory->createBuilder(InquiryType::class, $Inquiry);
if ($this->isGranted('ROLE_USER')) {
/** @var Customer $user */
$user = $this->getUser();
$builder->setData(
[
'name' => $user->__toString(),
'kana' => $user->getKana01() .' '.$user->getKana02(),
'email' => $user->getEmail(),
]
);
}
// FRONT_CONTACT_INDEX_INITIALIZE
$form = $builder->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
switch ($request->get('mode')) {
case 'confirm':
return $this->render('Inquiry/confirm.twig', [
'form' => $form->createView(),
]);
case 'complete':
$Inquiry = $form->getData();
$this->entityManager->persist($Inquiry);
$this->entityManager->flush();
// $event = new EventArgs(
// [
// 'form' => $form,
// 'data' => $data,
// ],
// $request
// );
// $this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_CONTACT_INDEX_COMPLETE);
// $data = $event->getArgument('data');
// // メール送信
$this->mailService->sendInquiryMail($Inquiry);
return $this->redirect($this->generateUrl('inquiry_complete'));
}
}
return [
'form' => $form->createView(),
];
}
/**
* お問い合わせ完了画面.
*
* @Route("/inquiry/complete", name="inquiry_complete", methods={"GET"})
* @Template("Inquiry/complete.twig")
*/
public function complete()
{
return [];
}
}