<?php
/*
* This file is part of Customize of EC-CUBE by Kenji Nakanishi
*
* Copyright(c) 2021 Kenji Nakanishi. All Rights Reserved.
*
* https://www.facebook.com/web.kenji.nakanishi
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Customize\Controller;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
use Eccube\Controller\AbstractController;
use Eccube\Entity\Category;
use Eccube\Entity\Customer;
use Eccube\Entity\Master\OrderItemType;
use Eccube\Entity\Master\OrderStatus;
use Eccube\Entity\Master\ProductStatus;
use Eccube\Entity\Master\SaleType;
use Eccube\Entity\Order;
use Eccube\Entity\OrderItem;
use Eccube\Entity\Product;
use Eccube\Entity\ProductClass;
use Eccube\Entity\ProductCategory;
use Eccube\Repository\OrderItemRepository;
use Eccube\Repository\OrderRepository;
use Plugin\SheebDlc4\Entity\Config;
use Plugin\SheebDlc4\Entity\DownloadContent;
use Plugin\SheebDlc4\PluginManager;
use Plugin\SheebDlc4\Service\SaveFile\AbstractSaveFile;
use Plugin\SheebDlc4\Service\SaveFile\Modules\Local;
use Plugin\SheebDlc4\Service\SaveFile\SaveFileModuleFactory;
use Plugin\SheebDlc4\Service\SheebUtils;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Asset\Packages;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Eccube\Common\EccubeConfig;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Knp\Component\Pager\PaginatorInterface;
use Eccube\Form\Type\SearchProductType;
use Eccube\Form\Type\Master\ProductListMaxType;
use Eccube\Form\Type\Master\ProductListOrderByType;
class VideoController extends AbstractController
{
/**
* @var EntityManagerInterface
*/
private $em;
/**
* @var \Symfony\Component\Asset\Packages
*/
private $assets;
/**
* @var EccubeConfig
*/
protected $eccubeConfig;
public function __construct(EntityManagerInterface $em, Packages $asset, EccubeConfig $eccubeConfig)
{
$this->em = $em;
$this->assets = $asset;
$this->eccubeConfig = $eccubeConfig;
}
/**
* カテゴリ一覧ページ
*
* @Route("/category_list", name="category_list", methods={"GET"})
* @Template("category_list.twig")
*
* @return array
*
* @throws \Exception
*/
public function categories(Request $request)
{
}
/**
* カテゴリ詳細ページ
*
* @Route("/categories/{category_id}", name="categories/{category_id}", methods={"GET"})
* @ParamConverter("Category", options={ "id" = "category_id"})
* @Template("category_detail.twig")
*
* @return array
*
* @throws \Exception
*/
public function category_detail(Request $request, Category $Category, PaginatorInterface $paginator)
{
/*
* リクエストパラメータ
*/
$paramShowUnavailable = boolval($request->get('show-unavailable', false));
$paramOrderBy = $request->get('order-by', 'datetime');
$pageno = $request->get('pageno', 1);
// handleRequestは空のqueryの場合は無視するため
if ($request->getMethod() === 'GET') {
$request->query->set('pageno', $request->query->get('pageno', ''));
}
// searchForm
/** @var \Symfony\Component\Form\FormBuilderInterface $builder */
$builder = $this->formFactory->createNamedBuilder('', SearchProductType::class);
if ($request->getMethod() === 'GET') {
$builder->setMethod('GET');
}
/** @var $searchForm \Symfony\Component\Form\FormInterface */
$searchForm = $builder->getForm();
$searchForm->handleRequest($request);
// 表示件数
$builder = $this->formFactory->createNamedBuilder(
'disp_number',
ProductListMaxType::class,
null,
[
'required' => false,
'allow_extra_fields' => true,
]
);
if ($request->getMethod() === 'GET') {
$builder->setMethod('GET');
}
$dispNumberForm = $builder->getForm();
$dispNumberForm->handleRequest($request);
// ソート順
$builder = $this->formFactory->createNamedBuilder(
'orderby',
ProductListOrderByType::class,
null,
[
'required' => false,
'allow_extra_fields' => true,
]
);
if ($request->getMethod() === 'GET') {
$builder->setMethod('GET');
}
$orderByForm = $builder->getForm();
$orderByForm->handleRequest($request);
$dlcSaleType = PluginManager::getDlcSaleType($this->em);
$qb = (function ($dlcSaleType, $param_category_id): QueryBuilder {
return $this->em->createQueryBuilder()
->select('prd')
->from(Product::class, 'prd')
->where('prd.Status = :ProductStatus')
->setParameter('ProductStatus', 1) // 公開: 1
->join(ProductClass::class, 'prdcls', 'WITH', 'prd.id = prdcls.Product AND prdcls.SaleType = :SaleType')
->setParameter('SaleType', $dlcSaleType)
->join(ProductCategory::class, 'prdcat', 'WITH', 'prd.id = prdcat.Product AND prdcat.category_id = :CategoryId')
->setParameter('CategoryId', $param_category_id);
// ->orderBy('prd.id', 'DESC');
// ->orderBy('prd.plg_sort_no', 'ASC');
})($dlcSaleType, $Category->getId());
$searchData = $searchForm->getData();
// 新着順, それ以外は並び順
if (!empty($searchData['orderby']) && $searchData['orderby']->getId() == $this->eccubeConfig['eccube_product_order_newer']) {
$qb->orderBy('prd.create_date', 'DESC');
$qb->addOrderBy('prd.id', 'DESC');
} else {
$qb->orderBy('prd.plg_sort_no', 'ASC');
}
$listItems = [];
foreach ($qb->getQuery()->getResult() as $Product) {
$listItems[] = $Product;
}
/** @var SlidingPagination $pagination */
$pagination = $paginator->paginate(
$qb->getQuery(),
// !empty($searchData['pageno']) ? $searchData['pageno'] : 1,
$pageno,
// !empty($searchData['disp_number']) ? $searchData['disp_number']->getId() : $this->productListMaxRepository->findOneBy([], ['sort_no' => 'ASC'])->getId()
!empty($searchData['disp_number']) ? $searchData['disp_number']->getId() : 6
);
return [
'listItems' => $listItems,
'pagination' => $pagination,
'category' => $Category,
'customer' => $this->getUser(),
'filters' => [
'show-unavailable' => $paramShowUnavailable,
'order-by' => $paramOrderBy,
],
'search_form' => $searchForm->createView(),
'disp_number_form' => $dispNumberForm->createView(),
'order_by_form' => $orderByForm->createView(),
];
}
/**
* 動画詳細
*
* @Route("/video/{product_id}/content/{content_id}", name="video/{product_id}/content/{content_id}", methods={"GET"})
* @ParamConverter("Product", options={ "id" = "product_id" })
* @ParamConverter("DownloadContent", options={ "id" = "content_id" })
* @Template("Video/show_contents.twig")
*/
public function showContent(Request $request, Product $Product, DownloadContent $DownloadContent)
{
// --- Check: ログインしているかどうか ---
$Customer = $this->getUser();
if (empty($Customer)) {
return $this->redirectToRoute('mypage_login');
}
if ($Product->getStatus()->getId() != ProductStatus::DISPLAY_SHOW) {
throw new NotFoundHttpException();
}
return [
'Product' => $Product,
'DownloadContent' => $DownloadContent,
'title' => $DownloadContent->getSheebDlc4DisplayName(),
'customer' => $this->getUser(),
'status' => $Product->getStatus(),
];
}
}