app/Customize/Controller/ArtistsController.php line 106

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Customize\Controller;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Eccube\Controller\AbstractController;
  16. use Customize\Repository\ArtistRepository;
  17. use Customize\Repository\CategoryRepository;
  18. use Eccube\Repository\ProductRepository;
  19. use Customize\Entity\Artist
  20. class ArtistsController extends AbstractController
  21. {
  22.     /**
  23.      * @var ArtistRepository
  24.      */
  25.     protected $artistRepository;
  26.     /**
  27.      * @var CategoryRepository
  28.      */
  29.     protected $categoryRepository;
  30.     /**
  31.      * @var ProductRepository
  32.      */
  33.     protected $productRepository;
  34.     /**
  35.      *  @param ArtistRepository $artistRepository
  36.      *  @param CategoryRepository $categoryRepository
  37.      * @param ProductRepository $productRepository
  38.      */
  39.     public function __construct(
  40.         ArtistRepository $artistRepository,
  41.         CategoryRepository $categoryRepository,
  42.         ProductRepository $productRepository
  43.     )
  44.     {
  45.       $this->artistRepository $artistRepository;
  46.       $this->categoryRepository $categoryRepository;
  47.       $this->productRepository $productRepository;
  48.     }
  49.     /**
  50.      * @Route("/artists", name="artists", methods={"GET"})
  51.      * @Template("Artists/index.twig")
  52.      */
  53.     public function index()
  54.     {
  55.         $artists $this->artistRepository->customFindAllArtist();
  56.         $categories $this->categoryRepository->customFindAll();
  57.         $products $this->productRepository->findAll();
  58.         $id = [];
  59.         $num count($artists);
  60.         for($i=0$i<$num;$i++) {
  61.             array_push($id$artists[$i]["id"]);
  62.             $selectedArtist[] = $this->artistRepository->find($artists[$i]["id"]);
  63.             $selectedProducts[] = $this->productRepository->findBy(['artist_id' => $artists[$i]["id"]]);
  64.         }
  65.         $num2 count($selectedProducts) - 1;
  66.         // dd($selectedProducts);
  67.         // dd($id, $selectedArtist, $selectedProducts);
  68.         return [
  69.             'artists' => $artists,
  70.             'categories' => $categories,
  71.             "products" => $products,
  72.             'selectedArtist' => $selectedArtist,
  73.             'selectedProducts' => $selectedProducts,
  74.             "num" => $num,
  75.             "num2" => $num2,
  76.         ];
  77.     }
  78.     /**
  79.      * @Route("/artists/detail/{id}", name="artists_detail", methods={"GET"}, requirements={"id" = "\d+"})
  80.      * @Template("Artists/detail.twig")
  81.      * 
  82.      * @param int $id
  83.      */
  84.     public function detail($id)
  85.     {
  86.         $artists $this->artistRepository->customFindAllArtist();
  87.         $artist $this->artistRepository->find($id);
  88.         $selectedArtist $this->artistRepository->find($id);
  89.         $categories $this->categoryRepository->customFindAll();
  90.         $products $this->productRepository->findAll();
  91.         $selectedProducts $this->productRepository->findBy(['artist_id' => $id]);
  92.         return [
  93.             'artists' => $artists,
  94.             'artist' => $artist,
  95.             'selectedArtist' => $selectedArtist,
  96.             'categories' => $categories,
  97.             'selectedProducts' => $selectedProducts,
  98.         ];
  99.     }
  100. }