<?php
namespace Customize\Controller;
use Eccube\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Plugin\Maker42\Entity\Maker;
use Plugin\Maker42\Repository\MakerRepository;
use Customize\Repository\MakerListRepository;
class MakerController extends AbstractController
{
/**
* @param MakerRepository $makerRepository
*/
/**
* @param MakerListRepository $makerListRepository
*/
public function __construct(
MakerRepository $makerRepository,
MakerListRepository $makerListRepository) {
$this->makerRepository = $makerRepository;
$this->makerListRepository = $makerListRepository;
}
/**
* @Method("GET")
* @Route("/maker/", name="maker")
* @Template("Maker/maker.twig")
*/
public function index()
{
$makers = $this->makerRepository->findBy([], ['sort_no' => 'DESC']);
return [
'Makers' => $makers,
];
}
/**
* @Method("GET")
* @Route("/maker/search", name="maker_search")
* @Template("Maker/search.twig")
*/
public function makerSearch()
{
if(!empty($_GET['kana'])){
$mode = 1;
$kana_key = $_GET['kana'];
$makers = $this->makerListRepository->makerSearch($mode,$_GET['kana']);
$maker_count = $this->makerListRepository->makerSearchCount($mode,$_GET['kana']);
}else{
$mode = 2;
$kana_array = [
"あ" => ['あ','い','う','え','お'],
"か" => ['か','き','く','け','こ'],
"さ" => ['さ','し','す','せ','そ'],
"た" => ['た','ち','つ','て','と'],
"な" => ['な','に','ぬ','ね','の'],
"は" => ['は','ひ','ふ','へ','ほ'],
"ま" => ['ま','み','む','め','も'],
"や" => ['や','ゆ','よ'],
"ら" => ['ら','り','る','れ','ろ'],
"わ" => ['わ','を','ん'],
];
$kana_row = "";
if(!empty($kana_array)){
foreach($kana_array as $kana_key => $kana_val){
if($kana_key == $_GET['kana_row']){
$kana_row = $kana_val;
}
}
}
$makers = $this->makerListRepository->makerSearch($mode,$kana_row);
$maker_count = $this->makerListRepository->makerSearchCount($mode,$kana_row);
}
return [
'makers' => $makers,
'maker_count' => $maker_count
];
}
}