<?php
/*
* This file is part of EC-CUBE, Addition by INSPIRATION
*
*/
namespace Customize\Controller;
use Customize\Repository\CategoriesRepository;
use Customize\Repository\FaqsRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Eccube\Controller\AbstractController;
class FaqController extends AbstractController
{
/**
* @var CategoriesRepository
*/
protected $categoriesRepository;
/**
* @var FaqsRepository
*/
protected $faqsRepository;
/**
* FaqController constructor.
*
* @param FaqsRepository $faqsRepository
*/
public function __construct(
CategoriesRepository $categoriesRepository,
FaqsRepository $faqsRepository
)
{
$this->categoriesRepository = $categoriesRepository;
$this->faqsRepository = $faqsRepository;
}
/**
* よくある質問.
*
* @Route("/faq", name="faq", methods={"GET"})
* @Template("Faq/index.twig")
*/
public function index()
{
$qb = $this->categoriesRepository->createQueryBuilder('c')
->andWhere('c.del_flg = 0')
->andWhere('c.release_flg = 1')
->andWhere('c.program_name = :programName')
->setParameter(':programName', 'Faq')
->orderBy('c.rank');
$CategoryDatas = $qb->getQuery()->getResult();
return [
'CategoryDatas' => $CategoryDatas,
];
}
/**
* よくある質問検索結果.
*
* @Route("/faq/result", name="faq_result", methods={"GET"})
* @Template("Faq/result.twig")
*/
public function result(Request $request)
{
$Result = $request->query->get('query');
return [
'Result' => $Result,
];
}
/**
* よくある質問カテゴリー画面.
*
* @Route("/faq/category/{id}", name="faq_category", methods={"GET"}, requirements={"id" = "\d+"})
* @Template("Faq/category.twig")
*/
public function category($id)
{
$CategoryData = $this->categoriesRepository->findOneBy(['id' => $id]);
$qb = $this->faqsRepository->createQueryBuilder('f')
->andWhere('f.del_flg = 0')
->andWhere('f.release_flg = 1')
->andWhere('f.category = :findCategory')
->setParameter(':findCategory', $id)
->orderBy('f.rank');
$FaqListDatas = $qb->getQuery()->getResult();
return [
'CategoryData' => $CategoryData,
'FaqListDatas' => $FaqListDatas,
];
}
/**
* よくある質問詳細画面.
*
* @Route("/faq/detail/{id}", name="faq_detail", methods={"GET"}, requirements={"id" = "\d+"})
* @Template("Faq/detail.twig")
*/
public function detail($id)
{
$FaqData = $this->faqsRepository->findOneBy(['id' => $id]);
$qb = $this->faqsRepository->createQueryBuilder('f')
->andWhere('f.del_flg = 0')
->andWhere('f.release_flg = 1')
->andWhere('f.category = :findCategory')
->andWhere('f.id NOT IN (:excludes)')
->setParameter(':findCategory', $FaqData['category'])
->setParameter(':excludes', $FaqData['id'])
->orderBy('f.rank');
$RelationDatas = $qb->getQuery()->getResult();
return [
'FaqData' => $FaqData,
'RelationDatas' => $RelationDatas,
];
}
}