<?php
namespace Customize\Controller;
use Customize\Entity\ConstructionCase;
use Customize\Repository\ConstructionCaseRepository;
use Customize\Repository\ProductRepository;
use Eccube\Controller\AbstractController;
use Knp\Component\Pager\PaginatorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class WorkController extends AbstractController
{
/**
* @var ConstructionCaseRepository
*/
private $constructionCaseRepository;
/**
* @var ProductRepository
*/
private $productRepository;
/**
* WorkController constructor.
*/
public function __construct(
ConstructionCaseRepository $constructionCaseRepository,
ProductRepository $productRepository
)
{
$this->constructionCaseRepository = $constructionCaseRepository;
$this->productRepository = $productRepository;
}
/**
* 施工事例一覧画面
*
* @Route("/work", name="work", methods={"GET", "POST"})
* @Template("Work/index.twig")
*/
public function index(Request $request, PaginatorInterface $paginator)
{
$queryBuilder = $this->constructionCaseRepository->createQueryBuilder('c')
->orderBy('c.update_date', 'DESC');
$page = $request->query->getInt('pageno', 1);
$limit = 21; // 1ページあたりの表示件数
$pagination = $paginator->paginate(
$queryBuilder,
$page,
$limit
);
return [
'Constructions' => $pagination->getItems(),
'pagination' => $pagination,
];
}
/**
* 施工事例詳細画面
*
* @Route("/work/{id}", name="work_detail", methods={"GET"}, requirements={"id" = "\d+"})
* @Template("Work/detail.twig")
*
* @param Request $request
* @return array
*/
public function detail(Request $request, $id)
{
if (empty($id)) {
return $this->redirectToRoute('work');
}
$Construction = $this->constructionCaseRepository->findByIdImageSorted($id);
$ImageProducts = [];
foreach ($Construction->getConstructionCaseImage() as $image) {
$Products = $this->productRepository->findWithCategories($image->getProductIdText());
$ImageProducts[$image->getId()] = $Products;
}
return [
'Construction' => $Construction,
'ImageProducts' => $ImageProducts
];
}
}