<?php
namespace Customize\Controller;
use Eccube\Controller\AbstractController;
use Customize\Repository\TopImageRepository;
use Customize\Repository\NewsRepository;
use Customize\Repository\ProductRepository;
use Customize\Repository\TopProductRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;
class TopController extends AbstractController
{
/**
* @var TopImageRepository
*/
protected $topImageRepository;
/**
* @var NewsRepository
*/
protected $newsRepository;
/**
* @var ProductRepository
*/
protected $productRepository;
/**
* @var TopProductRepository
*/
protected $topProductRepository;
/**
* TopImageController constructor.
*
* @param TopImageRepository $topImageRepository
* @param NewsRepository $newsRepository
*/
public function __construct(
TopImageRepository $topImageRepository,
NewsRepository $newsRepository,
TopProductRepository $topProductRepository,
ProductRepository $productRepository
){
$this->topImageRepository = $topImageRepository;
$this->newsRepository = $newsRepository;
$this->productRepository = $productRepository;
$this->topProductRepository = $topProductRepository;
}
/**
* @Route("/", name="homepage")
* @Template("index.twig")
*/
public function index()
{
$TopImages = $this->topImageRepository->findBy([], ['sort_no' => 'DESC']);
$NewsList1 = $this->newsRepository->getList(3,0);
$NewsList2 = $this->newsRepository->getList(3,3);
$productIntroduction = $this->topProductRepository->getQueryBuilderAll()->getQuery()->getResult();
$ids = [];
foreach ($productIntroduction as $Product) {
$ids[] = $Product['product_id'];
}
$Products = $this->productRepository->getProductIntroductionList($ids);
return [
'TopImages' => $TopImages,
'NewsList1' => $NewsList1,
'NewsList2' => $NewsList2,
'Products' => $Products
];
}
}