<?php
declare(strict_types=1);
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use WhiteOctober\BreadcrumbsBundle\Model\Breadcrumbs;
use App\Entity\SitePageCMSTranslation;
use App\Entity\SitePageCMS;
use App\Entity\SiteFAQ;
use App\Entity\SiteFAQCategory;
/**
* Pages CMS et FAQ
*/
class SitePageCMSController extends AbstractController
{
public function pageCMSAction(Breadcrumbs $breadcrumbs, $slug)
{
$em = $this->get('doctrine')->getManager();
$sitePageCmsRepository = $em->getRepository(SitePageCMSTranslation::class);
$sitePageCmsTranslation = $sitePageCmsRepository->findOneBySlug($slug);
if (empty($sitePageCmsTranslation)) {
throw new NotFoundHttpException("Cette page n'existe pas.");
}
$sitePageCms = $sitePageCmsTranslation->getTranslatable();
$breadcrumbs->addRouteItem("sylius.ui.home", "sylius_shop_homepage");
$breadcrumbs->addItem($sitePageCms->getTitle());
return $this->render('site_page_cms_show.html.twig', [
'sitePageCms' => $sitePageCms
]);
}
public function faqAction( Request $request, Breadcrumbs $breadcrumbs)
{
$faqsearch = $request->request->get('faqsearch', null);
$em = $this->get('doctrine')->getManager();
$siteFaqCategoryRepository = $em->getRepository(SiteFAQCategory::class);
$siteFaqsCategory = $siteFaqCategoryRepository->findAll();
$siteFaqRepository = $em->getRepository(SiteFAQ::class);
// dump($siteFaqsCategory);
// $siteFaqs = $siteFaqRepository->findAll();
$faqsAll = array();
foreach($siteFaqsCategory as $index => $siteFaqCategory){
$faqsAll[$index]['categorie'] = $siteFaqCategory;
if(!empty($faqsearch)){
$faqsAll[$index]['faqs'] = $siteFaqRepository->createQueryBuilder('o')
->where('o.question LIKE :search')
->andWhere('o.FAQCategory = :cat')
->setParameter('cat', $siteFaqCategory->getId())
->setParameter('search', '%'.$faqsearch.'%')
->getQuery()
->getResult();
}else{
$faqsAll[$index]['faqs'] = $siteFaqRepository->findBy(
['FAQCategory' => $siteFaqCategory->getId()]
);
}
}
// dump($faqsearch);
$breadcrumbs->addRouteItem("sylius.ui.home", "sylius_shop_homepage");
$breadcrumbs->addItem('FAQ');
return $this->render('site_faq.html.twig', [
'faqsAll' => $faqsAll,
'faqsearch' => $faqsearch,
]);
}
}