<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Customize\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;
use Eccube\Controller\AbstractController;
use Customize\Repository\ArtistRepository;
use Customize\Repository\CategoryRepository;
use Eccube\Repository\ProductRepository;
use Customize\Entity\Artist;
class ArtistsController extends AbstractController
{
/**
* @var ArtistRepository
*/
protected $artistRepository;
/**
* @var CategoryRepository
*/
protected $categoryRepository;
/**
* @var ProductRepository
*/
protected $productRepository;
/**
* @param ArtistRepository $artistRepository
* @param CategoryRepository $categoryRepository
* @param ProductRepository $productRepository
*/
public function __construct(
ArtistRepository $artistRepository,
CategoryRepository $categoryRepository,
ProductRepository $productRepository
)
{
$this->artistRepository = $artistRepository;
$this->categoryRepository = $categoryRepository;
$this->productRepository = $productRepository;
}
/**
* @Route("/artists", name="artists", methods={"GET"})
* @Template("Artists/index.twig")
*/
public function index()
{
$artists = $this->artistRepository->customFindAllArtist();
$categories = $this->categoryRepository->customFindAll();
$products = $this->productRepository->findAll();
$id = [];
$num = count($artists);
for($i=0; $i<$num;$i++) {
array_push($id, $artists[$i]["id"]);
$selectedArtist[] = $this->artistRepository->find($artists[$i]["id"]);
$selectedProducts[] = $this->productRepository->findBy(['artist_id' => $artists[$i]["id"]]);
}
$num2 = count($selectedProducts) - 1;
// dd($selectedProducts);
// dd($id, $selectedArtist, $selectedProducts);
return [
'artists' => $artists,
'categories' => $categories,
"products" => $products,
'selectedArtist' => $selectedArtist,
'selectedProducts' => $selectedProducts,
"num" => $num,
"num2" => $num2,
];
}
/**
* @Route("/artists/detail/{id}", name="artists_detail", methods={"GET"}, requirements={"id" = "\d+"})
* @Template("Artists/detail.twig")
*
* @param int $id
*/
public function detail($id)
{
$artists = $this->artistRepository->customFindAllArtist();
$artist = $this->artistRepository->find($id);
$selectedArtist = $this->artistRepository->find($id);
$categories = $this->categoryRepository->customFindAll();
$products = $this->productRepository->findAll();
$selectedProducts = $this->productRepository->findBy(['artist_id' => $id]);
return [
'artists' => $artists,
'artist' => $artist,
'selectedArtist' => $selectedArtist,
'categories' => $categories,
'selectedProducts' => $selectedProducts,
];
}
}