src/Controller/SitePageCMSController.php line 22

Open in your IDE?
  1. <?php 
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use WhiteOctober\BreadcrumbsBundle\Model\Breadcrumbs;
  9. use App\Entity\SitePageCMSTranslation;
  10. use App\Entity\SitePageCMS;
  11. use App\Entity\SiteFAQ;
  12. use App\Entity\SiteFAQCategory;
  13. /**
  14.  * Pages CMS et FAQ
  15.  */
  16. class SitePageCMSController extends AbstractController
  17. {
  18.     public function pageCMSAction(Breadcrumbs $breadcrumbs$slug)
  19.     {
  20.         $em $this->get('doctrine')->getManager();
  21.         $sitePageCmsRepository $em->getRepository(SitePageCMSTranslation::class);
  22.         $sitePageCmsTranslation $sitePageCmsRepository->findOneBySlug($slug);
  23.         if (empty($sitePageCmsTranslation)) {
  24.             throw new NotFoundHttpException("Cette page n'existe pas.");
  25.         }
  26.         $sitePageCms $sitePageCmsTranslation->getTranslatable();
  27.         $breadcrumbs->addRouteItem("sylius.ui.home""sylius_shop_homepage");
  28.         $breadcrumbs->addItem($sitePageCms->getTitle());
  29.         return $this->render('site_page_cms_show.html.twig', [
  30.             'sitePageCms' => $sitePageCms
  31.         ]);
  32.     }
  33.     public function faqActionRequest $requestBreadcrumbs $breadcrumbs)
  34.     {
  35.        
  36.         $faqsearch $request->request->get('faqsearch'null);
  37.         
  38.         $em $this->get('doctrine')->getManager();
  39.         $siteFaqCategoryRepository $em->getRepository(SiteFAQCategory::class);
  40.         $siteFaqsCategory $siteFaqCategoryRepository->findAll();
  41.         $siteFaqRepository $em->getRepository(SiteFAQ::class);
  42.         // dump($siteFaqsCategory);
  43.         // $siteFaqs = $siteFaqRepository->findAll();
  44.         $faqsAll = array();
  45.         foreach($siteFaqsCategory as $index => $siteFaqCategory){
  46.             $faqsAll[$index]['categorie'] = $siteFaqCategory;
  47.             if(!empty($faqsearch)){
  48.                 $faqsAll[$index]['faqs'] = $siteFaqRepository->createQueryBuilder('o')
  49.                 ->where('o.question LIKE :search')
  50.                 ->andWhere('o.FAQCategory = :cat')                
  51.                 ->setParameter('cat'$siteFaqCategory->getId())
  52.                 ->setParameter('search''%'.$faqsearch.'%')
  53.                 ->getQuery()
  54.                 ->getResult();
  55.             }else{
  56.                 $faqsAll[$index]['faqs'] = $siteFaqRepository->findBy(
  57.                     ['FAQCategory' => $siteFaqCategory->getId()]
  58.                 );      
  59.             }
  60.                
  61.         }
  62.         // dump($faqsearch);       
  63.         $breadcrumbs->addRouteItem("sylius.ui.home""sylius_shop_homepage");
  64.         $breadcrumbs->addItem('FAQ');
  65.         return $this->render('site_faq.html.twig', [
  66.             'faqsAll' => $faqsAll,
  67.             'faqsearch' => $faqsearch,
  68.         ]);
  69.     }
  70. }