app/Customize/Controller/VideoController.php line 199

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Customize of EC-CUBE by Kenji Nakanishi
  4.  *
  5.  * Copyright(c) 2021 Kenji Nakanishi. All Rights Reserved.
  6.  *
  7.  * https://www.facebook.com/web.kenji.nakanishi
  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 Doctrine\ORM\EntityManagerInterface;
  14. use Doctrine\ORM\Query\Expr;
  15. use Doctrine\ORM\QueryBuilder;
  16. use Eccube\Controller\AbstractController;
  17. use Eccube\Entity\Category;
  18. use Eccube\Entity\Customer;
  19. use Eccube\Entity\Master\OrderItemType;
  20. use Eccube\Entity\Master\OrderStatus;
  21. use Eccube\Entity\Master\ProductStatus;
  22. use Eccube\Entity\Master\SaleType;
  23. use Eccube\Entity\Order;
  24. use Eccube\Entity\OrderItem;
  25. use Eccube\Entity\Product;
  26. use Eccube\Entity\ProductClass;
  27. use Eccube\Entity\ProductCategory;
  28. use Eccube\Repository\OrderItemRepository;
  29. use Eccube\Repository\OrderRepository;
  30. use Plugin\SheebDlc4\Entity\Config;
  31. use Plugin\SheebDlc4\Entity\DownloadContent;
  32. use Plugin\SheebDlc4\PluginManager;
  33. use Plugin\SheebDlc4\Service\SaveFile\AbstractSaveFile;
  34. use Plugin\SheebDlc4\Service\SaveFile\Modules\Local;
  35. use Plugin\SheebDlc4\Service\SaveFile\SaveFileModuleFactory;
  36. use Plugin\SheebDlc4\Service\SheebUtils;
  37. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  38. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  39. use Symfony\Component\Asset\Packages;
  40. use Symfony\Component\HttpFoundation\Request;
  41. use Symfony\Component\HttpFoundation\Response;
  42. use Eccube\Common\EccubeConfig;
  43. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  44. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  45. use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
  46. use Symfony\Component\Routing\Annotation\Route;
  47. use Knp\Component\Pager\PaginatorInterface;
  48. use Eccube\Form\Type\SearchProductType;
  49. use Eccube\Form\Type\Master\ProductListMaxType;
  50. use Eccube\Form\Type\Master\ProductListOrderByType;
  51. class VideoController extends AbstractController
  52. {
  53.     /**
  54.      * @var EntityManagerInterface
  55.      */
  56.     private $em;
  57.     /**
  58.      * @var \Symfony\Component\Asset\Packages
  59.      */
  60.     private $assets;
  61.     /**
  62.      * @var EccubeConfig
  63.      */
  64.     protected $eccubeConfig;
  65.     public function __construct(EntityManagerInterface $emPackages $assetEccubeConfig $eccubeConfig)
  66.     {
  67.         $this->em $em;
  68.         $this->assets $asset;
  69.         $this->eccubeConfig $eccubeConfig;
  70.     }
  71.     /**
  72.      * カテゴリ一覧ページ
  73.      *
  74.      * @Route("/category_list", name="category_list", methods={"GET"})
  75.      * @Template("category_list.twig")
  76.      *
  77.      * @return array
  78.      *
  79.      * @throws \Exception
  80.      */
  81.     public function categories(Request $request)
  82.     {
  83.     }
  84.     /**
  85.      * カテゴリ詳細ページ
  86.      *
  87.      * @Route("/categories/{category_id}", name="categories/{category_id}", methods={"GET"})
  88.      * @ParamConverter("Category", options={ "id" = "category_id"})
  89.      * @Template("category_detail.twig")
  90.      *
  91.      * @return array
  92.      *
  93.      * @throws \Exception
  94.      */
  95.     public function category_detail(Request $requestCategory $CategoryPaginatorInterface $paginator)
  96.     {
  97.         /*
  98.          * リクエストパラメータ
  99.          */
  100.         $paramShowUnavailable boolval($request->get('show-unavailable'false));
  101.         $paramOrderBy $request->get('order-by''datetime');
  102.         $pageno $request->get('pageno'1);
  103.         // handleRequestは空のqueryの場合は無視するため
  104.         if ($request->getMethod() === 'GET') {
  105.             $request->query->set('pageno'$request->query->get('pageno'''));
  106.         }
  107.         // searchForm
  108.         /** @var \Symfony\Component\Form\FormBuilderInterface $builder */
  109.         $builder $this->formFactory->createNamedBuilder(''SearchProductType::class);
  110.         if ($request->getMethod() === 'GET') {
  111.             $builder->setMethod('GET');
  112.         }
  113.         /** @var $searchForm \Symfony\Component\Form\FormInterface */
  114.         $searchForm $builder->getForm();
  115.         $searchForm->handleRequest($request);
  116.         // 表示件数
  117.         $builder $this->formFactory->createNamedBuilder(
  118.             'disp_number',
  119.             ProductListMaxType::class,
  120.             null,
  121.             [
  122.                 'required' => false,
  123.                 'allow_extra_fields' => true,
  124.             ]
  125.         );
  126.         if ($request->getMethod() === 'GET') {
  127.             $builder->setMethod('GET');
  128.         }
  129.         $dispNumberForm $builder->getForm();
  130.         $dispNumberForm->handleRequest($request);
  131.         // ソート順
  132.         $builder $this->formFactory->createNamedBuilder(
  133.             'orderby',
  134.             ProductListOrderByType::class,
  135.             null,
  136.             [
  137.                 'required' => false,
  138.                 'allow_extra_fields' => true,
  139.             ]
  140.         );
  141.         if ($request->getMethod() === 'GET') {
  142.             $builder->setMethod('GET');
  143.         }
  144.         $orderByForm $builder->getForm();
  145.         $orderByForm->handleRequest($request);
  146.         $dlcSaleType PluginManager::getDlcSaleType($this->em);
  147.         $qb = (function ($dlcSaleType$param_category_id): QueryBuilder {
  148.             return $this->em->createQueryBuilder()
  149.                 ->select('prd')
  150.                 ->from(Product::class, 'prd')
  151.                 ->where('prd.Status = :ProductStatus')
  152.                 ->setParameter('ProductStatus'1// 公開: 1
  153.                 ->join(ProductClass::class, 'prdcls''WITH''prd.id = prdcls.Product AND prdcls.SaleType = :SaleType')
  154.                 ->setParameter('SaleType'$dlcSaleType)
  155.                 ->join(ProductCategory::class, 'prdcat''WITH''prd.id = prdcat.Product AND prdcat.category_id = :CategoryId')
  156.                 ->setParameter('CategoryId'$param_category_id);
  157.                 // ->orderBy('prd.id', 'DESC');
  158.                 // ->orderBy('prd.plg_sort_no', 'ASC');
  159.         })($dlcSaleType$Category->getId());
  160.         $searchData $searchForm->getData();
  161.         // 新着順, それ以外は並び順
  162.         if (!empty($searchData['orderby']) && $searchData['orderby']->getId() == $this->eccubeConfig['eccube_product_order_newer']) {
  163.             $qb->orderBy('prd.create_date''DESC');
  164.             $qb->addOrderBy('prd.id''DESC');
  165.         } else {
  166.             $qb->orderBy('prd.plg_sort_no''ASC');
  167.         }
  168.         $listItems = [];
  169.         foreach ($qb->getQuery()->getResult() as $Product) {
  170.             $listItems[] = $Product;
  171.         }
  172.         /** @var SlidingPagination $pagination */
  173.         $pagination $paginator->paginate(
  174.             $qb->getQuery(),
  175.             // !empty($searchData['pageno']) ? $searchData['pageno'] : 1,
  176.             $pageno,
  177.             // !empty($searchData['disp_number']) ? $searchData['disp_number']->getId() : $this->productListMaxRepository->findOneBy([], ['sort_no' => 'ASC'])->getId()
  178.             !empty($searchData['disp_number']) ? $searchData['disp_number']->getId() : 6
  179.         );
  180.         return [
  181.             'listItems' => $listItems,
  182.             'pagination' => $pagination,
  183.             'category' => $Category,
  184.             'customer' => $this->getUser(),
  185.             'filters' => [
  186.                 'show-unavailable' => $paramShowUnavailable,
  187.                 'order-by' => $paramOrderBy,
  188.             ],
  189.             'search_form' => $searchForm->createView(),
  190.             'disp_number_form' => $dispNumberForm->createView(),
  191.             'order_by_form' => $orderByForm->createView(),
  192.         ];
  193.     }
  194.     /**
  195.      * 動画詳細
  196.      *
  197.      * @Route("/video/{product_id}/content/{content_id}", name="video/{product_id}/content/{content_id}", methods={"GET"})
  198.      * @ParamConverter("Product", options={ "id" = "product_id" })
  199.      * @ParamConverter("DownloadContent", options={ "id" = "content_id" })
  200.      * @Template("Video/show_contents.twig")
  201.      */
  202.     public function showContent(Request $requestProduct $ProductDownloadContent $DownloadContent)
  203.     {
  204.         // --- Check: ログインしているかどうか ---
  205.         $Customer $this->getUser();
  206.         if (empty($Customer)) {
  207.             return $this->redirectToRoute('mypage_login');
  208.         }
  209.         if ($Product->getStatus()->getId() != ProductStatus::DISPLAY_SHOW) {
  210.             throw new NotFoundHttpException();
  211.         }
  212.         return [
  213.             'Product' => $Product,
  214.             'DownloadContent' => $DownloadContent,
  215.             'title' => $DownloadContent->getSheebDlc4DisplayName(),
  216.             'customer' => $this->getUser(),
  217.             'status' => $Product->getStatus(),
  218.         ];
  219.     }
  220. }