app/Plugin/ProductReview42/ProductReviewEvent.php line 71

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;
  13. use Eccube\Entity\Product;
  14. use Eccube\Event\TemplateEvent;
  15. use Eccube\Repository\Master\ProductStatusRepository;
  16. use Plugin\ProductReview42\Entity\ProductReviewStatus;
  17. use Plugin\ProductReview42\Repository\ProductReviewConfigRepository;
  18. use Plugin\ProductReview42\Repository\ProductReviewRepository;
  19. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  20. class ProductReviewEvent implements EventSubscriberInterface
  21. {
  22.     /**
  23.      * @var ProductReviewConfigRepository
  24.      */
  25.     protected $productReviewConfigRepository;
  26.     
  27.     /**
  28.      * @var ProductStatusRepository
  29.      */
  30.     protected $productStatusRepository;
  31.     /**
  32.      * @var ProductReviewRepository
  33.      */
  34.     protected $productReviewRepository;
  35.     /**
  36.      * ProductReview constructor.
  37.      *
  38.      * @param ProductReviewConfigRepository $productReviewConfigRepository
  39.      * @param ProductStatusRepository $productStatusRepository
  40.      * @param ProductReviewRepository $productReviewRepository
  41.      */
  42.     public function __construct(
  43.         ProductReviewConfigRepository $productReviewConfigRepository,
  44.         ProductStatusRepository $productStatusRepository,
  45.         ProductReviewRepository $productReviewRepository
  46.     ) {
  47.         $this->productReviewConfigRepository $productReviewConfigRepository;
  48.         $this->productStatusRepository $productStatusRepository;
  49.         $this->productReviewRepository $productReviewRepository;
  50.     }
  51.     /**
  52.      * @return array
  53.      */
  54.     public static function getSubscribedEvents()
  55.     {
  56.         return [
  57.             'Product/detail.twig' => 'detail',
  58.         ];
  59.     }
  60.     /**
  61.      * @param TemplateEvent $event
  62.      */
  63.     public function detail(TemplateEvent $event)
  64.     {
  65.         $event->addSnippet('ProductReview42/Resource/template/default/review.twig');
  66.         $Config $this->productReviewConfigRepository->get();
  67.         /** @var Product $Product */
  68.         $Product $event->getParameter('Product');
  69.         $ProductReviews $this->productReviewRepository->findBy(['Status' => ProductReviewStatus::SHOW'Product' => $Product], ['id' => 'DESC'], $Config->getReviewMax());
  70.         $rate $this->productReviewRepository->getAvgAll($Product);
  71.         $avg round($rate['recommend_avg']);
  72.         $count intval($rate['review_count']);
  73.         $parameters $event->getParameters();
  74.         $parameters['ProductReviews'] = $ProductReviews;
  75.         $parameters['ProductReviewAvg'] = $avg;
  76.         $parameters['ProductReviewCount'] = $count;
  77.         $event->setParameters($parameters);
  78.     }
  79. }