app/Customize/Controller/Review/CustomizeReviewController.php line 135

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\Review;
  13. use Eccube\Controller\AbstractController;
  14. use Eccube\Controller\Mypage\MypageController;
  15. use Eccube\Entity\BaseInfo;
  16. use Eccube\Entity\Customer;
  17. use Eccube\Entity\Product;
  18. use Eccube\Entity\Order;
  19. use Eccube\Event\EccubeEvents;
  20. use Eccube\Event\EventArgs;
  21. use Eccube\Exception\CartException;
  22. use Eccube\Form\Type\Front\CustomerLoginType;
  23. use Eccube\Repository\BaseInfoRepository;
  24. use Eccube\Repository\CustomerFavoriteProductRepository;
  25. use Eccube\Repository\OrderRepository;
  26. use Eccube\Repository\ProductRepository;
  27. use Eccube\Service\CartService;
  28. use Eccube\Service\PurchaseFlow\PurchaseContext;
  29. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  30. use Knp\Component\Pager\Paginator;
  31. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  32. use Symfony\Component\HttpFoundation\Request;
  33. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  34. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  35. use Symfony\Component\Routing\Annotation\Route;
  36. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  37. use Doctrine\ORM\Query\ResultSetMapping;
  38. use Eccube\Entity\Master\ProductStatus;
  39. use Eccube\Form\Type\AddCartType;
  40. use Eccube\Form\Type\Master\ProductListMaxType;
  41. use Eccube\Form\Type\Master\ProductListOrderByType;
  42. use Eccube\Form\Type\SearchProductType;
  43. use Eccube\Repository\Master\ProductListMaxRepository;
  44. use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
  45. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  46. use Plugin\ProductReview4\Repository\ProductReviewRepository;
  47. class CustomizeReviewController extends AbstractController
  48. {
  49.     /**
  50.      * @var PurchaseFlow
  51.      */
  52.     protected $purchaseFlow;
  53.     /**
  54.      * @var CustomerFavoriteProductRepository
  55.      */
  56.     protected $customerFavoriteProductRepository;
  57.     /**
  58.      * @var CartService
  59.      */
  60.     protected $cartService;
  61.     /**
  62.      * @var ProductRepository
  63.      */
  64.     protected $productRepository;
  65.     /**
  66.      * @var BaseInfo
  67.      */
  68.     protected $BaseInfo;
  69.     /**
  70.      * @var AuthenticationUtils
  71.      */
  72.     protected $helper;
  73.     /**
  74.      * @var ProductListMaxRepository
  75.      */
  76.     protected $productListMaxRepository;
  77.     private $title '';
  78.     /**
  79.      * @var ProductReviewRepository
  80.      */
  81.     protected $productReviewRepository;
  82.     /**
  83.      * ProductController constructor.
  84.      *
  85.      * @param PurchaseFlow $cartPurchaseFlow
  86.      * @param CustomerFavoriteProductRepository $customerFavoriteProductRepository
  87.      * @param CartService $cartService
  88.      * @param ProductRepository $productRepository
  89.      * @param BaseInfoRepository $baseInfoRepository
  90.      * @param AuthenticationUtils $helper
  91.      * @param ProductListMaxRepository $productListMaxRepository
  92.      * @param ProductReviewRepository $productReviewRepository
  93.      */
  94.     public function __construct(
  95.         PurchaseFlow $cartPurchaseFlow,
  96.         CustomerFavoriteProductRepository $customerFavoriteProductRepository,
  97.         CartService $cartService,
  98.         ProductRepository $productRepository,
  99.         BaseInfoRepository $baseInfoRepository,
  100.         AuthenticationUtils $helper,
  101.         ProductListMaxRepository $productListMaxRepository,
  102.         ProductReviewRepository $productReviewRepository
  103.     ) {
  104.         $this->purchaseFlow $cartPurchaseFlow;
  105.         $this->customerFavoriteProductRepository $customerFavoriteProductRepository;
  106.         $this->cartService $cartService;
  107.         $this->productRepository $productRepository;
  108.         $this->BaseInfo $baseInfoRepository->get();
  109.         $this->helper $helper;
  110.         $this->productListMaxRepository $productListMaxRepository;
  111.         $this->productReviewRepository $productReviewRepository;
  112.     }
  113.     /**
  114.      * レビュー図一覧
  115.      *
  116.      * @Route("/review_list", name="review_list")
  117.      * @Template("Review/index.twig")
  118.      */
  119.     public function index(Request $requestPaginator $paginator)
  120.     {
  121.         // Page指定
  122.         $currentPage 1;
  123.         if (isset($_GET['pageno'])) {
  124.             $currentPage $_GET['pageno'];
  125.         }
  126.         $limitPerPage 10;
  127.         $offset = ($currentPage 1) * $limitPerPage;
  128.         
  129.         $options = [];
  130.         
  131.         $qb $this->entityManager->createQueryBuilder();
  132.         $qb->select('a')->from('Plugin\ProductReview4\Entity\ProductReview','a');
  133.         $orderby_name "新着順";
  134.         $orderby  1;
  135.         if(isset($_GET["orderby"])){
  136.             $orderby $_GET["orderby"];
  137.             if($orderby == 1){
  138.                 $qb->orderBy('a.id','desc');
  139.                 $orderby_name "新着順";
  140.             }elseif($orderby == 2){
  141.                 $qb->orderBy('a.recommend_level','desc');
  142.                 $qb->addorderBy('a.id','desc');
  143.                 $orderby_name "評価の高い順";
  144.             }elseif($orderby == 3){
  145.                 $qb->orderBy('a.recommend_level','asc');
  146.                 $qb->addorderBy('a.id','desc');                
  147.                 $orderby_name "評価の低い順";
  148.             }elseif($orderby == 4){
  149.                 $qb->orderBy('a.ref_count','desc');
  150.                 $qb->addorderBy('a.id','desc');                
  151.                 $orderby_name "参考になったの多い順";
  152.             }
  153.         }else{
  154.             $qb->orderBy('a.id','desc');
  155.         }
  156.         $qb->where('a.Status = 1');
  157.         $where false;
  158.         $category_name "絞り込み";
  159.         $category_id "";
  160.         if(isset($_GET["category_id"]) && $_GET["category_id"]){
  161.             $category_id $_GET["category_id"];
  162.             $qb->join('Eccube\Entity\Product''p', \Doctrine\ORM\Query\Expr\Join::WITH'a.Product = p.id');
  163.             $qb->join('Eccube\Entity\ProductCategory''pc', \Doctrine\ORM\Query\Expr\Join::WITH'pc.product_id = p.id');
  164.             //$qb->join('Eccube\Entity\Category', 'c', \Doctrine\ORM\Query\Expr\Join::WITH, 'pc.category_id = c.id');
  165.             $qb->andWhere('pc.category_id = :category_id')->setParameter('category_id',$category_id);
  166.             $cate $this->entityManager->getRepository('Eccube\Entity\Category')->findOneBy(['id'=>$category_id]);
  167.             $category_name $cate->getName();
  168.             $where true;
  169.         }
  170.         $categories $this->entityManager->getRepository('Eccube\Entity\Category')->findBy(["id"=>[7,18,8,12,17,11,9,19,20,21,10,22]]);
  171.         $category_map = [];
  172.         foreach($categories as $cate){
  173.             $category_map[] = $cate->getId();
  174.         }
  175.         $keyword "";
  176.         if(isset($_GET["keyword"]) && $_GET["keyword"]){
  177.             $keyword $_GET["keyword"];
  178.             if($where){
  179.                 $qb->andwhere('(a.title like :keyword or a.comment like :keyword or p.name like :keyword)')->setParameter('keyword' '%'.$keyword.'%');
  180.             }else{
  181.                 $qb->join('Eccube\Entity\Product''p', \Doctrine\ORM\Query\Expr\Join::WITH'a.Product = p.id');
  182.                 $qb->andWhere('(a.title like :keyword or a.comment like :keyword or p.name like :keyword)')->setParameter('keyword' '%'.$keyword.'%');
  183.             }
  184.         }
  185.         
  186.         //echo $qb->getDql();
  187.         //exit;
  188.         $data $qb->getQuery();//->select('a')
  189.                 //->select('p.name')
  190.                 //->from('Plugin\ProductReview4\Entity\ProductReview','a')
  191.                 //->join(sprintf('(%s)', $sub_qb->getDql()), 'b',\Doctrine\ORM\Query\Expr\Join::WITH, 'b.product_id = a.product_id')
  192.                 //->join('Eccube\Entity\Product', 'p', \Doctrine\ORM\Query\Expr\Join::WITH, 'a.product_id = p.id')
  193.                 //->getQuery();
  194.                 //;
  195.         $pagination $paginator->paginate($data$currentPage$limitPerPage$options);
  196.         //var_dump($pagination);
  197.         //$ids = [];
  198.         //$ProductList = array();
  199.         
  200.         
  201.         $ReviewAveList = array();
  202.         $ReviewCntList = array();
  203.         foreach ($pagination as $Review) {
  204.         //    foreach($Reviews as $Review){
  205.                 $Product $Review->getProduct();//getProduct();
  206.                 $ids[] = $Product->getId();
  207.                 $rate $this->entityManager->getRepository('Plugin\ProductReview4\Entity\ProductReview')->getAvgAll($Product);
  208.                 $ReviewAveList[$Product->getId()] = round($rate['recommend_avg']);
  209.                 $ReviewCntList[$Product->getId()] = intval($rate['review_count']);
  210.         //    }
  211.         }
  212.         $user_id "";
  213.         $Customer $this->getUser();
  214.         if($Customer){
  215.             $user_id $Customer->getId();
  216.         }
  217.         return [
  218.         //    'subtitle' => $this->getPageTitle($searchData),
  219.             'pagination' => $pagination,
  220.         //    'search_form' => $searchForm->createView(),
  221.         //    'disp_number_form' => $dispNumberForm->createView(),
  222.         //    'order_by_form' => $orderByForm->createView(),
  223.         //    'forms' => $forms,
  224.         //    'Category' => $Category,
  225.             'categories' => $categories,
  226.             'ReviewAveList' => $ReviewAveList,
  227.             'ReviewCntList' => $ReviewCntList,
  228.             'orderby_name' => $orderby_name,
  229.             "keyword" => $keyword,
  230.             "category_id"=>$category_id,
  231.             "category_name"=>$category_name,
  232.             "orderby"=>$orderby,
  233.             "category_map"=>$category_map,
  234.             "user_id" => $user_id,
  235.         //    "ProductReviews" => $ProductReviews,
  236.         ];
  237.     }
  238.     /**
  239.      *
  240.      * @Route("/mypage/myreview_list", name="mypage_myreview_list")
  241.      * @Template("Mypage/review-list.twig")
  242.      */
  243.     public function mypage_myreview_list(Request $requestPaginator $paginator)
  244.     {
  245.         $Customer $this->getUser();
  246.         if($Customer == null){
  247.         }
  248.         $review_id 0;
  249.         if(isset($_GET["id"])){
  250.             $review_id $_GET["id"];
  251.         }
  252.  // Page指定
  253.         $currentPage 1;
  254.         if (isset($_GET['pageno'])) {
  255.             $currentPage $_GET['pageno'];
  256.         }
  257.         $limitPerPage 10;
  258.         //$offset = ($currentPage - 1) * $limitPerPage;
  259.         
  260.         $options = [];
  261.         
  262.         //$qb = $this->entityManager->createQueryBuilder();
  263.         $qb $this->productReviewRepository->createQueryBuilder('r');
  264.         //$qb->select('a')->from('Plugin\ProductReview4\Entity\ProductReview','a');
  265.         $qb->orderBy('r.id','desc');
  266.         
  267.         $qb->where('r.Status = 1');
  268.         $qb->andWhere('r.Customer = :customer_id')
  269.             ->setParameter('customer_id'$Customer->getId())
  270.             ->andWhere('r.OrderItem > 0')
  271.             ;
  272.         if($review_id){
  273.             $qb->andWhere('r.id = :id')->setParameter('id'$review_id);
  274.         }
  275.         $data $qb->getQuery();//->select('a')
  276.         //var_dump($data->getSql());
  277.         //exit;
  278.                 //->select('p.name')
  279.                 //->from('Plugin\ProductReview4\Entity\ProductReview','a')
  280.                 //->join(sprintf('(%s)', $sub_qb->getDql()), 'b',\Doctrine\ORM\Query\Expr\Join::WITH, 'b.product_id = a.product_id')
  281.                 //->join('Eccube\Entity\Product', 'p', \Doctrine\ORM\Query\Expr\Join::WITH, 'a.product_id = p.id')
  282.                 //->getQuery();
  283.                 //;
  284.         $pagination $paginator->paginate($data$currentPage$limitPerPage$options);
  285.         //var_dump($pagination);
  286.         //$ids = [];
  287.         //$ProductList = array();
  288.         return [
  289.         //    'subtitle' => $this->getPageTitle($searchData),
  290.             'pagination' => $pagination,
  291.             'review_id' => $review_id,
  292.         //    'search_form' => $searchForm->createView(),
  293.         //    'disp_number_form' => $dispNumberForm->createView(),
  294.         //    'order_by_form' => $orderByForm->createView(),
  295.         //    'forms' => $forms,
  296.         //    'Category' => $Category,
  297.         //    'categories' => $categories,
  298.         //    'ReviewAveList' => $ReviewAveList,
  299.         //    'ReviewCntList' => $ReviewCntList,
  300.         //    'orderby_name' => $orderby_name,
  301.         //    "keyword" => $keyword,
  302.         //    "category_id"=>$category_id,
  303.         //    "category_name"=>$category_name,
  304.         //    "orderby"=>$orderby,
  305.         //    "category_map"=>$category_map,
  306.         //    "user_id" => $user_id,
  307.         //    "ProductReviews" => $ProductReviews,
  308.         ];        
  309.     }
  310.     /**
  311.      * レビュー
  312.      *
  313.      * @Route("/review_list/addref", name="review_list_addref")
  314.      */
  315.     public function addref(Request $request)
  316.     {
  317.     
  318.         $Customer $this->getUser();
  319.         if($Customer == null){
  320.             $msg = [];
  321.             $msg["err"] = 1;
  322.             $this->json($msg200);
  323.         }
  324.         $user_id $Customer->getId();
  325.         $rid $_GET["rid"];
  326.         $Review $this->entityManager->getRepository('Plugin\ProductReview4\Entity\ProductReview')->findOneBy(['id'=>$rid]);
  327.         $Review->setRefCount($Review->getRefCount() + 1);
  328.         $ref_users $Review->getRefUsers();
  329.         if(!in_array($user_id$ref_users)){
  330.             $ref_users[] = $user_id;
  331.             $Review->setRefUsers($ref_users);
  332.         }
  333.         $this->entityManager->persist($Review);
  334.         $this->entityManager->flush();
  335.         $msg = [];
  336.         $msg["err"] = 0;
  337.         $msg["success"] = 1;
  338.         $msg["user_id"] = $user_id;
  339.         $msg["rid"] = $rid;
  340.         $msg["ref_count"] = $Review->getRefCount();
  341.         return $this->json($msg200);
  342.     }
  343.     /**
  344.      *  Login
  345.      *
  346.      *  @Route("/mypage/review_list", name="mypage_review_list")
  347.      *  @throws \Exception
  348.      *
  349.      */
  350.     public function login(){
  351.         
  352.         $Customer $this->getUser();
  353.         if (empty($Customer)) {
  354.             throw new BadRequestHttpException();
  355.         }
  356.         return $this->redirectToRoute('review_list');
  357.     }
  358.     /**
  359.      *  Login
  360.      *
  361.      *  @Route("/mypage/product_review/{id}", name="mypage_product_review")
  362.      *  @param Request $request
  363.      *  @param Product $Product
  364.      *  @throws \Exception
  365.      *
  366.      */
  367.     public function product_login(Request $requestProduct $Product){
  368.         
  369.         $Customer $this->getUser();
  370.         if (empty($Customer)) {
  371.             throw new BadRequestHttpException();
  372.         }
  373.         return $this->redirectToRoute('product_review',$Product->getId());
  374.     }
  375. }