src/Controller/Buzz/CoreController.php line 146

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\Buzz;
  4. use App\Helper\Utils;
  5. use App\Controller\EntityUsingController;
  6. use App\Repository\Buzz\BuzzActualitesRepository;
  7. use App\Services\Buzz\BuzzIndexPageProvider;
  8. use App\Services\Buzz\CanonicalUrlService;
  9. use App\Services\MetaTag;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use App\Services\ManagerEntity\PanierManagers;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use App\Services\ManagerEntity\ParametreSiteManagers;
  14. use Symfony\Component\HttpFoundation\RedirectResponse;
  15. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  16. use App\Services\ManagerEntity\DroitsAccesManagers;
  17. /**
  18.  *
  19.  * @author mehrez
  20.  */
  21. class CoreController extends EntityUsingController
  22. {
  23.     const MAX_AGE 43200;
  24.     /**
  25.      * @var \App\Services\ManagerEntity\ParametreSiteManagers
  26.      */
  27.     private $psm;
  28.     /**
  29.      * @var ParameterBagInterface
  30.      */
  31.     private $params;
  32.     /**
  33.      * @var PanierManagers
  34.      */
  35.     private $pm;
  36.     /**
  37.      * @var BuzzIndexPageProvider
  38.      */
  39.     private $buzzIndexPageProvider;
  40.     /**
  41.      * @var BuzzActualitesRepository
  42.      */
  43.     private $buzzActualitesRepository;
  44.     /**
  45.      * @var DroitsAccesManagers
  46.      */
  47.     private $droitsAccesManagers;
  48.     
  49.     /**
  50.      * @var CanonicalUrlService
  51.      */
  52.     private $canonicalUrlService;
  53.     public function __construct(PanierManagers $pmParametreSiteManagers $psmParameterBagInterface $paramsBuzzIndexPageProvider $buzzIndexPageProviderBuzzActualitesRepository $buzzActualitesRepositoryDroitsAccesManagers $droitsAccesManagersCanonicalUrlService $canonicalUrlService)
  54.     {
  55.         $this->psm $psm;
  56.         $this->params $params;
  57.         $this->pm $pm;
  58.         $this->buzzIndexPageProvider $buzzIndexPageProvider;
  59.         $this->buzzActualitesRepository $buzzActualitesRepository;
  60.         $this->droitsAccesManagers $droitsAccesManagers;
  61.         $this->canonicalUrlService $canonicalUrlService;
  62.     }
  63.     public function changeLangue(Request $request): RedirectResponse
  64.     {
  65.         $uri $request->server->get('HTTP_REFERER');
  66.         $lang $request->attributes->get('lang');
  67.         if ($lang) {
  68.             setcookie('lang'$langtime() + 60 60 24 365);
  69.             $request->getSession()->set('_locale'$lang);
  70.             $request->setLocale($lang);
  71.             $request->getSession()->set('lang'$lang);
  72.         }
  73.         return $this->redirect($uri);
  74.     }
  75.     /**
  76.      *
  77.      */
  78.     public function changeFlag(Request $request$codePays) {
  79.         // depuis config/packages/international.yaml
  80.         $listCodePays array_column($this->params->get('app.pays_version'), '2'''); // _fr_ _ch_ _be_ _ca_
  81.         $oldPathUri $request->headers->get('referer');
  82.         foreach ($listCodePays as $code) {
  83.             if (!empty($oldPathUri) && !empty($code) && Utils::stringContainsWord($oldPathUri$code)) {
  84.                 $oldPathUri str_replace($code$codePays$oldPathUri);
  85.                 return $this->redirect($oldPathUri);
  86.             }
  87.             if (!empty($oldPathUri) && Utils::endsWith('/' Utils::codePaysWithoutDash($code), $oldPathUri)) { // PAGE D'ACCUEIL AVEC  /fr
  88.                 $oldPathUri str_replace(Utils::codePaysWithoutDash($code), Utils::codePaysWithoutDash($codePays), $oldPathUri);
  89.                 return $this->redirect($oldPathUri);
  90.             }
  91.         }
  92.         if (!$oldPathUri) {
  93.             $oldPathUri "/";
  94.         }
  95.         return $this->redirect($oldPathUri);
  96.     }
  97.     
  98.     public function menu(Request $request$lang$currentRoute$codePays$authFrom null): Response
  99.     {
  100.         $listValueParamSiteFooter $this->psm->getListValueParamSiteMenu($codePays'FUSACQ');
  101.         foreach ($listValueParamSiteFooter as $key => $item) {
  102.             $item['value'] = Utils::getLinkFromValueParam($item['value']);
  103.             $listValueParamSiteFooter[$key] = $item;
  104.         }
  105.         $session $request->getSession();
  106.         $userIdentity null;
  107.         if ($session) {
  108.             $userIdentity $session->get('user');
  109.         }
  110.         $response $this->render(
  111.             'buzz/core/menu.html.twig',
  112.             [
  113.                 'controller_name' => 'CoreController',
  114.                 'codePaysWithUnderScore' => $codePays,
  115.                 'currentRoute' => $currentRoute,
  116.                 'codePays' => str_replace('_'''$codePays),
  117.                 'nb_bloc' => count($listValueParamSiteFooter),
  118.                 'lang' => $lang,
  119.                 'params_header' => $listValueParamSiteFooter,
  120.                 'authFrom' => $authFrom,
  121.                 'userIdentity' => $userIdentity
  122.             ]
  123.         );
  124.         $response->setPublic();
  125.         $response->setMaxAge(43200); // 12heures
  126.         return $response;
  127.     }
  128.     /**
  129.      */
  130.     public function footer(Request $request$codePays$lang): Response
  131.     {
  132.         $listValueParamSiteFooter $this->psm->getListValueParamSiteFooter($codePays'FUSACQ');
  133.         foreach ($listValueParamSiteFooter as $key => $item) {
  134.             $item['value'] = Utils::getLinkFromValueParam($item['value']);
  135.             $listValueParamSiteFooter[$key] = $item;
  136.         }
  137.         $html $this->renderView('buzz/core/footer.html.twig', [
  138.             'controller_name' => 'CoreController',
  139.             'codePaysWithUnderScore' => $codePays,
  140.             'nb_bloc' => count($listValueParamSiteFooter),
  141.             'lang' => $lang,
  142.             'anneeEnCours' => date("Y"),
  143.             'params_footer' => $listValueParamSiteFooter,
  144.         ]);
  145.         $etag md5($html);
  146.         $response = new Response($html);
  147.         $response->setEtag($etag);
  148.         if ($response->isNotModified($request)) {
  149.             return $response;
  150.         }
  151.         $response->setPublic();
  152.         $response->setMaxAge(43200); // 12 heures
  153.         return $response;
  154.     }
  155.     /**
  156.      * Récupère la colonne de droite avec les données juridiques et experts
  157.      *
  158.      * @param Request $request
  159.      * @param string $codePays
  160.      * @return Response
  161.      */
  162.     public function rightColumn(Request $request$codePays 'fr')
  163.     {
  164.         $alwaysShow $request->get('alwaysShowJuridiqueExperts'false);
  165.         $isInternationalImage $request->get('isInternationalImage'false);
  166.         if ($codePays === 'fr' || $alwaysShow) {
  167.             $juridique $this->buzzIndexPageProvider->getSidebarJuridiqueData('fr'3);
  168.             $experts $this->buzzIndexPageProvider->getSidebarDirectExpertsData('fr');
  169.         } else {
  170.             $juridique = [];
  171.             $experts = [];
  172.         }
  173.         $enDirectFusacq $this->buzzIndexPageProvider->getLastDirectFusacqWithHeure(5);
  174.         return $this->render('buzz/fragments/sidebar.html.twig', [
  175.             'juridique' => $juridique,
  176.             'experts' => $experts,
  177.             'en_direct_fusacq' => $enDirectFusacq,
  178.             'alwaysShowJuridiqueExperts' => $alwaysShow,
  179.             'isInternationalImage' => $isInternationalImage,
  180.         ]);
  181.     }
  182.     /**
  183.      * Récupère la colonne de droite pour la page de détail d'un article
  184.      *
  185.      * @param string $lang
  186.      * @param string $codePays
  187.      * @param string|null $authFrom
  188.      * @param Request $request
  189.      * @return Response
  190.      */
  191.     public function colonneDroiteDetail($lang$codePays$authFrom nullRequest $request)
  192.     {
  193.         $idSecteur $request $request->get('idSecteur') : null;
  194.         $idActualite $request->get('idActualite');
  195.         $idOperation $request->get('idOperation');
  196.         
  197.         if (!$idSecteur && $idActualite) {
  198.             if (!$idOperation) {
  199.                 $articleData $this->buzzIndexPageProvider->getArticleDetailById((int)$idActualite);
  200.                 if ($articleData && !empty($articleData['id_operation'])) {
  201.                     $idOperation = (int) $articleData['id_operation'];
  202.                 }
  203.             }
  204.             $idSecteur $this->buzzIndexPageProvider->getSecteurWithFallback((int)$idActualite$idOperation ? (int)$idOperation null);
  205.         }
  206.         $show_experts_references $request->get('show_experts_references'false);
  207.         $render_only_tables $request->get('render_only_tables'false);
  208.         $show_tables_in_aside $request->get('show_tables_in_aside'true);
  209.         $idLocalisation $request->get('idLocalisation');
  210.         
  211.         if (!$idOperation && $idActualite) {
  212.             $articleData $this->buzzIndexPageProvider->getArticleDetailById((int)$idActualite);
  213.             if ($articleData && !empty($articleData['id_operation'])) {
  214.                 $idOperation = (int) $articleData['id_operation'];
  215.             }
  216.         }
  217.         $societesAReprendre = [];
  218.         $acquereursSecteur = [];
  219.         $secteurInfo null;
  220.         
  221.         if ($idOperation) {
  222.             $operation $this->buzzIndexPageProvider->getOperationById($idOperation);
  223.             if ($operation && !empty($operation['id_secteur_activite'])) {
  224.                 $idSecteur = (int) $operation['id_secteur_activite'];
  225.             }
  226.             
  227.             $societesAReprendre $this->buzzIndexPageProvider->getSocietesAReprendreDansSecteurByOperation($idOperation5$idSecteur);
  228.             $acquereursSecteur $this->buzzIndexPageProvider->getAcquereursDansSecteurByOperation($idOperation5$idSecteur);
  229.             if (!$idLocalisation) {
  230.                 $idLocalisation $this->buzzIndexPageProvider->getLocalisationIdFromOperation((int) $idOperation);
  231.             }
  232.             if ($idSecteur) {
  233.                 $secteurInfo $this->buzzIndexPageProvider->getSecteurInfo($idSecteur);
  234.             }
  235.         }
  236.         if ($idSecteur) {
  237.             $actualitesSecteur $this->buzzIndexPageProvider->getSidebarActualitesSecteur($idSecteur5$idActualite ? (int)$idActualite null);
  238.         } else {
  239.             $actualitesSecteur = [];
  240.         }
  241.         $localisationInfo $this->buzzIndexPageProvider->getLocalisationInfo($idLocalisation);
  242.         $enDirectFusacq $this->buzzIndexPageProvider->getLastDirectFusacqWithHeure(5);
  243.         $enDirectDesExperts $this->buzzIndexPageProvider->getSidebarDirectExpertsData($codePays);
  244.        
  245.         $renderOnlyTables = (bool) $request->get('render_only_tables'false);
  246.         $template $renderOnlyTables
  247.             'buzz/fragments/secteur_tables.html.twig'
  248.             'buzz/fragments/colonne_droite_buzz.html.twig';
  249.         return $this->render($template, [
  250.             'actualites_secteur' => $actualitesSecteur,
  251.             'societes_a_reprendre' => $societesAReprendre,
  252.             'acquereurs_secteur' => $acquereursSecteur,
  253.             'secteur_info' => $secteurInfo,
  254.             'localisation_info' => $localisationInfo,
  255.             'en_direct_fusacq' => $enDirectFusacq,
  256.             'en_direct_des_experts' => $enDirectDesExperts,
  257.             'codePaysWithUnderScore' => $codePays,
  258.             'lang' => $lang,
  259.             'authFrom' => $authFrom,
  260.             'show_experts_references' => $show_experts_references,
  261.             'render_only_tables' => $renderOnlyTables,
  262.             'show_tables_in_aside' => $show_tables_in_aside,
  263.         ]);
  264.     }
  265.     /**
  266.      * Récupère la sidebar de droite avec prestations, formations et juridique
  267.      *
  268.      * @param string $lang
  269.      * @param string $codePays
  270.      * @param string|null $authFrom
  271.      * @return Response
  272.      */
  273.     public function sidebarDroite($lang$codePays$authFrom null)
  274.     {
  275.         $prestations $this->buzzIndexPageProvider->getDernieresPrestationsSidebar(3);
  276.         $formations $this->buzzIndexPageProvider->getFormationsSidebar(3);
  277.         $juridique $this->buzzIndexPageProvider->getSidebarJuridiqueData($codePays3);
  278.         return $this->render('buzz/fragments/sidebar_droite.html.twig', [
  279.             'prestations' => $prestations,
  280.             'formations' => $formations,
  281.             'juridique' => $juridique,
  282.             'codePaysWithUnderScore' => $codePays,
  283.             'lang' => $lang,
  284.             'authFrom' => $authFrom,
  285.         ]);
  286.     }
  287.     /**
  288.      * Récupère l'aside juridique et fiscal avec les actualités et experts
  289.      *
  290.      * @param string $codePays
  291.      * @param string|null $authFrom
  292.      * @return Response
  293.      */
  294.     public function asideJuridiqueFiscale($codePays 'fr'$authFrom null)
  295.     {
  296.         $enDirectFusacq $this->buzzIndexPageProvider->getLastDirectFusacqWithHeure(5);
  297.         $enDirectDesExperts $this->buzzIndexPageProvider->getSidebarDirectExpertsData($codePays);
  298.         $user $this->getUser();
  299.         $statusAuth 2;
  300.         if ($user) {
  301.             $hasAccess $this->droitsAccesManagers->hasJuridiqueAccess($user);
  302.             $statusAuth $hasAccess 1;
  303.         } else {
  304.             $statusAuth 0;
  305.         }
  306.         return $this->render('buzz/fragments/aside_juridique_fiscale.html.twig', [
  307.             'enDirectFusacq' => $enDirectFusacq,
  308.             'enDirectDesExperts' => $enDirectDesExperts,
  309.             'authFrom' => $authFrom,
  310.             'statusAuth' => $statusAuth,
  311.         ]);
  312.     }
  313.     /**
  314.      * Page des flux RSS
  315.      */
  316.     public function fluxRss(Request $request$codePays '_fr_'): Response
  317.     {
  318.         $lang $request->getLocale();
  319.         $currentRoute 'buzz_flux_rss';
  320.         $codePaysWithUnderScore $codePays;
  321.         $authFrom null;
  322.         
  323.         $cleanCodePays $this->canonicalUrlService->cleanCodePays($codePays);
  324.         $canonicalUrl $this->canonicalUrlService->getBuzzFluxRssCanonical($cleanCodePays);
  325.         
  326.         $hreflangLinks $this->canonicalUrlService->getBuzzHreflangLinks('buzz_flux_rss', [], null$cleanCodePays);
  327.         $alternates $this->canonicalUrlService->convertHreflangToAlternates($hreflangLinks);
  328.         $metaTag = (new MetaTag())
  329.             ->setTitle('Flux RSS Fusacq Buzz - Actualités fusions-acquisitions')
  330.             ->setDescription('Abonnez-vous aux flux RSS Fusacq Buzz pour recevoir l\'actualité des fusions-acquisitions en temps réel. Flux RSS national, international, juridique et fiscal.')
  331.             ->setCanonical($canonicalUrl)
  332.             ->setAlternates($alternates);
  333.         return $this->render('buzz/flux_rss.html.twig', [
  334.             'metaTag' => $metaTag,
  335.             'lang' => $lang,
  336.             'currentRoute' => $currentRoute,
  337.             'codePaysWithUnderScore' => $codePaysWithUnderScore,
  338.             'authFrom' => $authFrom,
  339.             'hreflangLinks' => $hreflangLinks,
  340.         ]);
  341.     }
  342.     /**
  343.      * Page inscription classements
  344.      */
  345.     public function inscriptionClassements(Request $request$codePays '_fr_'): Response
  346.     {
  347.         $lang $request->getLocale();
  348.         $cleanCodePays $this->canonicalUrlService->cleanCodePays($codePays);
  349.         $canonicalUrl $this->canonicalUrlService->getBuzzInscriptionClassementsCanonical($cleanCodePays);
  350.         
  351.         $hreflangLinks $this->canonicalUrlService->getBuzzHreflangLinks('buzz_inscription_classements', [], null$cleanCodePays);
  352.         $alternates $this->canonicalUrlService->convertHreflangToAlternates($hreflangLinks);
  353.         $metaTag = (new MetaTag())
  354.             ->setTitle('Les classements FUSACQ : Mode d\'emploi')
  355.             ->setDescription('Comment apparaître dans les classements FUSACQ ?')
  356.             ->setCanonical($canonicalUrl)
  357.             ->setAlternates($alternates);
  358.         return $this->render('classement/inscription_classements.html.twig', [
  359.             'metaTag' => $metaTag,
  360.             'lang' => $lang,
  361.             'currentRoute' => 'buzz_inscription_classements',
  362.             'codePaysWithUnderScore' => $codePays,
  363.             'authFrom' => null,
  364.             'hreflangLinks' => $hreflangLinks,
  365.         ]);
  366.     }
  367. }