src/Controller/HomeController.php line 41

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Constants\CentreServicesParametresConstants;
  4. use App\Constants\CompteClientConstants;
  5. use App\Entity\Centre;
  6. use App\Entity\CompteClient;
  7. use App\Manager\Dossier\DossierListManager;
  8. use App\Manager\Sendinblue\SendinblueContactsManager;
  9. use App\Repository\CentreServicesParametresRepository;
  10. use App\Repository\CompteClientRepository;
  11. use App\Services\Metier\CentreServicesParametresSM;
  12. use Doctrine\Persistence\ManagerRegistry;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\Session\Session;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. /**
  17. * @Route("/")
  18. */
  19. class HomeController extends AbstractController
  20. {
  21. private CentreServicesParametresSM $csp;
  22. private CompteClientRepository $compteClientRepository;
  23. private CentreServicesParametresRepository $centreServicesParametresRepository;
  24. public function __construct(CentreServicesParametresSM $csp,CompteClientRepository $compteClientRepository, CentreServicesParametresRepository $centreServicesParametresRepository)
  25. {
  26. $this->csp = $csp;
  27. $this->compteClientRepository = $compteClientRepository;
  28. $this->centreServicesParametresRepository = $centreServicesParametresRepository;
  29. }
  30. /**
  31. * @Route("", name="connect_home")
  32. * @param Session $session
  33. * @param ManagerRegistry $doctrine
  34. *
  35. * @return void
  36. */
  37. public function index(Session $session, ManagerRegistry $doctrine)
  38. {
  39. $compte = $this->getUser();
  40. assert($compte instanceof CompteClient);
  41. $smartBannerUrlScheme = $this->centreServicesParametresRepository->findOneBy(['reference' => CentreServicesParametresConstants::CENTRE_SMART_BANNER_URL_SCHEME]);
  42. $smartBannerIcon = $this->centreServicesParametresRepository->findOneBy(['reference' => CentreServicesParametresConstants::CENTRE_SMART_BANNER_ICON]);
  43. $urlFrontDesk = $this->centreServicesParametresRepository->findOneBy(['reference' => CentreServicesParametresConstants::CENTRE_FRONTDESK_URL]);
  44. $compteId = $compte->getId();
  45. $session->set('id-compte', $compteId);
  46. $session->set('smart-banner-icon', $smartBannerIcon->getValeur());
  47. $session->set('smart-banner-url-scheme', $smartBannerUrlScheme->getValeur());
  48. $session->set('url-front-desk', $urlFrontDesk->getValeur());
  49. $em = $doctrine->getManager();
  50. $idDossier = 0;
  51. $dossier = DossierListManager::getDossierByCompteClientDQL($em, $compteId);
  52. if(isset($dossier[0]) && is_object($dossier[0])) {
  53. $idDossier = $dossier[0]->getIdDossier();
  54. $idCentre = $dossier[0]->getIdCentre();
  55. $centre = $em->getRepository(Centre::class)->find($idCentre);
  56. $session->set('nom-centre', $centre->getNomCentre());
  57. $session->set('id-centre', $idCentre);
  58. $session->set('email-centre', $centre->getEmailCentre());
  59. if($compte->getEtat() == CompteClientConstants::ETAT_INACTIF){
  60. $compte->setEtat(CompteClientConstants::ETAT_ACTIF)
  61. ->setDisponibilite(1);
  62. $em->persist($compte);
  63. $em->flush();
  64. $cleApi = $this->csp->getBrevoApiKey();
  65. SendinblueContactsManager::createOrUpdateAttributContact($cleApi, $compte, $dossier[0]);
  66. }
  67. }
  68. // $session->set('idDossier', $idDossier);
  69. return $this->render('home/home.html.twig', array('idDossier' => $idDossier));
  70. }
  71. }