app/Plugin/ProductReview42/Controller/ProductReviewController.php line 74

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 Plugin\ProductReview42\Controller;
  13. use Eccube\Controller\AbstractController;
  14. use Eccube\Entity\Master\ProductStatus;
  15. use Eccube\Entity\Product;
  16. use Plugin\ProductReview42\Entity\ProductReview;
  17. use Plugin\ProductReview42\Entity\ProductReviewStatus;
  18. use Plugin\ProductReview42\Form\Type\ProductReviewType;
  19. use Plugin\ProductReview42\Repository\ProductReviewRepository;
  20. use Plugin\ProductReview42\Repository\ProductReviewStatusRepository;
  21. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  22. use Symfony\Component\HttpFoundation\RedirectResponse;
  23. use Symfony\Component\HttpFoundation\Request;
  24. use Symfony\Component\HttpFoundation\Response;
  25. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  26. use Symfony\Component\Routing\Annotation\Route;
  27. /**
  28.  * Class ProductReviewController front.
  29.  */
  30. class ProductReviewController extends AbstractController
  31. {
  32.     /**
  33.      * @var ProductReviewStatusRepository
  34.      */
  35.     private $productReviewStatusRepository;
  36.     /**
  37.      * @var ProductReviewRepository
  38.      */
  39.     private $productReviewRepository;
  40.     /**
  41.      * ProductReviewController constructor.
  42.      *
  43.      * @param ProductReviewStatusRepository $productStatusRepository
  44.      * @param ProductReviewRepository $productReviewRepository
  45.      */
  46.     public function __construct(
  47.         ProductReviewStatusRepository $productStatusRepository,
  48.         ProductReviewRepository $productReviewRepository
  49.     ) {
  50.         $this->productReviewStatusRepository $productStatusRepository;
  51.         $this->productReviewRepository $productReviewRepository;
  52.     }
  53.     /**
  54.      * @Route("/product_review/{id}/review", name="product_review_index", requirements={"id" = "\d+"})
  55.      * @Route("/product_review/{id}/review", name="product_review_confirm", requirements={"id" = "\d+"})
  56.      *
  57.      * @param Request $request
  58.      * @param Product $Product
  59.      *
  60.      * @return RedirectResponse|Response
  61.      */
  62.     public function index(Request $requestProduct $Product)
  63.     {
  64.         if (!$this->session->has('_security_admin') && $Product->getStatus()->getId() !== ProductStatus::DISPLAY_SHOW) {
  65.             log_info('Product review', ['status' => 'Not permission']);
  66.             throw new NotFoundHttpException();
  67.         }
  68.         $ProductReview = new ProductReview();
  69.         $form $this->createForm(ProductReviewType::class, $ProductReview);
  70.         $form->handleRequest($request);
  71.         if ($form->isSubmitted() && $form->isValid()) {
  72.             /** @var $ProductReview ProductReview */
  73.             $ProductReview $form->getData();
  74.             switch ($request->get('mode')) {
  75.                 case 'confirm':
  76.                     log_info('Product review config confirm');
  77.                     return $this->render('ProductReview42/Resource/template/default/confirm.twig', [
  78.                         'form' => $form->createView(),
  79.                         'Product' => $Product,
  80.                         'ProductReview' => $ProductReview,
  81.                     ]);
  82.                     break;
  83.                 case 'complete':
  84.                     log_info('Product review complete');
  85.                     if ($this->isGranted('ROLE_USER')) {
  86.                         $Customer $this->getUser();
  87.                         $ProductReview->setCustomer($Customer);
  88.                     }
  89.                     $ProductReview->setProduct($Product);
  90.                     $ProductReview->setStatus($this->productReviewStatusRepository->find(ProductReviewStatus::HIDE));
  91.                     $this->entityManager->persist($ProductReview);
  92.                     $this->entityManager->flush($ProductReview);
  93.                     log_info('Product review complete', ['id' => $Product->getId()]);
  94.                     return $this->redirectToRoute('product_review_complete', ['id' => $Product->getId()]);
  95.                     break;
  96.                 case 'back':
  97.                     // 確認画面から投稿画面へ戻る
  98.                     break;
  99.                 default:
  100.                     // do nothing
  101.                     break;
  102.             }
  103.         }
  104.         return $this->render('ProductReview42/Resource/template/default/index.twig', [
  105.             'Product' => $Product,
  106.             'ProductReview' => $ProductReview,
  107.             'form' => $form->createView(),
  108.         ]);
  109.     }
  110.     /**
  111.      * Complete.
  112.      *
  113.      * @Route("/product_review/{id}/complete", name="product_review_complete", requirements={"id" = "\d+"})
  114.      * @Template("ProductReview42/Resource/template/default/complete.twig")
  115.      *
  116.      * @param $id
  117.      *
  118.      * @return array
  119.      */
  120.     public function complete($id)
  121.     {
  122.         return ['id' => $id];
  123.     }
  124.     /**
  125.      * ページ管理表示用のダミールーティング.
  126.      *
  127.      * @Route("/product_review/display", name="product_review_display")
  128.      */
  129.     public function display()
  130.     {
  131.         return new Response();
  132.     }
  133. }