<?php
namespace App\Controller;
use App\Entity\User;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Annotation\Route;
class IndexController extends AbstractController
{
private ?ObjectManager $em = null;
private ?string $prefixSociete = null;
/**
* Stockage des informations de la société pour affichage sur entête document
* @var object|mixed|null
*/
private ?object $dataSociete = null;
public function __construct(RequestStack $requestStack, ManagerRegistry $doctrine)
{
$request = $requestStack->getCurrentRequest();
//TODO: page erreur subdomain
if(null===$request->getSession()->get('societe')) return $this->render('misc/404.html.twig');
// on récupère le sous-domaine stocké en session pour pointer vers le bon entity manager
$subdomain = $request->getSession()->get('societe')->getBase();
$this->em = $doctrine->getManager($subdomain);
$this->prefixSociete = $request->getSession()->get('societe')->getPrefix();
if(null!==$this->prefixSociete) $this->prefixSociete = strtoupper($this->prefixSociete);
$jsonString = $request->getSession()->get('societe')->getData();
if(null!==$jsonString) {
$this->dataSociete = json_decode($jsonString);
$this->dataSociete->lib_societe = $request->getSession()->get('societe')->getLibSociete();
}
}
/**
* @Route("/", name="index")
*/
public function index(UserPasswordHasherInterface $passwordHasher): Response
{
$userRepository = $this->em->getRepository(User::class);
/** @var \App\Entity\User $user */
$user = $userRepository->find(1);
// $user->setEmail('admin@gs-prod.fr');
// // update user
// $hashedPassword = $passwordHasher->hashPassword(
// $user,
// 'Groovy_Baby2022'
// );
// $user->setPassword($hashedPassword);
// $this->em->persist($user);
// $this->em->flush();
return $this->render('index.html.twig', [
'id_menu' => 'index',
'controller_name' => 'IndexController',
]);
}
}