<?php
namespace App\Controller;
use App\Repository\DescriptionRepository;
use App\Entity\RankingLignes;
use App\Repository\CommuneRepository;
use App\Repository\ProvinceRepository;
use App\Repository\RubriqueRepository;
use App\Repository\CommercesRepository;
use App\Repository\RankingRepository;
use App\Repository\RankingPhotosRepository;
use App\Repository\RankingLignesRepository;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query\ResultSetMapping;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Session\Session;
class RankingController extends AbstractController
{
private $em;
/**
* @var Environment
*/
private $twig;
/**
* @var CommuneRepository
*/
private $communeRepository;
/**
* @var ProvinceRepository
*/
private $provinceRepository;
/**
* @var RankingRepository
*/
private $rankingRepository;
/**
* @var RankingLignesRepository
*/
private $rankingLignesRepository;
/**
* @var CommercesRepository
*/
private $CommercesRepository;
/**
* @var RankingPhotosRepository
*/
private $rankingPhotoRepository;
/**
* @var RubriqueRepository
*/
private $rubriqueRepository;
/**
* @var DescriptionRepository
*/
private $descriptionRepository;
private $breadcrumb;
private $session ;
public function __construct(Environment $twig,
EntityManagerInterface $em,
CommuneRepository $communeRepository,
DescriptionRepository $descriptionRepository,
ProvinceRepository $ProvinceRepository,
RankingRepository $RankingRepository,
RankingLignesRepository $rankingLignesRepository,
RankingPhotosRepository $rankingPhotoRepository,
RubriqueRepository $rubriqueRepository,
CommercesRepository $CommercesRepository)
{
$this->twig = $twig;
$this->em = $em;
$this->descriptionRepository = $descriptionRepository;
$this->communeRepository = $communeRepository;
$this->provinceRepository = $ProvinceRepository;
$this->rankingRepository = $RankingRepository;
$this->rankingLignesRepository = $rankingLignesRepository;
$this->CommercesRepository = $CommercesRepository;
$this->rankingPhotoRepository = $rankingPhotoRepository;
$this->rubriqueRepository = $rubriqueRepository;
$this->breadcrumb=[];
}
/**
* @Route("/rubrique+{slug}.html",name="rubrique_ranking", requirements={"slug"="[^+]+", "rubrique_slug"="[^+]+"})
*/
public function index($slug, Request $request): Response
{
$rubrique= $this->rubriqueRepository->findOneBySlug($slug);
if(!$rubrique){
return $this->redirectToRoute('rubrique_text',array('text'=>$slug));
}
$communee = $this->communeRepository->find30Communee();
$id=!empty($rubrique) ? $rubrique->getId() : null;
$rubrique_name=!empty($rubrique) ?$rubrique->getRubrique() : null;
$rubrique_slug=!empty($rubrique) ? $rubrique->getSlugNom() :null;
$list_ranking = $id != null ? $this->rankingRepository->findByIdRubrique($id) : '';
$lignes = $this->rankingLignesRepository->findAll();
$photos = $this->rankingPhotoRepository->findAll();
$list_commcartesvisites = $id != null ? $this->CommercesRepository->getCartVisitCommerces($id): '';
$list_coloredComm = $id != null ? $this->CommercesRepository->getColoredCommerces($id): '';
$list_freeComm = $id != null ? $this->CommercesRepository->getFreeCommerces($id): '';
$total_results= count($list_ranking) + count($list_coloredComm) + count($list_commcartesvisites) + count($list_freeComm);
$meta_title = $rubrique_name . " Atout Commerces annuaire des commerçants et artisans en Wallonie | Atout-Commerces.be";
$meta_description = "Liste complète des " . $rubrique_name . ". Atout Commerces est un annuaire des commerçants, artisans, professions libérales, et entrepreneurs. 100.000 professionnels référencés. Retrouvez tous les " . $rubrique_name . " en Wallonie.";
//new rubrique ajax
$list_ranking1 = $id != null ? $this->rankingRepository->findByIdRubriqueAndLevel($id,1): '';
$list_ranking2 = $id != null ? $this->rankingRepository->findByIdRubriqueAndLevel($id,2): '';
$list_ranking3 = $id != null ? $this->rankingRepository->findByIdRubriqueAndLevel($id,3): '';
shuffle($list_ranking1);
shuffle($list_ranking2);
shuffle($list_ranking3);
$linkFR= "fr/rubrique+" . $slug . ".html";
$linkNL=!empty($rubrique) ?$rubrique->getRubriqueNL() : null;
$linkNL= "nl/rubrique+" . $linkNL . ".html";
$slug_commune = $this->communeRepository->findAll();
//rubrique state already exists
if ($request->query->get('l')=="get"){
return new Response($this->twig->render('Results_Search/rubrique.html.twig',
[
'list_ranking' => $list_ranking,
'list_commcartesvisites' => $list_commcartesvisites,
'list_coloredComm' => $list_coloredComm,
'list_freeComm' => $list_freeComm,
'lignes' => $lignes,
'photos' => $photos,
'idc' => null,
'idp' => null,
'rubrique_name' => $rubrique_name,
'ou' => null,
//'name'=>$rubrique_name,
'rubrique_slug' => $rubrique_slug,
'meta_title' => $meta_title,
'meta_description' => $meta_description,
'commune_nom' => null,
'total_results' => $total_results,
'province_obj' => null,
'textCommercial'=>false,
'noindex'=>count($list_ranking) >=20,
'rubriqueobjet' =>$rubrique ? $rubrique : null,
'communee'=>$communee,
'slug_commune'=>$slug_commune,
'linkNL' => $linkNL,
'linkFR' => $linkFR,
]));
}
if (count($list_ranking) < 20){
return new Response($this->twig->render('Results_Search/rubrique.html.twig',
[
'list_ranking' => $list_ranking,
'list_commcartesvisites' => $list_commcartesvisites,
'list_coloredComm' => $list_coloredComm,
'list_freeComm' => $list_freeComm,
'lignes' => $lignes,
'photos' => $photos,
'idc' => null,
'idp' => null,
'rubrique_name' => $rubrique_name,
'ou' => null,
//'name'=>$rubrique_name,
'rubrique_slug' => $rubrique_slug,
'meta_title' => $meta_title,
'meta_description' => $meta_description,
'commune_nom' => null,
'total_results' => $total_results,
'province_obj' => null,
'textCommercial'=>false,
'noindex'=>count($list_ranking) >=20,
'rubriqueobjet' =>$rubrique ? $rubrique : null,
'communee'=>$communee,
'slug_commune'=>$slug_commune,
'linkNL' => $linkNL,
'linkFR' => $linkFR,
]));
}
if (count($list_ranking) > 20){
return new Response($this->twig->render('Results_Search/new-rubrique-ajax.html.twig',
[
'idr'=>$id,
'idc'=>null,
'rubriqueobjet' =>$rubrique ? $rubrique : null,
'rubrique_name'=>$rubrique_name,
'ou'=>null,
'rubrique_slug'=>$rubrique_slug,
'meta_title' => $meta_title,
'meta_description' => $meta_description,
'slug_rub' => $slug,
'total_results'=>$total_results,
'textCommercial'=>false,
'list_ranking'=>$list_ranking,
'list_ranking1'=>$list_ranking1,
'list_ranking2'=>$list_ranking2,
'list_ranking3'=>$list_ranking3,
'lignes'=>$lignes,
'photos'=>$photos,
'list_commcartesvisites'=>$list_commcartesvisites,
'list_coloredComm'=>$list_coloredComm,
'list_freeComm'=>$list_freeComm,
'communee'=>$communee,
'slug_commune'=>$slug_commune,
'linkNL' => $linkNL,
'linkFR' => $linkFR,
]));
}
return new Response($this->twig->render('Results_Search/new-rubrique-ajax.html.twig',
[
'idr'=>$id,
'idc'=>null,
'rubriqueobjet' =>$rubrique ? $rubrique : null,
'rubrique_name'=>$rubrique_name,
'ou'=>null,
'rubrique_slug'=>$rubrique_slug,
'meta_title' => $meta_title,
'meta_description' => $meta_description,
'slug_rub' => $slug,
'total_results'=>$total_results,
'textCommercial'=>false,
'list_ranking'=>$list_ranking,
'list_ranking1'=>$list_ranking1,
'list_ranking2'=>$list_ranking2,
'list_ranking3'=>$list_ranking3,
'lignes'=>$lignes,
'photos'=>$photos,
'list_commcartesvisites'=>$list_commcartesvisites,
'list_coloredComm'=>$list_coloredComm,
'list_freeComm'=>$list_freeComm,
'communee'=>$communee,
'slug_commune'=>$slug_commune,
'linkNL' => $linkNL,
'linkFR' => $linkFR,
]));
}
/**
* @Route("/rubrique_stats/{slug_rub}",name="rubrique_stats")
*/
public function rubrique_stats($slug_rub)
{
$rubrique= $this->rubriqueRepository->findOneBySlug($slug_rub);
$id=!empty($rubrique) ? $rubrique->getId() : null;
$rubrique_name=!empty($rubrique) ?$rubrique->getRubrique() : null;
$rubrique_slug=!empty($rubrique) ? $rubrique->getSlugNom() :null;
$list_ranking = $id != null ? $this->rankingRepository->findByIdRubrique($id) : '';
$list_commcartesvisites = $id != null ? $this->CommercesRepository->getCartVisitCommerces($id): '';
$list_coloredComm = $id != null ? $this->CommercesRepository->getColoredCommerces($id): '';
$list_freeComm = $id != null ? $this->CommercesRepository->getFreeCommerces($id): '';
return new JsonResponse([
'html' => $this->renderView('Results_Search/template-parts/rubrique_stats.html.twig', [
'list_ranking'=>$list_ranking,
'list_commcartesvisites'=>$list_commcartesvisites,
'list_coloredComm'=>$list_coloredComm,
'list_freeComm'=>$list_freeComm,
'rubrique_name'=>$rubrique_name,
'rubrique_slug'=>$rubrique_slug,
'ou'=>null,
'idc'=>null,
'idr'=>$id,
'rubriqueobjet' =>$rubrique ? $rubrique : null,
]),
]);
}
/**
* @Route("/list_ranking/{slug_rub}",name="list_ranking")
*/
public function list_ranking($slug_rub)
{
$rubrique= $this->rubriqueRepository->findOneBySlug($slug_rub);
$id=!empty($rubrique) ? $rubrique->getId() : null;
$rubrique_name=!empty($rubrique) ?$rubrique->getRubrique() : null;
$rubrique_slug=!empty($rubrique) ? $rubrique->getSlugNom() :null;
$list_ranking = $id != null ? $this->rankingRepository->findByIdRubrique($id) : '';
$list_ranking1 = $id != null ? $this->rankingRepository->findByIdRubriqueAndLevel($id,1): '';
$list_ranking2 = $id != null ? $this->rankingRepository->findByIdRubriqueAndLevel($id,2): '';
$list_ranking3 = $id != null ? $this->rankingRepository->findByIdRubriqueAndLevel($id,3): '';
shuffle($list_ranking1);
shuffle($list_ranking2);
shuffle($list_ranking3);
$lignes= $this->rankingLignesRepository->findAll();
$photos= $this->rankingPhotoRepository->findAll();
return new JsonResponse([
'html' => $this->renderView('Results_Search/template-parts/list_ranking.html.twig', [
'list_ranking'=>$list_ranking,
'list_ranking1'=>$list_ranking1,
'list_ranking2'=>$list_ranking2,
'list_ranking3'=>$list_ranking3,
'rubrique_name'=>$rubrique_name,
'rubrique_slug'=>$rubrique_slug,
'lignes'=>$lignes,
'photos'=>$photos,
]),
]);
}
/**
* @Route("/list_commcartesvisites/{slug_rub}",name="list_commcartesvisites")
*/
public function list_commcartesvisites($slug_rub)
{
$rubrique= $this->rubriqueRepository->findOneBySlug($slug_rub);
$id=!empty($rubrique) ? $rubrique->getId() : null;
$rubrique_name=!empty($rubrique) ?$rubrique->getRubrique() : null;
$rubrique_slug=!empty($rubrique) ? $rubrique->getSlugNom() :null;
$list_commcartesvisites = $id != null ? $this->CommercesRepository->getCartVisitCommerces($id): '';
return new JsonResponse([
'html' => $this->renderView('Results_Search/template-parts/list_commcartesvisites.html.twig', [
'list_commcartesvisites'=>$list_commcartesvisites,
'rubrique_name'=>$rubrique_name,
'rubrique_slug'=>$rubrique_slug,
]),
]);
}
/**
* @Route("/list_coloredComm/{slug_rub}",name="list_coloredComm")
*/
public function list_coloredComm($slug_rub)
{
$rubrique= $this->rubriqueRepository->findOneBySlug($slug_rub);
$id=!empty($rubrique) ? $rubrique->getId() : null;
$rubrique_name=!empty($rubrique) ?$rubrique->getRubrique() : null;
$rubrique_slug=!empty($rubrique) ? $rubrique->getSlugNom() :null;
$list_coloredComm = $id != null ? $this->CommercesRepository->getColoredCommerces($id): '';
return new JsonResponse([
'html' => $this->renderView('Results_Search/template-parts/list_coloredComm.html.twig', [
'list_coloredComm'=>$list_coloredComm,
'rubrique_name'=>$rubrique_name,
'rubrique_slug'=>$rubrique_slug,
]),
]);
}
/**
* @Route("/list_freeComm/{slug_rub}",name="list_freeComm")
*/
public function list_freeComm($slug_rub)
{
$rubrique= $this->rubriqueRepository->findOneBySlug($slug_rub);
$id=!empty($rubrique) ? $rubrique->getId() : null;
$list_freeComm = $id != null ? $this->CommercesRepository->getFreeCommerces($id): '';
return new JsonResponse([
'html' => $this->renderView('Results_Search/template-parts/list_freeComm.html.twig', [
'list_freeComm'=>$list_freeComm,
]),
]);
}
/**
* @Route("/rubrique/{slug_rubrique}/commune/{slug_commune}",name="rubrique_commune",requirements={ "slug_rubrique"="[^+]+", "slug_commune"="^(?!province.*$).*[^+]+" })
*/
public function rubriqueCommune($slug_rubrique, $slug_commune): Response
{
return $this->redirectToRoute('rub_comm_url',array('slug_rubrique'=>$slug_rubrique,'slug_commune'=>$slug_commune));
}
/**
* @Route("/rubrique+{slug_rubrique}+{slug_commune}.html",name="rub_comm_url", requirements={ "slug_rubrique"="[^+]+", "rubrique_slug"="[^+]+" , "slug_commune"="^(?!province.*$).*[^+]+" })
*/
public function rubcommurl($slug_rubrique, $slug_commune): Response
{
$rubrique= $this->rubriqueRepository->findOneBySlug($slug_rubrique);
$commune1= $this->communeRepository->findOneBySlug($slug_commune);
$commune2= $this->communeRepository->findOneByEntite1($slug_commune);
$commune = $commune1 ? $commune1 : $commune2;
if ( $rubrique== null) {
return $this->redirectToRoute('text_rubrique_id_commune',array('text_rubrique'=>$slug_rubrique,'slug_commune'=>$slug_commune));
}
if ($commune == null and $rubrique== null) {
return new Response($this->twig->render('Results_Search/critere_not_found.html.twig',
[
'critere'=>$commune? $slug_rubrique:$slug_commune,
'champs_recherche' =>$commune? 'rubrique':'commune',
]));
}
else {
$commune_id = !empty($commune) ? $commune->getId() : null;
$commune_name = !empty($commune) ? $commune->getNom() : $slug_commune;
$commune_slug = !empty($commune) ? $commune->getSlugNom() : $slug_commune;
$province_name = !empty($commune) ? $commune->getIdProvince()->getNom() : null;
$province_obj = !empty($commune) ? $commune->getIdProvince() : null;
$province_url = !empty($commune) ? $commune->getIdProvince()->getUrl() : null;
$province_id = !empty($commune) ? $commune->getIdProvince()->getId() : null;
$commune_slug = !empty($commune1) ? $commune->getSlugNom() : $slug_commune;
$commune_nom = !empty($commune) ? $commune->getNom() : null;
$rubrique_id = !empty($rubrique) ? $rubrique->getId() : null;
$name = !empty($rubrique) ? $rubrique->getRubrique() : null;
$slug = !empty($rubrique) ? $rubrique->getSlugNom() : null;
// TOTAL RESULT
$id=!empty($rubrique) ? $rubrique->getId() : null;
$list_ranking = $id != null ? $this->rankingRepository->findByRubriqueCommune($id,$commune_id) : '';
$list_ranking1 = $id != null ? $this->rankingRepository->findByRubriqueCommuneAndLevel($id,$commune_id,1): '';
$list_ranking2 = $id != null ? $this->rankingRepository->findByRubriqueCommuneAndLevel($id,$commune_id,2): '';
$list_ranking3 = $id != null ? $this->rankingRepository->findByRubriqueCommuneAndLevel($id,$commune_id,3): '';
shuffle($list_ranking1);
shuffle($list_ranking2);
shuffle($list_ranking3);
$list_commcartesvisites = $id != null ? $this->CommercesRepository->findCartVisitCommercesByRubriqueAndCommune($id,$commune_id): '';
$list_coloredComm = $id != null ? $this->CommercesRepository->findColoredCommercesByRubriqueAndCommune($id,$commune_id): '';
$list_freeComm = $id != null ? $this->CommercesRepository->findFreeCommercesByRubriqueAndCommune($id,$commune_id): '';
$total_result= count($list_ranking) + count($list_freeComm) +count($list_commcartesvisites) + count($list_coloredComm);
// TOTAL RESULT
$meta_title = $name . " à " . $commune_name . " . Atout Commerces annuaire des commerçants et artisans en Wallonie | Atout-Commerces.be";
$meta_description = "Liste complète des " . $name . " de la commune de " . $commune_name . " . Atout Commerces est un annuaire des commerçants, artisans, professions libérales, et entrepreneurs. 100.000 professionnels référencés. Retrouvez tous les " . $name . " en Wallonie.";
$lignes= $this->rankingLignesRepository->findAll();
$photos= $this->rankingPhotoRepository->findAll();
$descriptionseo=$this->descriptionRepository->findByRubriqueCommune($rubrique_id,$commune_id);
$linkFR= "fr/rubrique+" . $slug_rubrique . "+". $slug_commune . ".html";
$slugRubNL=!empty($rubrique) ?$rubrique->getRubriqueNL() : null;
$slugComNL=!empty($commune) ? $commune->getSlugNL() : null;
$linkNL="nl/rubrique+" . $slugRubNL . "+". $slugComNL . ".html";
/**maillage*** */
$communesMaillage = [];
if ($province_obj && $rubrique_id) {
$communesDeProvince = $this->communeRepository->findBy(['idProvince' => $province_id]);
foreach ($communesDeProvince as $communeProche) {
$nbCommerces = $this->CommercesRepository->countCommercesByRubriqueAndCommune($rubrique_id, $communeProche->getId());
if ($nbCommerces > 0 && $communeProche->getId() !== $commune_id) {
$communesMaillage[] = [
'nom' => $communeProche->getNom(),
'slugNom' => $communeProche->getSlugNom(),
'compteur' => $nbCommerces
];
}
}
}
usort($communesMaillage, function($a, $b) {
return $b['compteur'] <=> $a['compteur'];
});
return new Response($this->twig->render('Results_Search/rubrique.html.twig',
[
'list_ranking'=>$list_ranking,
'list_ranking1'=>$list_ranking1,
'list_ranking2'=>$list_ranking2,
'list_ranking3'=>$list_ranking3,
'list_commcartesvisites'=>$list_commcartesvisites,
'list_coloredComm'=>$list_coloredComm,
'list_freeComm'=>$list_freeComm,
'lignes'=>$lignes,
'photos'=>$photos,
'ou'=>$commune_name,
'idc'=>$commune_id,
'idp'=>null,
'rubrique_name'=>$name,
'rubrique_slug'=>$slug,
'name'=>$commune_name,
'commune_nom'=>$commune_name,
'province_obj'=>$province_obj,
'slug'=>$commune_slug,
'rubriqueobjet' =>$rubrique ? $rubrique : null,
'total_results' => $total_result,
'descriptionseoo'=>$descriptionseo ? $descriptionseo : null,
'linkNL' => $linkNL,
'linkFR' => $linkFR,
'communes_maillage' => $communesMaillage,
'province_nom' => $province_name,
]));
}
}
/**
* @Route("/rubrique_commune_stats/{slug_rubrique}/{slug_commune}",name="rubrique_commune_stats")
*/
public function rubrique_commune_stats($slug_rubrique, $slug_commune)
{
$rubrique= $this->rubriqueRepository->findOneBySlug($slug_rubrique);
$commune1= $this->communeRepository->findOneBySlug($slug_commune);
$commune2= $this->communeRepository->findOneByEntite1($slug_commune);
$commune = $commune1 ? $commune1 : $commune2;
$commune_id=!empty($commune) ? $commune->getId() : null;
$commune_name=!empty($commune1) ? $commune->getNom() : $slug_commune;
$province_name=!empty($commune) ? $commune->getIdProvince()->getNom() : null;
$rubrique_id=!empty($rubrique) ? $rubrique->getId():null;
$name=!empty($rubrique) ? $rubrique->getRubrique():null;
$slug=!empty($rubrique) ? $rubrique->getSlugNom():null;
$list_ranking =$commune_id !=null && $rubrique_id !=null ? $this->rankingRepository->findByRubriqueCommune($rubrique_id,$commune_id) :'';
$list_commcartesvisites =$commune_id !=null && $rubrique_id !=null ? $this->CommercesRepository->findCartVisitCommercesByRubriqueAndCommune($rubrique_id,$commune_id):'';
$list_coloredComm =$commune_id !=null && $rubrique_id !=null ? $this->CommercesRepository->findColoredCommercesByRubriqueAndCommune($rubrique_id,$commune_id):'';
$list_freeComm =$commune_id !=null && $rubrique_id !=null ? $this->CommercesRepository->findFreeCommercesByRubriqueAndCommune($rubrique_id,$commune_id):'';
return new JsonResponse([
'html' => $this->renderView('Results_Search/template-parts/rubrique_stats.html.twig', [
'list_ranking'=>$list_ranking,
'list_commcartesvisites'=>$list_commcartesvisites,
'list_coloredComm'=>$list_coloredComm,
'list_freeComm'=>$list_freeComm,
'rubrique_name'=>$name,
'rubrique_slug'=>$slug,
'ou'=>$commune_name,
'idc'=>null,
'idr'=>$rubrique_id,
'province' => $province_name,
'rubriqueobjet' =>$rubrique ? $rubrique : null,
]),
]);
}
/**
* @Route("/list_ranking_rubrique_commune/{slug_rubrique}/{slug_commune}",name="list_ranking_rubrique_commune")
*/
public function list_ranking_rubrique_commune($slug_rubrique, $slug_commune)
{
$rubrique= $this->rubriqueRepository->findOneBySlug($slug_rubrique);
$commune1= $this->communeRepository->findOneBySlug($slug_commune);
$commune2= $this->communeRepository->findOneByEntite1($slug_commune);
$commune = $commune1 ? $commune1 : $commune2;
$commune_id=!empty($commune) ? $commune->getId() : null;
$rubrique_id=!empty($rubrique) ? $rubrique->getId():null;
$rubrique_name=!empty($rubrique) ? $rubrique->getRubrique():null;
$province_id=!empty($commune) ? $commune->getIdProvince()->getId():null;
$list_ranking =$commune_id !=null && $rubrique_id !=null ? $this->rankingRepository->findByRubriqueCommune($rubrique_id,$commune_id) :'';
$lignes= $this->rankingLignesRepository->findAll();
$photos= $this->rankingPhotoRepository->findAll();
return new JsonResponse([
'html' => $this->renderView('Results_Search/template-parts/list_ranking.html.twig', [
'list_ranking'=>$list_ranking,
'lignes'=>$lignes,
'photos'=>$photos,
'idC'=>$commune_id,
'idP'=>$province_id,
'rubrique_name'=>$rubrique_name,
]),
]);
}
/**
* @Route("/list_commcartesvisites_rubrique_commune/{slug_rubrique}/{slug_commune}",name="list_commcartesvisites_rubrique_commune")
*/
public function list_commcartesvisites_rubrique_commune($slug_rubrique, $slug_commune)
{
$rubrique= $this->rubriqueRepository->findOneBySlug($slug_rubrique);
$commune1= $this->communeRepository->findOneBySlug($slug_commune);
$commune2= $this->communeRepository->findOneByEntite1($slug_commune);
$commune = $commune1 ? $commune1 : $commune2;
$commune_id=!empty($commune) ? $commune->getId() : null;
$rubrique_id=!empty($rubrique) ? $rubrique->getId():null;
$list_commcartesvisites =$commune_id !=null && $rubrique_id !=null ? $this->CommercesRepository->findCartVisitCommercesByRubriqueAndCommune($rubrique_id,$commune_id):'';
$rubrique_name=!empty($rubrique) ?$rubrique->getRubrique() : null;
return new JsonResponse([
'html' => $this->renderView('Results_Search/template-parts/list_commcartesvisites.html.twig', [
'list_commcartesvisites'=>$list_commcartesvisites,
'rubrique_name'=>$rubrique_name,
]),
]);
}
/**
* @Route("/list_coloredComm_rubrique_commune/{slug_rubrique}/{slug_commune}",name="list_coloredComm_rubrique_commune")
*/
public function list_coloredComm_rubrique_commune($slug_rubrique, $slug_commune)
{
$rubrique= $this->rubriqueRepository->findOneBySlug($slug_rubrique);
$commune1= $this->communeRepository->findOneBySlug($slug_commune);
$commune2= $this->communeRepository->findOneByEntite1($slug_commune);
$commune = $commune1 ? $commune1 : $commune2;
$commune_id=!empty($commune) ? $commune->getId() : null;
$rubrique_id=!empty($rubrique) ? $rubrique->getId():null;
$list_coloredComm =$commune_id !=null && $rubrique_id !=null ? $this->CommercesRepository->findColoredCommercesByRubriqueAndCommune($rubrique_id,$commune_id):'';
return new JsonResponse([
'html' => $this->renderView('Results_Search/template-parts/list_coloredComm.html.twig', [
'list_coloredComm'=>$list_coloredComm,
]),
]);
}
/**
* @Route("/list_freeComm/{slug_rubrique}/{slug_commune}",name="list_freeComm_rubrique_commune")
*/
public function list_freeComm_rubrique_commune($slug_rubrique, $slug_commune)
{
$rubrique= $this->rubriqueRepository->findOneBySlug($slug_rubrique);
$commune1= $this->communeRepository->findOneBySlug($slug_commune);
$commune2= $this->communeRepository->findOneByEntite1($slug_commune);
$commune = $commune1 ? $commune1 : $commune2;
$commune_id=!empty($commune) ? $commune->getId() : null;
$rubrique_id=!empty($rubrique) ? $rubrique->getId():null;
$list_freeComm =$commune_id !=null && $rubrique_id !=null ? $this->CommercesRepository->findFreeCommercesByRubriqueAndCommune($rubrique_id,$commune_id):'';
return new JsonResponse([
'html' => $this->renderView('Results_Search/template-parts/list_freeComm.html.twig', [
'list_freeComm'=>$list_freeComm,
]),
]);
}
/**
* @Route("/rubrique/{slug_rubrique}/province/{slug_province}",name="rubrique_province", requirements={ "slug_province"="[^+]+", "slug_rubrique"="[^+]+" })
*/
public function rubriqueProvince($slug_rubrique, $slug_province): Response
{
return $this->redirectToRoute('rub_prov_url',array('slug_rubrique'=>$slug_rubrique,'slug_province'=>$slug_province));
}
/**
* @Route("/rubrique+{slug_rubrique}+{slug_province}.html",name="rub_prov_url", requirements={ "slug_province"="[^+]+", "slug_province"="[^+]+" })
*/
public function rubProvinceUrl($slug_rubrique, $slug_province): Response
{
$rubrique= $this->rubriqueRepository->findOneBySlug($slug_rubrique);
$province= $this->provinceRepository->findOneBy(array('url'=>$slug_province));
if ( $rubrique == null) {
return $this->redirectToRoute('rub_text_prov_url',array('text_rubrique'=>$slug_rubrique,'slug_province'=>$slug_province));
}
if ($province == null and $rubrique== null) {
return new Response($this->twig->render('Results_Search/critere_not_found.html.twig',
[
'critere'=>$province? $slug_rubrique:$slug_province,
'champs_recherche' =>$province? 'rubrique':'province',
]));
} else {
$province_id = !empty($province) ? $province->getId() : null;
$province_name = !empty($province) ? $province->getNom() : null;
$province_slug = !empty($province) ? $province->getUrl() : null;
$rubrique_id = !empty($rubrique) ? $rubrique->getId() : null;
$name = !empty($rubrique) ? $rubrique->getRubrique() : null;
$slug = !empty($rubrique) ? $rubrique->getSlugNom() : null;
$list_ranking = $province_id != null && $rubrique_id != null ? $this->rankingRepository->findByRubriqueProvince($rubrique_id, $province_id) : '';
$list_commcartesvisites = $province_id != null && $rubrique_id != null ? $this->CommercesRepository->findCartVisitCommercesByRubriqueAndProvince($rubrique_id, $province_id) : '';
$list_coloredComm = $province_id != null && $rubrique_id != null ? $this->CommercesRepository->findColoredCommercesByRubriqueAndProvince($rubrique_id, $province_id) : '';
$list_freeComm = $province_id != null && $rubrique_id != null ? $this->CommercesRepository->findFreeCommercesByRubriqueAndProvince($rubrique_id, $province_id) : '';
$total_results= count($list_ranking) + count($list_coloredComm) + count($list_commcartesvisites) + count($list_freeComm);
$lignes = $this->rankingLignesRepository->findAll();
$photos = $this->rankingPhotoRepository->findAll();
// Get province communes for maillage
$provinceCommuneMapping = $this->getProvinceCommuneMapping();
$province_communes_names = [];
foreach ($provinceCommuneMapping as $key => $communes) {
if (strcasecmp($key, $province_name) === 0) {
$province_communes_names = $communes;
break;
}
}
$province_communes_maillage = [];
if (!empty($province_communes_names) && $rubrique_id != null) {
foreach ($province_communes_names as $commune_name) {
$commune = $this->communeRepository->findOneBy(['nom' => $commune_name]);
if (!$commune) {
continue;
}
$commune_id = $commune->getId();
// Get the count of commerces for this rubrique in this commune
$count_ranking = count($this->rankingRepository->findByRubriqueCommune($rubrique_id, $commune_id));
$count_cartes = count($this->CommercesRepository->findCartVisitCommercesByRubriqueAndCommune($rubrique_id, $commune_id));
$count_colored = count($this->CommercesRepository->findColoredCommercesByRubriqueAndCommune($rubrique_id, $commune_id));
$count_free = count($this->CommercesRepository->findFreeCommercesByRubriqueAndCommune($rubrique_id, $commune_id));
$total_count = $count_ranking + $count_cartes + $count_colored + $count_free;
$province_communes_maillage[] = [
'nom' => $commune->getNom(),
'slugNom' => $commune->getSlugNom(),
'compteur' => $total_count
];
}
}
$linkFR= "fr/rubrique+" . $slug_rubrique . "+".$slug_province.".html";
$slugRubNL=!empty($rubrique) ?$rubrique->getRubriqueNL() : null;
$slugProvFR=!empty($province) ? $province->getProvNL() : null;
$linkNL= "nl/rubrique+" . $slugRubNL . "+".$slugProvFR.".html";
return new Response($this->twig->render('Results_Search/rubrique.html.twig',
[
'list_ranking' => $list_ranking,
'list_commcartesvisites' => $list_commcartesvisites,
'list_coloredComm' => $list_coloredComm,
'list_freeComm' => $list_freeComm,
'lignes' => $lignes,
'photos' => $photos,
'ou' => $province_name,
'idc' => null,
'idp' => $province_id,
'rubrique_name' => $name,
'rubrique_slug' => $slug,
'name' => $province_name,
'province' => $province_name,
'slug' => $province_slug,
'total_results' => $total_results,
'commune_nom' => null,
'province_obj' => $province,
'rubriqueobjet' =>$rubrique ? $rubrique : null,
'linkNL' => $linkNL,
'linkFR' => $linkFR,
'province_communes_maillage' => $province_communes_maillage,
]));
}
}
/**
* @Route("/rubrique/{slug_rubrique}/code_postal/{code}",name="rubrique_code_postal", requirements={"token"=".+"})
*/
public function rubriqueCodePostal($slug_rubrique, $code): Response
{
$commune= $this->communeRepository->findByCodePostal($code);
$commune_id=null;
$commune_name=null;
$commune_slugname=null;
$province_id=null;
foreach ( $commune as $c){
$commune_id=$c->getId();
$province_id=$c->getIdProvince();
$commune_name=$c->getNom();
$commune_slugname=$c->getSlugNom();
}
$rubrique= $this->rubriqueRepository->findOneBySlug($slug_rubrique);
if ($commune == null or $rubrique == null){
return new Response($this->twig->render('bundles/TwigBundle/Exception/error404.html.twig'));
}else {
$rubrique_id = !empty($rubrique) ? $rubrique->getId() : null;
$name = !empty($rubrique) ? $rubrique->getRubrique() : null;
$list_ranking = $commune_id != null && $rubrique_id != null ? $this->rankingRepository->findByRubriqueCommune($rubrique_id, $commune_id) : '';
$list_commcartesvisites = $commune_id != null && $rubrique_id != null ? $this->CommercesRepository->findCartVisitCommercesByRubriqueAndCommune($rubrique_id, $commune_id) : '';
$list_coloredComm = $commune_id != null && $rubrique_id != null ? $this->CommercesRepository->findColoredCommercesByRubriqueAndCommune($rubrique_id, $commune_id) : '';
$list_freeComm = $this->CommercesRepository->findFreeCommercesByRubriqueAndCommune($rubrique_id, $commune_id);
$total_results= count($list_ranking) + count($list_coloredComm) + count($list_commcartesvisites) + count($list_freeComm);
$lignes = $this->rankingLignesRepository->findAll();
$photos = $this->rankingPhotoRepository->findAll();
$linkFR= "fr/rubrique/" . $slug_rubrique . "/code_postal/". $code;
$linkNL=!empty($rubrique) ?$rubrique->getRubriqueNL() : null;
$linkNL= "nl/rubrique/" . $linkNL . "/code_postal/". $code;
return new Response($this->twig->render('Results_Search/rubrique.html.twig',
[
'list_ranking' => $list_ranking,
'list_commcartesvisites' => $list_commcartesvisites,
'list_coloredComm' => $list_coloredComm,
'list_freeComm' => $list_freeComm,
'lignes' => $lignes,
'photos' => $photos,
'ou' => $commune_name,
'idc' => $commune_id,
'idp' => $province_id,
'rubrique_name' => $name,
'name' => $commune_name,
'commune_nom' => $commune_name,
'total_results' => $total_results,
'slug' => $commune_slugname,
'rubriqueobjet' =>$rubrique ? $rubrique : null,
'linkNL' => $linkNL,
'linkFR' => $linkFR,
]));
}
}
//text rubrique + id commune
/**
* @Route("/rubrique/{text_rubrique}+{slug_commune}.html",name="text_rubrique_id_commune", requirements={"token"=".+"})
*/
public function textRubriqueIDCommune($text_rubrique,$slug_commune){
//var_dump("text",$text_rubrique); die();
$commune1= $this->communeRepository->findOneBy(array('slugNom'=>$slug_commune));
$commune2= $this->communeRepository->findOneByEntite1($slug_commune);
$commune = $commune1 ? $commune1 : $commune2;
$commune_id=!empty($commune) ? $commune->getId() : null;
$commune_name=!empty($commune) ? $commune->getNom() : null;
$commune_slug=!empty($commune) ? $commune->getSlugNom() : null;
$name=$text_rubrique;
$slug=$text_rubrique;
$list_ranking =$commune_id !=null ? $this->rankingRepository->txtrubriqueIdCommune($text_rubrique,$commune_id) :'';
$list_commcartesvisites =$commune_id !=null ? $this->CommercesRepository->findCartVisitCommercesByTxtRubriqueAndCommune($text_rubrique,$commune_id):'';
$list_coloredComm =$commune_id !=null ? $this->CommercesRepository->findColoredCommercesByTxtRubriqueAndCommune($text_rubrique,$commune_id):'';
$list_freeComm =$commune_id !=null ? $this->CommercesRepository->findFreeCommercesByTxtRubriqueAndCommune($text_rubrique,$commune_id):'';
$total_results= count($list_ranking) + count($list_coloredComm) + count($list_commcartesvisites) + count($list_freeComm);
$lignes= $this->rankingLignesRepository->findAll();
$photos= $this->rankingPhotoRepository->findAll();
return new Response($this->twig->render('Results_Search/rubrique.html.twig',
[
'list_ranking'=>$list_ranking,
'list_commcartesvisites'=>$list_commcartesvisites,
'list_coloredComm'=>$list_coloredComm,
'list_freeComm'=>$list_freeComm,
'lignes'=>$lignes,
'photos'=>$photos,
'ou'=>$commune_name,
'rubrique_name'=>$name,
'idc'=>$commune_id,
'rubrique_slug'=>$slug,
'name'=>$commune_name,
'slug'=>$commune_slug,
'commune_nom' => null,
'total_results' => $total_results,
'idp' => null,
]));
}
//text rubrique + id province
/**
* @Route("/rubrique/{text_rubrique}+{slug_province}",name="rub_text_prov_url", requirements={ "slug_province"="[^+]+", "slug_province"="[^+]+" })
*/
public function textRubriqueIDProvince($text_rubrique, $slug_province): Response
{
$province= $this->provinceRepository->findOneBy(array('url'=>$slug_province));
$province_id=!empty($province)? $province->getId():null;
$province_name=!empty($province)? $province->getNom():null;
$province_slug=!empty($province)? $province->getUrl():null;
$commune_nom=null;
$ids_commune = $this->communeRepository->findByIdProvince($province_id);
$ids=[];
foreach ($ids_commune as $c){
array_push($ids,$c->getId());
}
$list_ranking =$province_id !=null ? $this->rankingRepository->findByTextRubriqueProvince($text_rubrique,$province_id) :'';
$list_commcartesvisites = $province_id !=null ? $this->CommercesRepository->findCartVisitCommercesByTextRubriqueAndProvince($text_rubrique,$province_id):'';
$list_coloredComm = $province_id !=null ? $this->CommercesRepository->findColoredCommercesByTextRubriqueAndProvince($text_rubrique,$province_id):'';
$list_freeComm = $province_id !=null ? $this->CommercesRepository->findFreeCommercesByTextRubriqueAndProvince($text_rubrique,$province_id):'';
$total_results= count($list_ranking) + count($list_coloredComm) + count($list_commcartesvisites) + count($list_freeComm);
$lignes= $this->rankingLignesRepository->findAll();
$photos= $this->rankingPhotoRepository->findAll();
// Get province communes for maillage
$provinceCommuneMapping = $this->getProvinceCommuneMapping();
$province_communes_names = [];
foreach ($provinceCommuneMapping as $key => $communes) {
if (strcasecmp($key, $province_name) === 0) {
$province_communes_names = $communes;
break;
}
}
$province_communes_maillage = [];
if (!empty($province_communes_names)) {
foreach ($province_communes_names as $commune_name) {
$commune = $this->communeRepository->findOneBy(['nom' => $commune_name]);
if (!$commune) {
continue;
}
$commune_id = $commune->getId();
// Get the count of commerces for this text rubrique in this commune
$count_ranking = count($this->rankingRepository->txtrubriqueIdCommune($text_rubrique, $commune_id));
$count_cartes = count($this->CommercesRepository->findCartVisitCommercesByTxtRubriqueAndCommune($text_rubrique, $commune_id));
$count_colored = count($this->CommercesRepository->findColoredCommercesByTxtRubriqueAndCommune($text_rubrique, $commune_id));
$count_free = count($this->CommercesRepository->findFreeCommercesByTxtRubriqueAndCommune($text_rubrique, $commune_id));
$total_count = $count_ranking + $count_cartes + $count_colored + $count_free;
$province_communes_maillage[] = [
'nom' => $commune->getNom(),
'slugNom' => $commune->getSlugNom(),
'compteur' => $total_count
];
}
}
$linkFR= "fr/rubrique/" . $text_rubrique . "+".$slug_province;
$slugProvFR=!empty($province) ? $province->getProvNL() : null;
$linkNL= "nl/rubrique/" . $text_rubrique . "+".$slugProvFR;
return new Response($this->twig->render('Results_Search/rubrique.html.twig',
[
'list_ranking'=>$list_ranking,
'list_commcartesvisites'=>$list_commcartesvisites,
'list_coloredComm'=>$list_coloredComm,
'list_freeComm'=>$list_freeComm,
'lignes'=>$lignes,
'photos'=>$photos,
'ou'=>$province_name,
'idc'=>null,
'idp'=>$province_id,
'rubrique_name'=>$text_rubrique,
'rubrique_slug'=>$text_rubrique,
'name' => $province_name,
'commune_nom' => null,
'province_obj' => $province,
'total_results' => $total_results,
'slug' => $province_slug,
'linkNL' => $linkNL,
'linkFR' => $linkFR,
'province_communes_maillage' => $province_communes_maillage,
]));
}
/**
* @Route("/rubrique/{text}.html",name="rubrique_text", requirements={"slug"="[^+]+"})
*/
public function textRubrique($text,Request $request): Response
{
$rubrique_name=$text;
$rubrique_slug=$text;
$communee = $this->communeRepository->find30Communee();
$rubrique= $this->rubriqueRepository->findOneBySlug($text);
$province_obj=null;
if (!$rubrique) {
// Rechercher par mot clé si non trouvé par slug
$rubrique = $this->rubriqueRepository->findOneByMotCle($text);
if ($rubrique) {
// Rediriger vers la route avec le slug de la rubrique trouvée
return $this->redirectToRoute('rubrique_ranking', ['slug' => $rubrique->getSlugNom()]);
}
}
if($rubrique){
return $this->redirectToRoute('rubrique_ranking',array('slug'=>$text));
}else {
$list_ranking = $this->rankingRepository->findByTextRubrique($text);
$list_ranking1 = $this->rankingRepository->findByTextRubriqueAndLevel($text,1);
$list_ranking2 = $this->rankingRepository->findByTextRubriqueAndLevel($text,2);
$list_ranking3 = $this->rankingRepository->findByTextRubriqueAndLevel($text,3);
shuffle($list_ranking1);
shuffle($list_ranking2);
shuffle($list_ranking3);
// dd($list_ranking,$list_ranking1);
$list_commcartesvisites = $this->CommercesRepository->getCartVisitCommercesByTextrub($text);
$list_coloredComm = $this->CommercesRepository->getColoredCommercesByTextrub($text);
$list_freeComm = $this->CommercesRepository->getFreeCommercesByTextrub($text);
$total_results= count($list_ranking) + count($list_coloredComm) + count($list_commcartesvisites) + count($list_freeComm);
// dd($list_freeComm,$list_commcartesvisites,$list_coloredComm,$list_ranking);
$lignes = $this->rankingLignesRepository->findAll();
$photos = $this->rankingPhotoRepository->findAll();
$meta_title = $rubrique_name . " Atout Commerces antextRubriqueCodePostalnuaire des commerçants et artisans en Wallonie | Atout-Commerces.be";
$meta_description = "Liste complète des " . $rubrique_name . ". Atout Commerces est un annuaire des commerçants, artisans, professions libérales, et entrepreneurs. 100.000 professionnels référencés. Retrouvez tous les " . $rubrique_name . " en Wallonie.";
$linkNL= "nl/rubrique/" . $text .".html";
$linkFR="fr/rubrique/" . $text .".html";
if ($request->query->get('l')=="get")
{
return new Response($this->twig->render('Results_Search/rubrique.html.twig',
[
'list_ranking' => $list_ranking,
'list_ranking1' => $list_ranking1,
'list_ranking2' => $list_ranking2,
'list_ranking3' => $list_ranking3,
'list_commcartesvisites' => $list_commcartesvisites,
'list_coloredComm' => $list_coloredComm,
'list_freeComm' => $list_freeComm,
'lignes' => $lignes,
'photos' => $photos,
'idc' => null,
'idp' => null,
'rubrique_name' => $rubrique_name,
'ou' => null,
//'name'=>$rubrique_name,
'rubrique_slug' => $rubrique_slug,
'meta_title' => $meta_title,
'meta_description' => $meta_description,
'commune_nom' => null,
'total_results' => $total_results,
'province_obj' => $province_obj,
'textCommercial'=>false,
'communee'=>$communee,
'noindex'=>count($list_ranking1) + count($list_ranking2) + count($list_ranking3)>=20,
'linkNL' => $linkNL,
'linkFR' => $linkFR,
'noindex'=>count($list_ranking1) + count($list_ranking2) + count($list_ranking3)>=20
]));
}
if(count($list_ranking)<20 ){
return new Response($this->twig->render('Results_Search/rubrique.html.twig',
[
'list_ranking' => $list_ranking,
'list_ranking1' => $list_ranking1,
'list_ranking2' => $list_ranking2,
'list_ranking3' => $list_ranking3,
'list_commcartesvisites' => $list_commcartesvisites,
'list_coloredComm' => $list_coloredComm,
'list_freeComm' => $list_freeComm,
'lignes' => $lignes,
'photos' => $photos,
'idc' => null,
'idp' => null,
'rubrique_name' => $rubrique_name,
'ou' => null,
'rubrique_slug' => $rubrique_slug,
'meta_title' => $meta_title,
'meta_description' => $meta_description,
'commune_nom' => null,
'total_results' => $total_results,
'province_obj' => $province_obj,
'textCommercial'=> false,
'communee'=>$communee,
'linkNL' => $linkNL,
'linkFR' => $linkFR,
//'noindex'=>count($list_ranking)>=20
]));
}
if(count($list_ranking)>20 ){
return new Response($this->twig->render('Results_Search/newRubrique.html.twig',
[
'list_ranking' => $list_ranking,
'list_ranking1' => $list_ranking1,
'list_ranking2' => $list_ranking2,
'list_ranking3' => $list_ranking3,
'lignes' => $lignes,
'photos' => $photos,
'idc' => null,
'idp' => null,
'rubrique_name' => $rubrique_name,
'searchedText' => $text,
'ou' => null,
'rubrique_slug' => $rubrique_slug,
'meta_title' => $meta_title,
'meta_description' => $meta_description,
'commune_nom' => null,
'total_results' => $total_results,
'province_obj' => $province_obj,
'communee'=>$communee,
'textCommercial'=>true,
'linkNL' => $linkNL,
'linkFR' => $linkFR,
'textCommercial'=>true
]));
}
return new Response($this->twig->render('Results_Search/newRubrique.html.twig',
[
'list_ranking' => $list_ranking,
'list_ranking1' => $list_ranking1,
'list_ranking2' => $list_ranking2,
'list_ranking3' => $list_ranking3,
'lignes' => $lignes,
'photos' => $photos,
'idc' => null,
'idp' => null,
'rubrique_name' => $rubrique_name,
'searchedText' => $text,
'ou' => null,
//'name'=>$rubrique_name,
'rubrique_slug' => $rubrique_slug,
'meta_title' => $meta_title,
'meta_description' => $meta_description,
'commune_nom' => null,
'total_results' => $total_results,
'province_obj' => $province_obj,
'communee'=>$communee,
'textCommercial'=>false,
'linkNL' => $linkNL,
'linkFR' => $linkFR,
'textCommercial'=>false
]));
}
}
//text rubrique + code postal
/**
* @Route("/rubrique/{text_rubrique}/{codep}.html",name="text_rubrique_codep", requirements={"token"=".+"})
*/
public function textRubriqueCodePostal($text_rubrique,$codep){
$commune= is_numeric($codep) ? $this->communeRepository->findByCodePostal($codep) : $this->communeRepository->findByNomC1($codep);
$commune= $commune ? $commune: $this->communeRepository->findOneBySlug($codep);
$commune= $commune ? $commune: $this->communeRepository->findOneByEntite1($codep);
$province_obj = $commune ? null : $this->provinceRepository->findOneBySlug($codep);
if ( $province_obj) {
return $this->redirectToRoute('rub_text_prov_url',array('text_rubrique'=>$text_rubrique,'slug_province'=>$codep));
}
$commune_id= null;
$commune_name= null;
$slug= null;
if($commune != null) {
$commune_id= !is_array($commune) ? $commune->getId() : null;
$commune_name= !is_array($commune) ? $commune->getNom() : null;
$slug= !is_array($commune) ? $commune->getSlugNom() : null;
foreach ($commune as $c) {
$commune_id = $c->getId();
$commune_name = $c->getNom();
$slug = $c->getSlugNom();
$province_obj = $c->getIdProvince();
}
}
$name=$text_rubrique;
$list_ranking = $commune_id !=null ? $this->rankingRepository->findByTxtRubriqueCommune($text_rubrique,$commune_id):'' ;
$list_commcartesvisites =$commune_id !=null ? $this->CommercesRepository->findCartVisitCommercesByTxtRubriqueAndCommune($text_rubrique,$commune_id):'';
$list_coloredComm =$commune_id !=null ? $this->CommercesRepository->findColoredCommercesByTxtRubriqueAndCommune($text_rubrique,$commune_id):'';
$list_freeComm = $this->CommercesRepository->findFreeCommercesByTxtRubriqueAndCommune($text_rubrique,$commune_id);
$lignes= $this->rankingLignesRepository->findAll();
$photos= $this->rankingPhotoRepository->findAll();
$total_results= count($list_ranking) + count($list_coloredComm) + count($list_commcartesvisites) + count($list_freeComm);
$meta_title = $name." à ".$commune_name." . Atout Commerces annuaire des commerçants et artisans en Wallonie | Atout-Commerces.be";
$meta_description = "Liste complète des ".$name." de la commune de ".$commune_name." . Atout Commerces est un annuaire des commerçants, artisans, professions libérales, et entrepreneurs. 100.000 professionnels référencés. Retrouvez tous les ".$name." en Wallonie.";
$linkNL= "nl/rubrique/" . $text_rubrique . "/". $codep . ".html";
$linkFR="fr/rubrique/" . $text_rubrique . "/". $codep . ".html";
// dd($text_rubrique,$codep,$commune_id,$commune_name,$slug,$province_obj);
if (is_numeric($codep) and $commune == null){
return new Response($this->twig->render('Results_Search/critere_not_found.html.twig',
[
'critere'=>$codep,
'champs_recherche' => 'Code Postal'
]));
}else {
return new Response($this->twig->render('Results_Search/rubrique.html.twig',
[
'list_ranking' => $list_ranking,
'list_commcartesvisites' => $list_commcartesvisites,
'list_coloredComm' => $list_coloredComm,
'list_freeComm' => $list_freeComm,
'lignes' => $lignes,
'idc' => $commune_id,
'photos' => $photos,
'ou' => $commune_name,
'name' => $commune_name,
'idp' => null,
'rubrique_name' => $name,
'meta_title' => $meta_title,
'meta_description' => $meta_description,
'commune_nom' => $commune_name,
'slug' => $slug,
'province_obj' => $province_obj,
'total_results' => $total_results,
'linkNL' => $linkNL,
'linkFR' => $linkFR,
'total_results' => $total_results
]));
}
}
///// id rubrique + text commune
/**
* @Route("/{id_rubrique}+{text_commune}.html",name="rub_text_comm")
*/
public function findByIdrubStringcomm($id_rubrique, $text_commune): Response
{
$rubrique= $this->rubriqueRepository->findOneBySlug($id_rubrique);
$commune= $this->communeRepository->findByEntite($text_commune);
// $commune= $commune ? $commune : $this->communeRepository->findByNomC($text_commune);
$commune= $commune ? $commune : $this->communeRepository->findByNomC1($text_commune);
$province_obj = $commune ? null : $this->provinceRepository->findOneBySlug($text_commune);
if ( $province_obj) {
$slug_province= $province_obj->getUrl();
$slug_rubrique= $rubrique->getSlugNom();
return $this->redirectToRoute('rubrique_province',array('slug_rubrique'=>$slug_rubrique,'slug_province'=>$slug_province));
}
$commune_id=null;
$commune_name=null;
$commune_slug=null;
$province_obj=null;
foreach ( $commune as $c){
$commune_id=$c->getId();
$commune_name=$c->getNom();
$commune_slug=$c->getSlugNom();
$province_obj=$c->getIdProvince();
}
$rubrique_id=!empty($rubrique) ? $rubrique->getId():null;
$name=!empty($rubrique) ? $rubrique->getRubrique():null;
$slug=!empty($rubrique) ? $rubrique->getSlugNom():null;
$list_ranking =$commune_id !=null && $rubrique_id !=null ? $this->rankingRepository->findByRubriqueCommune($rubrique_id,$commune_id) :'';
$list_commcartesvisites =$commune_id !=null && $rubrique_id !=null ? $this->CommercesRepository->findCartVisitCommercesByRubriqueAndCommune($rubrique_id,$commune_id):'';
$list_coloredComm =$commune_id !=null && $rubrique_id !=null ? $this->CommercesRepository->findColoredCommercesByRubriqueAndCommune($rubrique_id,$commune_id):'';
$list_freeComm =$commune_id !=null && $rubrique_id !=null ? $this->CommercesRepository->findFreeCommercesByRubriqueAndCommune($rubrique_id,$commune_id):'';
$lignes= $this->rankingLignesRepository->findAll();
$photos= $this->rankingPhotoRepository->findAll();
$total_results= count($list_ranking) + count($list_coloredComm) + count($list_commcartesvisites) + count($list_freeComm);
$linkFR= "fr/" . $id_rubrique . "+". $text_commune . ".html";
$slugRubNL=!empty($rubrique) ?$rubrique->getRubriqueNL() : null;
$linkNL="nl/" . $slugRubNL . "+". $text_commune . ".html";
return new Response($this->twig->render('Results_Search/rubrique.html.twig',
[
'list_ranking'=>$list_ranking,
'list_commcartesvisites'=>$list_commcartesvisites,
'list_coloredComm'=>$list_coloredComm,
'list_freeComm'=>$list_freeComm,
'lignes'=>$lignes,
'photos'=>$photos,
'ou'=>$commune_name,
'idc'=>$commune_id,
'idp'=>null,
'rubrique_name'=>$name,
'rubrique_slug'=>$slug,
'name'=>$commune_name,
'commune_nom'=>$commune_name,
'province_obj'=>$province_obj,
'total_results'=>$total_results,
'slug'=>$commune_slug,
'linkNL' => $linkNL,
'linkFR' => $linkFR,
'slug'=>$commune_slug
]));
}
///// text rubrique + text commune
/**
* @Route("/quoi+{text_rubrique}/ou+{text_commune}.html",name="str_rub_str_comm")
*/
public function findByTextrubTextcomm($text_rubrique, $text_commune): Response
{
$name=$text_rubrique;
$slug=$text_rubrique;
$commune= $this->communeRepository->findByNomC1($text_commune);
$commune= $commune ? $commune : $this->communeRepository->findOneByEntite($text_commune);
$commune= $commune ? $commune : $this->communeRepository->findOneByEntite1($text_commune);
$province_obj = $commune ? null : $this->provinceRepository->findOneBySlug($text_commune);
$province_obj = $province_obj ? null : $this->provinceRepository->findOneNom($text_commune);
if ( $province_obj) {
if( is_array($province_obj)){
foreach ($province_obj as $p){
$slug_province = $p->getUrl();
}
}
else{ $slug_province = $province_obj->getUrl();}
return $this->redirectToRoute('rub_text_prov_url',array('text_rubrique'=>$text_rubrique,'slug_province'=>$slug_province));
}
//dd($commune,$province_obj);
$commune_id=null;
$commune_name=null;
$commune_slug=null;
foreach ( $commune as $c){
$commune_id=$c->getId();
$commune_name=$c->getNom();
$commune_slug=$c->getSlugNom();
$province_obj=$c->getIdProvince();
}
$list_ranking =$commune_id !=null ? $this->rankingRepository->findByTextRubriqueTextComm($text_rubrique,$commune_name) :'';
$list_commcartesvisites =$commune_id !=null? $this->CommercesRepository->findCartVisitCommercesByTextRubriqueTextCommune($text_rubrique,$commune_id):'';
$list_coloredComm =$commune_id !=null ? $this->CommercesRepository->findColoredCommercesByTextRubriqueTextCommune($text_rubrique,$commune_id):'';
$list_freeComm =$commune_id !=null ? $this->CommercesRepository->findFreeCommercesByTextRubriqueTextCommune($text_rubrique,$commune_id):'';
$lignes= $this->rankingLignesRepository->findAll();
$photos= $this->rankingPhotoRepository->findAll();
// $total_results= count($list_ranking) + count($list_coloredComm) + count($list_commcartesvisites) + count($list_freeComm);
$countR= is_array($list_ranking) ? count($list_ranking) : null;
$countCC= is_array($list_coloredComm) ? count($list_coloredComm) : null;
$countCV= is_array($list_commcartesvisites) ? count($list_commcartesvisites) : null;
$countFR= is_array($list_freeComm) ? count($list_freeComm) : null;
$total_results=$countR + $countCC + $countCV + $countFR ;
$meta_title = $name." à ".$commune_name." . Atout Commerces annuaire des commerçants et artisans en Wallonie | Atout-Commerces.be";
$meta_description = "Liste complète des ".$name." de la commune de ".$commune_name." . Atout Commerces est un annuaire des commerçants, artisans, professions libérales, et entrepreneurs. 100.000 professionnels référencés. Retrouvez tous les ".$name." en Wallonie.";
$linkNL= "nl/quoi+" . $text_rubrique . "/ou+".$text_commune.".html";
$linkFR= "fr/quoi+" . $text_rubrique . "/ou+".$text_commune.".html";
// $total_results= count($list_ranking) + count($list_coloredComm) + count($list_commcartesvisites) + count($list_freeComm);
$meta_title = $name." à ".$commune_name." . Atout Commerces annuaire des commerçants et artisans en Wallonie | Atout-Commerces.be";
$meta_description = "Liste complète des ".$name." de la commune de ".$commune_name." . Atout Commerces est un annuaire des commerçants, artisans, professions libérales, et entrepreneurs. 100.000 professionnels référencés. Retrouvez tous les ".$name." en Wallonie.";
return new Response($this->twig->render('Results_Search/rubrique.html.twig',
[
'list_ranking'=>$list_ranking,
'list_commcartesvisites'=>$list_commcartesvisites,
'list_coloredComm'=>$list_coloredComm,
'list_freeComm'=>$list_freeComm,
'lignes'=>$lignes,
'photos'=>$photos,
'ou'=>$text_commune,
'idc'=>$commune_id,
'idp'=>null,
'rubrique_name'=>$name,
'rubrique_slug'=>$slug,
'name'=>$text_commune,
'commune_nom'=>$commune_name,
'province_obj'=>$province_obj,
'slug'=>$text_commune,
'meta_title' => $meta_title,
'meta_description' => $meta_description,
'total_results' => $total_results,
'linkNL' => $linkNL,
'linkFR' => $linkFR,
]));
}
//ranking details
/**
* @Route("/{nom_ranking}-{seo_ranking}_k_{id_ranking}.html",name="ranking_detail", defaults={"nom_ranking": "nom", "seo_ranking": "seo"} ,requirements={"token"=".+", "nom_ranking"="[^+]+", "seo_ranking"="[^+]+" })
*/
public function rankingDetails(Request $request,$id_ranking){
$commune=$request->query->get("c");
$province=$request->query->get("p");
$rubriqueField=$request->query->get("r");
$communeObj=null;
$provinceObj=null;
$communeSlug=null;
$communeId=null;
$provinceUrl=null;
$provinceId=null;
$rubriqueSlug=null;
$rubriqueId=null;
$rubriqueNom=null;
if($commune != "null"){
$idc=(int)$commune;
$communeField=$idc? $this->communeRepository->find($idc):null;
$communeObj=$communeField;
$communeSlug=$communeField?$communeField->getSlugNom():null;
$communeId=$communeField?$communeField->getId():null;
}
// dd($province);
if($province != "null"){
$idp=(int)$province;
$provinceField= $idp?$this->provinceRepository->find($idp):null;
$provinceObj=$provinceField;
$provinceUrl=$provinceField?$provinceField->getUrl():null;
$provinceId=$provinceField? $provinceField->getId():null;
}
if($rubriqueField != "null"){
$rub= $this->rubriqueRepository->findOneBySlug($rubriqueField);
$rub= $rub? $rub :$this->rubriqueRepository->findOneBy(array("rubrique"=>$rubriqueField));
$rubriqueField= $rub? $rub : null;
$rubriqueSlug=$rub? $rub->getSlugNom(): null;
$rubriqueId=$rub? $rub->getId(): null;
$rubriqueNom=$rub? $rub->getRubrique(): null;
}
$ranking = $this->rankingRepository->find($id_ranking);
if($ranking){
// Vérification si 'afficher' est à 0
if ($ranking->getAfficher() === 0) {
// Redirection vers la page 404 si 'afficher' est 0
// return new Response($this->twig->render('Results_Search/critere_not_found.html.twig'), 404);
// Récupérer la première rubrique associée au ranking
$rubriques = $ranking->getRubrique();
if (!empty($rubriques)) {
$rubrique = $rubriques[0]; // On prend la première rubrique associée
$rubriqueSlug = $rubrique->getSlugNom(); // Récupération du slug de la rubrique
// Redirection vers la page de la rubrique
return $this->redirectToRoute('rubrique_ranking', ['slug' => $rubriqueSlug]);
} else {
// Gérer le cas où il n'y a pas de rubrique associée
return new Response($this->twig->render('bundles/TwigBundle/Exception/error404.html.twig'));
}
}
$rubriques=$ranking->getRubrique();
$rubrique_id=0;
foreach ($rubriques as $r){
$rubrique_id= $r->getId();
break;
}
$id= $rubrique_id;
$rubrique= $this->rubriqueRepository->findByTextId($id);
$lignes= $this->rankingLignesRepository->findByRankingId($id_ranking);
$photos= $this->rankingPhotoRepository->findBy(array('ranking'=>$id_ranking));
return new Response($this->twig->render('Results_Search/ranking_details.html.twig',
[
'ranking'=>!empty($ranking) ? $ranking: '',
'lignes'=>$lignes,
'photos'=>$photos,
'commune'=>!empty($nomC)? $nomC : '',
'idc'=>!empty($idC)? $idC : '',
'slugc'=>!empty($slugC)? $slugC : '',
'province_nom'=>!empty($nomp)? $nomp : '',
'province_slug'=>!empty($slugp)? $slugp : '',
'province_id'=>!empty($idP)? $idP : null,
'categorie'=>!empty($rubrique)? $rubrique : null,
'rubriqueField'=>$rubriqueField,
'communeObj'=>$communeObj,
'provinceObj'=>$provinceObj,
'communeSlug'=>$communeSlug,
'communeId'=>$communeId,
'provinceUrl'=>$provinceUrl,
'rubrique_Slug'=>$rubriqueSlug,
'rubrique_Nom'=>$rubriqueNom,
'rubrique_id'=>$rubriqueId,
'provinceId'=>$provinceId
]));
}else{
return new Response($this->twig->render('bundles/TwigBundle/Exception/error404.html.twig'));
}
}
/**
* @Route("/ranking_detail.html",name="ranking_bo",requirements={"token"=".+"})
* @IsGranted("ROLE_ADMIN")
*/
public function rankingDetailsFromBO(Request $request){
$id_ranking= $request->attributes->get("0");
$ranking = $this->rankingRepository->find($id_ranking);
$commune=$this->communeRepository->findByIdRanking($id_ranking);
//
$rubriques=$ranking->getRubrique();
$rubrique_id=0;
foreach ($rubriques as $r){
$rubrique_id= $r->getId();
break;
}
$id= $rubrique_id;
$rubrique= $this->rubriqueRepository->findByTextId($id);
$lignes= $this->rankingLignesRepository->findByRankingId($id_ranking);
$photos= $this->rankingPhotoRepository->findBy(array('ranking'=>$id_ranking));
$nomC='';
$nomp='';
foreach ($commune as $c){
$nomC = $c->getNom();
$slugC = $c->getSlugNom();
$idC = $c->getId();
$nomp = $c->getIdProvince()->getNom();
$slugp = $c->getIdProvince()->getUrl();
$idP= $c->getIdProvince()->getId();
}
return new Response($this->twig->render('Admin/ranking_details.html.twig',
[
'ranking'=>!empty($ranking) ? $ranking: '',
'lignes'=>$lignes,
'photos'=>$photos,
'commune'=>!empty($nomC)? $nomC : '',
'idc'=>!empty($idC)? $idC : '',
'slugc'=>!empty($slugC)? $slugC : '',
'province_nom'=>!empty($nomp)? $nomp : '',
'province_slug'=>!empty($slugp)? $slugp : '',
'province_id'=>!empty($idP)? $idP : null,
'categorie'=>!empty($rubrique)? $rubrique : null
]));
}
public function getMaxRubCom($id_comm): Response
{
$id = (int) $id_comm;
if ($id <= 0) {
return new Response(
$this->twig->render('Results_Search/Counting/commercesRubByCom.html.twig', [
'commerces' => [],
'commune' => null,
])
);
}
$commune = $this->communeRepository->find($id);
if (!$commune) {
return new Response(
$this->twig->render('Results_Search/Counting/commercesRubByCom.html.twig', [
'commerces' => [],
'commune' => null,
])
);
}
$commerces = $this->CommercesRepository->countCommByRubCom($id);
return new Response(
$this->twig->render('Results_Search/Counting/commercesRubByCom.html.twig', [
'commerces' => $commerces,
'commune' => $commune,
])
);
}
private function getProvinceCommuneMapping(): array
{
return [
'Province du Brabant-Wallon' => [
"Braine l'Alleud & entités",
"Chaumont-Gistoux & entités",
"Genappe & entités",
"Grez-Doiceau, Beauvechain",
"Jodoigne, Incourt & entités",
"Lasne, La Hulpe & entités",
"Nivelles & entités",
"Orp-Jauche, Hélécine & entités",
"Ottignies, Louvain-la-Neuve",
"Perwez, Ramillies & entités",
"Rixensart & entités",
"Villers-la-ville, Court-Saint-Etienne & entités",
"Walhain, Chastre, Mont-Saint-Guibert & entités",
"Waterloo",
"Wavre & entités"
],
'Province du Hainaut' => [
"Ath & entités",
"Beaumont, Cerfontaine, Froidchapelle, Sivry-Rance & entités",
"Beloeil & entités",
"Binche & entités",
"Braine-le-Comte & entités",
"Celles, Mont-de-l'Enclus, Frasnes-lez-Anvaing & entités",
"Charleroi (Ville)",
"Châtelet & entités",
"Chièvres, Brugelette & entités",
"Courcelles & entités",
"Ecaussinnes, Seneffe, Le Roeulx & entités",
"Erquelinnes, Merbes-le-Château",
"Estaimpuis, Pecq & entités",
"Fleurus & entités",
"Frameries, Quévy & entités",
"Gerpinnes & entités",
"La Louvière (centre), Haine-St-Paul, Haine-St-Pierre",
"Leuze-en-Hainaut & entités",
"Manage & entités",
"Mons (centre-ville)",
"Entités Mons (sauf Ghlin & Jemappes)",
"Peruwelz & entités",
"Pont-à-Celles, Les Bons Villers & entités",
"Saint-Ghislain & entités",
"Soignies & entités",
"Tournai (centre-ville)"
],
'Province de Liège' => [
"Ans & entités", "Anthisnes, Ferrières, Hamoir, Comblain-au-Pont & entités", "Aubel, Herve, Thimister-Clermont et entités",
"Awans, Crisnée, Oreye & entités", "Bassenge & entités", "Beyne-Heusay, Fléron & entités", "Chaudfontaine & entités, Chênée",
"Esneux, Tilff & entités, Boncelles", "Hannut, Lincent & entités", "Héron, Wanze & entités", "Herstal (Centre), Vottem",
"Herve & entités", "Huy, Amay, Villers-le-Bouillet & entités", "Limbourg, Baelen & entités", "Malmedy, Stavelot & entités",
"Neupré, Nandrin & entités", "Ouffet, Tinlot, Clavier, Modave & entités", "Oupeye, Vivegnis, Haccourt",
"Pepinster, Theux & entités", "Soumagne, Olne & entités", "Spa, Jalhay, Sart-lez-Spa",
"Sprimont, Aywaille & entités", "Verviers (centre-ville), Heusy", "Visé, Dalhem, Blegny & entités", "Waremme, Berloz, Remicourt & entités",
"Wasseiges, Burdinne, Braives & entités", "Welkenraedt, Henri-Chapelle"
],
'Province du Luxembourg' => [
"Arlon & entités",
"Aubange & entités",
"Bastogne, Houffalize",
"Bertrix, Chiny, Herbeumont & entités",
"Bouillon, Paliseul & entités",
"Habay, Etalle & entités",
"Libramont, Saint-Hubert & entités",
"Marche-en-Famenne, La Roche-en-Ardenne, Rendeux, Hotton & entités",
"Martelange, Attert, Léglise, Fauvillers & entités",
"Messancy, Musson, Saint-Léger & entités",
"Vielsalm, Gouvy, Manhay, Lierneux & entités",
"Virton, Meix-devant-Virton, Rouvroy & entités"
],
'Province de Namur' => [
"Andenne & entités",
"Beauraing, Wellin, Tellin, Daverdisse & entités",
"Couvin, Chimay, Momignies & entités",
"Ciney & entités",
"Dinant, Houyet & entités",
"Eghezée & entités",
"Fernelmont & entités",
"Floreffe & entités",
"Fosses-la-Ville & entités",
"Gedinne, Bièvre, Vresse-sur-Semois & entités",
"Gembloux & entités",
"Hamois, Assesse & entités",
"Jambes & Saint-Servais",
"Jemeppe-sur-Sambre & entités",
"La Bruyère & entités",
"Mettet, Florennes & entités",
"Ohey, Gesves & entités",
"Philippeville, Hastière, Doische, Viroinval & entités",
"Profondeville & entités",
"Rochefort & entités",
"Sambreville & entités",
"Sombreffe",
"Somme-Leuze, Havelange & entités",
"Walcourt & entités"
]
];
}
}