<?php
namespace App\Controller\General\Template;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use App\Security\TokenAuthenticator;
use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
use App\Service\Servicetext\GeneralServicetext;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\Users\User\User;
use App\Entity\Produit\Service\Typearticle;
use App\Entity\Users\Adminuser\Parametre;
use App\Entity\Users\Adminuser\Parametreitem;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Produit\Service\Service;
use App\Entity\Produit\Service\Agence;
class MenuController extends AbstractController
{
private $params;
private $authenticator;
private $guardHandler;
public function __construct(ParameterBagInterface $params, TokenAuthenticator $authenticator, GuardAuthenticatorHandler $guardHandler)
{
$this->params = $params;
$this->authenticator = $authenticator;
$this->guardHandler = $guardHandler;
}
public function menubare(GeneralServicetext $service, Request $request, $position)
{
$user = null;
$em = $this->getDoctrine()->getManager();
if($this->getUser() == null and isset($_COOKIE["PIDSESSREM"]) and $_COOKIE["PIDSESSREM"] != 'delete')
{
$cookies = $_COOKIE["PIDSESSREM"];
$username = trim($service->decrypt($cookies, $this->params->get('saltcookies')));
if($service->email($username) || $service->telephone($username))
{
$repository = $em->getRepository(User::class);
$user = $repository->findOneBy(array('username'=>$username));
if($user != null)
{
$response = $this->guardHandler->authenticateUserAndHandleSuccess(
$user, // the User object you just created
$request,
$this->authenticator, // authenticator whose onAuthenticationSuccess you want to use
'main' // the name of your firewall in security.yaml
);
}
}
}
$liste_agence = $em->getRepository(Agence::class)
->findAll();
$type_article = $em->getRepository(Typearticle::class)
->myfindAll();
$aboutContacts = $em->getRepository(Parametre::class)
->findOneBy(array('typeParam'=>'contacts'), array('rang'=>'asc'), 1);
$liste_contacts = new ArrayCollection();
if($aboutContacts != null)
{
$liste_contacts = $em->getRepository(Parametreitem::class)
->findBy(array('parametre'=>$aboutContacts), array('rang'=>'asc'));
}
$aboutSocials = $em->getRepository(Parametre::class)
->findOneBy(array('typeParam'=>'socialmedia'), array('rang'=>'asc'), 1);
$social_medias = new ArrayCollection();
if($aboutSocials != null)
{
$social_medias = $em->getRepository(Parametreitem::class)
->findBy(array('parametre'=>$aboutSocials), array('rang'=>'asc'));
}
return $this->render($service->getThemeDirectory().'/General/Template/Menu/menubare.html.twig',
array(
'position'=>$position,
'type_article'=>$type_article,
'liste_contacts'=>$liste_contacts,
'social_medias'=>$social_medias,
'liste_agence'=>$liste_agence,
));
}
public function footer(GeneralServicetext $service, EntityManagerInterface $em, $position)
{
$aboutplatform = $em->getRepository(Parametre::class)
->findOneBy(array('typeParam'=>'aboutplatform'), array('rang'=>'asc'), 1);
$aboutSocials = $em->getRepository(Parametre::class)
->findOneBy(array('typeParam'=>'socialmedia'), array('rang'=>'asc'), 1);
$social_medias = new ArrayCollection();
if($aboutSocials != null)
{
$social_medias = $em->getRepository(Parametreitem::class)
->findBy(array('parametre'=>$aboutSocials), array('rang'=>'asc'));
}
$liste_service = $em->getRepository(Service::class)
->findTopServices(5);
$aboutContacts = $em->getRepository(Parametre::class)
->findOneBy(array('typeParam'=>'contacts'), array('rang'=>'asc'), 1);
$liste_contacts = new ArrayCollection();
if($aboutContacts != null)
{
$liste_contacts = $em->getRepository(Parametreitem::class)
->findBy(array('parametre'=>$aboutContacts), array('rang'=>'asc'));
}
$repository = $em->getRepository(Service::class);
$liste_departement = $repository->findServiceTypePagine("departement", 1, 8);
return $this->render($service->getThemeDirectory().'/General/Template/Menu/footer.html.twig',
array('position'=>$position, 'aboutplatform'=>$aboutplatform, 'social_medias'=>$social_medias,
'liste_service'=>$liste_service, 'liste_contacts'=>$liste_contacts, 'liste_departement'=>$liste_departement));
}
public function menuleft(GeneralServicetext $service, $position)
{
return $this->render($service->getThemeDirectory().'/General/Template/Menu/menuleft.html.twig', array('position'=>$position));
}
public function newletter(GeneralServicetext $service)
{
return $this->render($service->getThemeDirectory().'/General/Template/Menu/newletter.html.twig');
}
}