<?php
namespace App\Controller\Front;
use App\Entity\Menu;
use App\Entity\Country;
use App\Entity\Language;
use App\Entity\Secteurs;
use App\Entity\GroupBloc;
use App\Entity\ListeMenu;
use App\Service\BuildTree;
use App\Entity\ParametreRef;
use App\Entity\ThemeOptions;
use App\Entity\ParametreSite;
use App\Entity\ProduitOption;
use App\Entity\ReseauSociaux;
use App\Entity\Contact;
use App\Entity\Forms;
use App\Entity\FormsData;
use App\Entity\FormsFields;
use App\Entity\ParamContact;
use App\Entity\TelephonesClick;
use App\Entity\TextParametrable;
use App\Entity\TextParametrableTranslation;
use App\Service\RenderDefaultBloc;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
class FunctionController 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;
}
public function renderMenu(Request $request,BuildTree $buildTree,$className){
$_locale = $request->getLocale();
$data_menu_right = [];
$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']);
$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(),
];
}
}
$social = $this->getDoctrine()->getRepository(ReseauSociaux::class)->findBy(['site'=> '1']);
if($Menu_right){
$ListMenu_rigth = $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($Menu_right->getId());
$data_menu_right = $buildTree->buildMenu($ListMenu_rigth);
}
return $this->render('front/'.$this->theme.'/partials/header/header.html.twig',[
'menu_right'=> $data_menu_right,
'languages'=> $languages,
'className'=> $className,
'theme_option'=> $theme_option,
'contacts'=> $contacts,
'contactsInfos'=> $contacts_noms,
'social'=> $social,
'menuDetails' => $ListMenu_rigth,
'locale'=>$_locale
]);
}
public function renderFooter(Request $request,$TypeMenu,BuildTree $buildTree){
$_locale = $request->getLocale();
$data_menu = [];
$data_menu_footer = [];
$languages = $this->getDoctrine()->getRepository(Language::class)->findActifLang();
$theme_option = $this->getDoctrine()->getRepository(ThemeOptions::class)->findOneBy(['theme'=> $this->theme]);
$contacts = $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
$image_map = $this->getDoctrine()->getRepository(ParamContact::class)->find(1)->getImageMap();
$contacts_noms = [];
if($contacts){
foreach ($contacts as $contact) {
$contacts_noms[] = ['id'=> $contact->getId(),
'nomContact'=> $contact->translate($_locale)->getNomContact(),
];
}
}
$Menu = $this->getDoctrine()->getRepository(ListeMenu::class)->findOneBy(['type'=>$TypeMenu,'IdSite'=> '1']);
$social = $this->getDoctrine()->getRepository(ReseauSociaux::class)->findBy(['site'=> '1']);
if($Menu){
$ListMenu = $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($Menu->getId());
$data_menu = $buildTree->buildMenu($ListMenu);
}
$Menu_footer_top = $this->getDoctrine()->getRepository(ListeMenu::class)->findOneBy(['type'=> 'Menu-Footer','IdSite'=> '1']);
if ($Menu_footer_top) {
$ListMenuFooter = $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($Menu_footer_top->getId());
$data_menu_footer = $buildTree->buildMenu($ListMenuFooter);
}
/* $form = $this->getDoctrine()->getRepository(Forms::class)->findOneBy(['identifier' => 'form-footer']);
$formfields = $this->getDoctrine()->getRepository(FormsFields::class)->findOneBy(['form' => $form->getId()]); */
$parametre = $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy(['Site'=>'1']);
$secteurs = $this->getDoctrine()->getRepository(Secteurs::class)->findBy(['actif'=>true],['position'=>'ASC']);
$parametreRef = $this->getDoctrine()->getRepository(ParametreRef::class)->findOneBy(['alias'=> 'param_generale']);
/* $formsfieldsData = [];
if($formfields){
$formsfieldsData = unserialize($formfields->getData());
} */
return $this->render('front/'.$this->theme.'/partials/footer/footer.html.twig',[
'menus'=> $data_menu,
'social'=> $social,
'parametreRef'=> $parametreRef,
'secteurs'=> $secteurs,
'languages'=> $languages,
'parametre'=> $parametre,
'theme_option'=> $theme_option,
'contacts'=> $contacts,
'contactsInfos'=> $contacts_noms,
'data_menu_footer'=> $data_menu_footer,
'image_map' => $image_map,
/* 'form' => $form,
'formfields' => $formsfieldsData, */
]);
}
public function renderDefaultBloc(RenderDefaultBloc $defaultBloc){
$default_bloc = $defaultBloc->RenderBloc();
return $this->render('front/'.$this->theme.'/bloc/render_bloc_default.html.twig',[
'default_bloc'=> $default_bloc,
]);
}
// public function renderDefaultBloc($alias,RenderDefaultBloc $defaultBloc){
// $data_default_bloc = null;
// $default_bloc = $this->getDoctrine()->getRepository(GroupBloc::class)->findOneBy(['alias'=>$alias]);
// if($default_bloc){
// $data_default_bloc = $defaultBloc->RenderBloc($default_bloc);
// }
// return $this->render('front/'.$this->theme.'/bloc/render_bloc_default.html.twig',[
// 'data_default_bloc'=> $data_default_bloc,
// ]);
// }
public function renderTextParametrable($id){
$content_bloc = $this->getDoctrine()->getRepository(TextParametrableTranslation::class)->findOneBy(['id'=>$id]);
return $this->render('front/'.$this->theme.'/bloc/texte-parametrable.html.twig',[
'content_bloc'=> $content_bloc,
]);
}
public function renderTemplateParametrable($id){
$content_bloc = $this->getDoctrine()->getRepository(TextParametrableTranslation::class)->findOneBy(['id'=>$id]);
return $this->render('front/'.$this->theme.'/bloc/template-parametrable.html.twig',[
'content_bloc'=> $content_bloc,
]);
}
public function renderTextCopyright($id){
$content_bloc = $this->getDoctrine()->getRepository(TextParametrableTranslation::class)->findOneBy(['id'=>$id]);
return $this->render('front/'.$this->theme.'/bloc/texte-copyright.html.twig',[
'content_bloc'=> $content_bloc,
]);
}
public function renderTitreMenuFooter($id){
$content_bloc = $this->getDoctrine()->getRepository(TextParametrableTranslation::class)->findOneBy(['id'=>$id]);
return $this->render('front/'.$this->theme.'/bloc/titre-menu-footer.html.twig',[
'content_bloc'=> $content_bloc,
]);
}
public function renderContacts(){
$param_contact = $this->getDoctrine()->getRepository(ParamContact::class)->findOneBy(['id'=>1]);
$content_bloc = $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
return $this->render('front/'.$this->theme.'/bloc/liste-contacts.html.twig',[
'content_bloc'=> $content_bloc,
'param_contact'=> $param_contact,
]);
}
public function renderHorairesPageContact(){
$content_bloc = $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
return $this->render('front/'.$this->theme.'/bloc/horaires-contacts.html.twig',[
'content_bloc'=> $content_bloc,
]);
}
public function renderMapContact(){
$param_contact = $this->getDoctrine()->getRepository(ParamContact::class)->findOneBy(['id'=>1]);
$contacts = $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
return $this->render('front/'.$this->theme.'/bloc/map-contact.html.twig',[
'contacts'=> $contacts,
'param_contact'=> $param_contact,
]);
}
public function renderHeaderLp(Request $request,BuildTree $buildTree){
$_locale = $request->getLocale();
$parametre = $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy([],['id'=> 'ASC']);
return $this->render('front/'.$this->theme.'/landing-page/header.html.twig',[
'parametre'=> $parametre,
]);
}
public function renderFooterLp(Request $request,$TypeMenu,BuildTree $buildTree){
$_locale = $request->getLocale();
$data_menu = [];
$data_menu_footer = [];
$languages = $this->getDoctrine()->getRepository(Language::class)->findActifLang();
$theme_option = $this->getDoctrine()->getRepository(ThemeOptions::class)->findOneBy(['theme'=> $this->theme]);
$contacts = $this->getDoctrine()->getRepository(Contact::class)->getActifContacts();
$image_map = $this->getDoctrine()->getRepository(ParamContact::class)->find(1)->getImageMap();
if($contacts){
foreach ($contacts as $contact) {
$contacts_noms[] = ['id'=> $contact->getId(),
'nomContact'=> $contact->translate($_locale)->getNomContact(),
];
}
}
$Menu = $this->getDoctrine()->getRepository(ListeMenu::class)->findOneBy(['type'=>$TypeMenu,'IdSite'=> '1']);
$social = $this->getDoctrine()->getRepository(ReseauSociaux::class)->findBy(['site'=> '1']);
if($Menu){
$ListMenu = $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($Menu->getId());
$data_menu = $buildTree->buildMenu($ListMenu);
}
$Menu_footer_top = $this->getDoctrine()->getRepository(ListeMenu::class)->findOneBy(['type'=> 'Menu-Footer','IdSite'=> '1']);
if ($Menu_footer_top) {
$ListMenuFooter = $this->getDoctrine()->getRepository(Menu::class)->findMenuActif($Menu_footer_top->getId());
$data_menu_footer = $buildTree->buildMenu($ListMenuFooter);
}
/* $form = $this->getDoctrine()->getRepository(Forms::class)->findOneBy(['identifier' => 'form-footer']);
$formfields = $this->getDoctrine()->getRepository(FormsFields::class)->findOneBy(['form' => $form->getId()]); */
$parametre = $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy(['Site'=>'1']);
$secteurs = $this->getDoctrine()->getRepository(Secteurs::class)->findBy(['actif'=>true],['position'=>'ASC']);
$parametreRef = $this->getDoctrine()->getRepository(ParametreRef::class)->findOneBy(['alias'=> 'param_generale']);
/* $formsfieldsData = [];
if($formfields){
$formsfieldsData = unserialize($formfields->getData());
} */
return $this->render('front/'.$this->theme.'/landing-page/footer.html.twig',[
'menus'=> $data_menu,
'social'=> $social,
'parametreRef'=> $parametreRef,
'secteurs'=> $secteurs,
'languages'=> $languages,
'parametre'=> $parametre,
'theme_option'=> $theme_option,
'contacts'=> $contacts,
'contactsInfos'=> $contacts_noms,
'data_menu_footer'=> $data_menu_footer,
'image_map' => $image_map,
/* 'form' => $form,
'formfields' => $formsfieldsData, */
]);
}
/**
* @Route("/clic-telephone", name="click_telephone")
*/
public function EnregistrerClickTel(Request $request)
{
$numTel = $request->request->get('phoneNumber');
$clientIp = $request->getClientIp();
$dateClick = new \DateTime();
$checkClickTelByIpDate = $this->getDoctrine()->getRepository(TelephonesClick::class)->findBy(['ip'=>$clientIp,'telephone'=>$numTel]);
$clickByIpAfterTime = true;
if($checkClickTelByIpDate){
foreach ($checkClickTelByIpDate as $element) {
if($dateClick->diff($element->getDate())->h <= 24){
$clickByIpAfterTime = false;
return new JsonResponse('Veillez essayer après une durée');
}
}
}
if($clickByIpAfterTime){
$clickTel = new TelephonesClick();
$em = $this->getDoctrine()->getManager();
$clickTel->setIp($clientIp);
$clickTel->setDate($dateClick);
$clickTel->setTelephone($numTel);
$em->persist($clickTel);
$em->flush();
}
return new JsonResponse('Click enregistré');
}
}