<?php
namespace App\Controller;
use App\Constants\CentreServicesParametresConstants;
use App\Constants\CompteClientConstants;
use App\Entity\Centre;
use App\Entity\CompteClient;
use App\Manager\Dossier\DossierListManager;
use App\Manager\Sendinblue\SendinblueContactsManager;
use App\Repository\CentreServicesParametresRepository;
use App\Repository\CompteClientRepository;
use App\Services\Metier\CentreServicesParametresSM;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/")
*/
class HomeController extends AbstractController
{
private CentreServicesParametresSM $csp;
private CompteClientRepository $compteClientRepository;
private CentreServicesParametresRepository $centreServicesParametresRepository;
public function __construct(CentreServicesParametresSM $csp,CompteClientRepository $compteClientRepository, CentreServicesParametresRepository $centreServicesParametresRepository)
{
$this->csp = $csp;
$this->compteClientRepository = $compteClientRepository;
$this->centreServicesParametresRepository = $centreServicesParametresRepository;
}
/**
* @Route("", name="connect_home")
* @param Session $session
* @param ManagerRegistry $doctrine
*
* @return void
*/
public function index(Session $session, ManagerRegistry $doctrine)
{
$compte = $this->getUser();
assert($compte instanceof CompteClient);
$smartBannerUrlScheme = $this->centreServicesParametresRepository->findOneBy(['reference' => CentreServicesParametresConstants::CENTRE_SMART_BANNER_URL_SCHEME]);
$smartBannerIcon = $this->centreServicesParametresRepository->findOneBy(['reference' => CentreServicesParametresConstants::CENTRE_SMART_BANNER_ICON]);
$urlFrontDesk = $this->centreServicesParametresRepository->findOneBy(['reference' => CentreServicesParametresConstants::CENTRE_FRONTDESK_URL]);
$compteId = $compte->getId();
$session->set('id-compte', $compteId);
$session->set('smart-banner-icon', $smartBannerIcon->getValeur());
$session->set('smart-banner-url-scheme', $smartBannerUrlScheme->getValeur());
$session->set('url-front-desk', $urlFrontDesk->getValeur());
$em = $doctrine->getManager();
$idDossier = 0;
$dossier = DossierListManager::getDossierByCompteClientDQL($em, $compteId);
if(isset($dossier[0]) && is_object($dossier[0])) {
$idDossier = $dossier[0]->getIdDossier();
$idCentre = $dossier[0]->getIdCentre();
$centre = $em->getRepository(Centre::class)->find($idCentre);
$session->set('nom-centre', $centre->getNomCentre());
$session->set('id-centre', $idCentre);
$session->set('email-centre', $centre->getEmailCentre());
if($compte->getEtat() == CompteClientConstants::ETAT_INACTIF){
$compte->setEtat(CompteClientConstants::ETAT_ACTIF)
->setDisponibilite(1);
$em->persist($compte);
$em->flush();
$cleApi = $this->csp->getBrevoApiKey();
SendinblueContactsManager::createOrUpdateAttributContact($cleApi, $compte, $dossier[0]);
}
}
// $session->set('idDossier', $idDossier);
return $this->render('home/home.html.twig', array('idDossier' => $idDossier));
}
}