app/Customize/Controller/WorkController.php line 45

Open in your IDE?
  1. <?php
  2. namespace Customize\Controller;
  3. use Customize\Entity\ConstructionCase;
  4. use Customize\Repository\ConstructionCaseRepository;
  5. use Customize\Repository\ProductRepository;
  6. use Eccube\Controller\AbstractController;
  7. use Knp\Component\Pager\PaginatorInterface;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class WorkController extends AbstractController
  12. {
  13.     /**
  14.      * @var ConstructionCaseRepository
  15.      */
  16.     private $constructionCaseRepository;
  17.     /**
  18.      * @var ProductRepository
  19.      */
  20.     private $productRepository;
  21.     /**
  22.      * WorkController constructor.
  23.      */
  24.     public function __construct(
  25.         ConstructionCaseRepository $constructionCaseRepository,
  26.         ProductRepository $productRepository
  27.     )
  28.     {
  29.         $this->constructionCaseRepository $constructionCaseRepository;
  30.         $this->productRepository $productRepository;
  31.     }
  32.     /**
  33.      * 施工事例一覧画面
  34.      *
  35.      * @Route("/work", name="work", methods={"GET", "POST"})
  36.      * @Template("Work/index.twig")
  37.      */
  38.     public function index(Request $requestPaginatorInterface $paginator)
  39.     {
  40.         $queryBuilder $this->constructionCaseRepository->createQueryBuilder('c')
  41.             ->orderBy('c.update_date''DESC');
  42.         $page $request->query->getInt('pageno'1);
  43.         $limit 21// 1ページあたりの表示件数
  44.         $pagination $paginator->paginate(
  45.             $queryBuilder,
  46.             $page,
  47.             $limit
  48.         );
  49.         return [
  50.             'Constructions' => $pagination->getItems(),
  51.             'pagination' => $pagination,
  52.         ];
  53.     }
  54.     /**
  55.      * 施工事例詳細画面
  56.      *
  57.      * @Route("/work/{id}", name="work_detail", methods={"GET"}, requirements={"id" = "\d+"})
  58.      * @Template("Work/detail.twig")
  59.      *
  60.      * @param Request $request
  61.      * @return array
  62.      */
  63.     public function detail(Request $request$id)
  64.     {
  65.         if (empty($id)) {
  66.             return $this->redirectToRoute('work');
  67.         }
  68.         $Construction $this->constructionCaseRepository->findByIdImageSorted($id);
  69.         $ImageProducts = [];
  70.         foreach ($Construction->getConstructionCaseImage() as $image) {
  71.             $Products $this->productRepository->findWithCategories($image->getProductIdText());
  72.             $ImageProducts[$image->getId()] = $Products;
  73.         }
  74.         return [
  75.             'Construction' => $Construction,
  76.             'ImageProducts' => $ImageProducts
  77.         ];
  78.     }
  79. }