<?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\CategoriesProduct;
use App\Entity\Contact;
use App\Entity\ParamContact;
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;
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();
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,
]);
}
public function renderFooter(Request $request,$TypeMenu,BuildTree $buildTree){
$_locale = $request->getLocale();
$data_menu = [];
$categories = $this->getDoctrine()->getRepository(CategoriesProduct::class)->findBy([],['position'=>'ASC']);
$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();
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);
}
$parametre = $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy(['Site'=>'1']);
$parametreRef = $this->getDoctrine()->getRepository(ParametreRef::class)->find(1);
$secteurs = $this->getDoctrine()->getRepository(Secteurs::class)->findBy(['actif'=>true],['position'=>'ASC']);
return $this->render('front/'.$this->theme.'/partials/footer/footer.html.twig',[
'menus'=> $data_menu,
'social'=> $social,
'parametreRef'=> $parametreRef,
'secteurs'=> $secteurs,
'languages'=> $languages,
'categories'=> $categories,
'parametre'=> $parametre,
'theme_option'=> $theme_option,
'contacts'=> $contacts,
'contactsInfos'=> $contacts_noms,
]);
}
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,
]);
}
}