<?php
namespace App\Controller\FrontEnd;
use App\Entity\Menu;
use App\Entity\Forms;
use App\Entity\Contact;
use App\Entity\Country;
use App\Entity\Language;
use App\Entity\Secteurs;
use App\Entity\FormsData;
use App\Entity\GroupBloc;
use App\Entity\ListeMenu;
use App\Entity\FormsFields;
use App\Entity\ParamContact;
use App\Entity\ParametreRef;
use App\Entity\ThemeOptions;
use App\Entity\ParametreSite;
use App\Entity\ProduitOption;
use App\Entity\ReseauSociaux;
use App\Entity\TelephonesClick;
use App\Entity\TextParametrable;
use App\Service\NestedTreeStructure;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\TextParametrableTranslation;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class FeatureController extends AbstractController
{
private $theme;
private $client;
private $projectDirr;
public function __construct(string $theme,HttpClientInterface $client,string $projectDirr)
{
$this->theme = $theme;
$this->client = $client;
$this->projectDirr = $projectDirr;
}
/**
* @Route("lang/{language}", name="setlocale_langauge")
*/
public function setLocaleLangAction(Request $request,$language = null)
{
if($language != null)
{
$request->getSession()->set('_locale', $language);
}
return $this->redirectToRoute('index_page_home',['_locale'=> $language]);
}
/**
* @Route("/track-phone-click", methods={"POST"}, name="track_phone_click", condition="request.isXmlHttpRequest()")
*/
public function trackPhoneClick(Request $request,EntityManagerInterface $em)
{
if ($request->isXmlHttpRequest()) {
$_locale = $request->getLocale();
$parametre = $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy([],['id'=> 'ASC']);
if($parametre){
$nb_click = $parametre->getNbClickTel() != null ?$parametre->getNbClickTel():'0';
$parametre->setNbClickTel($nb_click + 1);
$em->flush();
}
return new JsonResponse(['message'=> 'Phone click saved successfully']);
}
}
public function renderMenu(Request $request,NestedTreeStructure $buildTree,$className= ''){
$_locale = $request->getLocale();
$data_menu_right = [];
$ListMenu_rigth = [];
$data_menu_left = [];
$ListMenu_left = [];
$theme_option = $this->getDoctrine()->getRepository(ThemeOptions::class)->findOneBy(['theme'=> $this->theme]);
$languages = $this->getDoctrine()->getRepository(Language::class)->findActifLang();
$Menu_right = $this->getDoctrine()->getRepository(ListeMenu::class)->findOneBy(['type'=>'Header-right','IdSite'=> '1']);
$Menu_left = $this->getDoctrine()->getRepository(ListeMenu::class)->findOneBy(['type'=>'Header-left','IdSite'=> '1']);
$contacts = $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
$contacts_noms = [];
if($contacts){
foreach ($contacts as $contact) {
$contacts_noms[] = ['id'=> $contact->getId(),
'nomContact'=> $contact->translate($_locale)->getNomContact(),
];
}
}
$socials = $this->getDoctrine()->getRepository(ReseauSociaux::class)->findAll();
if($Menu_right){
$ListMenu_rigth = $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($Menu_right->getId());
$data_menu_right = $buildTree->buildMenu($ListMenu_rigth);
}
if($Menu_left){
$ListMenu_left = $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($Menu_left->getId());
$data_menu_left = $buildTree->buildMenu($ListMenu_left);
}
return $this->render('theme/'.$this->theme.'/partials/_header.html.twig',[
'menu_right'=> $data_menu_right,
'menu_left'=> $data_menu_left,
'languages'=> $languages,
'className'=> $className,
'theme_option'=> $theme_option,
'contacts'=> $contacts,
'contactsInfos'=> $contacts_noms,
'socials'=> $socials,
'menuDetails' => $ListMenu_rigth,
'locale'=> $_locale
]);
}
public function renderFooter(Request $request,$TypeMenu,NestedTreeStructure $buildTree){
$_locale = $request->getLocale();
$menusFooter = null;
$menusFooterBas = null;
$contacts = $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
$parametre = $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy([],['id'=> 'ASC']);
$data_menu_footer = $this->getDoctrine()->getRepository(ListeMenu::class)->findOneBy(['type'=> 'Footer']);
if ($data_menu_footer) {
$menu_items = $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($data_menu_footer->getId());
$menusFooterBas = $buildTree->buildMenu($menu_items);
};
$data_menu_footer_bas = $this->getDoctrine()->getRepository(ListeMenu::class)->findOneBy(['type'=> 'Menu-Footer']);
if ($data_menu_footer_bas) {
$menu_items = $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($data_menu_footer_bas->getId());
$menusFooter = $buildTree->buildMenu($menu_items);
}
$socials = $this->getDoctrine()->getRepository(ReseauSociaux::class)->findAll();
return $this->render('theme/'.$this->theme.'/partials/_footer.html.twig',[
'contacts'=> $contacts,
'parametre'=> $parametre,
'menusFooter'=> $menusFooter,
'menusFooterBas'=> $menusFooterBas,
'socials'=> $socials
]);
}
public function displayContactsList(){
$param_contact = $this->getDoctrine()->getRepository(ParamContact::class)->findOneBy(['id'=>1]);
$content_bloc = $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
return $this->render('theme/'.$this->theme.'/component-blocks/contacts-listing-block.html.twig',[
'content_bloc'=> $content_bloc,
'param_contact'=> $param_contact,
]);
}
public function displayContactHoursPage(){
$content_bloc = $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
return $this->render('theme/'.$this->theme.'/component-blocks/contact-hours-block.html.twig',[
'content_bloc'=> $content_bloc,
]);
}
public function displayContactMap(){
$param_contact = $this->getDoctrine()->getRepository(ParamContact::class)->findOneBy(['id'=>1]);
$contacts = $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
return $this->render('theme/'.$this->theme.'/component-blocks/contact-map-block.html.twig',[
'contacts'=> $contacts,
'param_contact'=> $param_contact,
]);
}
public function displayOpenStreetMapWithContacts(){
$param_contact = $this->getDoctrine()->getRepository(ParamContact::class)->findOneBy(['id'=>1]);
$contacts = $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
return $this->render('theme/'.$this->theme.'/component-blocks/osm-map-block.html.twig',[
'contacts'=> $contacts,
'param_contact'=> $param_contact,
]);
}
}