src/Controller/CoreController.php line 150

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * @author Mehrez Labidi
  5.  */
  6. namespace App\Controller;
  7. use App\Helper\Utils;
  8. use App\Services\ManagerEntity\ParametreSiteManagers;
  9. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  10. use Symfony\Component\HttpFoundation\RedirectResponse;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use App\Services\ManagerEntity\PanierManagers;
  14. use App\Entity\Societes;
  15. class CoreController extends EntityUsingController {
  16.     /**
  17.      * @var \App\Services\ManagerEntity\ParametreSiteManagers
  18.      */
  19.     private $psm;
  20.     /**
  21.      * @var ParameterBagInterface
  22.      */
  23.     private $params;
  24.     /**
  25.      * @var PanierManagers
  26.      */
  27.     private $pm;
  28.     public function __construct(PanierManagers $pmParametreSiteManagers $psmParameterBagInterface $params) {
  29.         $this->psm $psm;
  30.         $this->params $params;
  31.         $this->pm $pm;
  32.     }
  33.     public function changeLangue(Request $request): RedirectResponse {
  34.         $uri $request->server->get('HTTP_REFERER');
  35.         $lang $request->attributes->get('lang');
  36.         if ($lang) {
  37.             setcookie('lang'$langtime() + 60 60 24 365);
  38.             $request->getSession()->set('_locale'$lang);
  39.             $request->setLocale($lang);
  40.             $request->getSession()->set('lang'$lang);
  41.         }
  42.         return $this->redirect($uri);
  43.     }
  44.     /**
  45.      * @param $currentRoute
  46.      * @param $codePays
  47.      *
  48.      * @return \Symfony\Component\HttpFoundation\RedirectResponse
  49.      */
  50.     public function changeFlag(Request $request$codePays) {
  51.         // depuis config/packages/international.yaml
  52.         $listCodePays array_column($this->params->get('app.pays_version'), '2'''); // _fr_ _ch_ _be_ _ca_
  53.         $oldPathUri $request->headers->get('referer');
  54.         foreach ($listCodePays as $code) {
  55.             if (!empty($oldPathUri) && !empty($code) && Utils::stringContainsWord($oldPathUri$code)) {
  56.                 $oldPathUri str_replace($code$codePays$oldPathUri);
  57.                 return $this->redirect($oldPathUri);
  58.             }
  59.             if (!empty($oldPathUri) && Utils::endsWith('/' Utils::codePaysWithoutDash($code), $oldPathUri)) { // PAGE D'ACCUEIL AVEC  /fr
  60.                 $oldPathUri str_replace(Utils::codePaysWithoutDash($code), Utils::codePaysWithoutDash($codePays), $oldPathUri);
  61.                 return $this->redirect($oldPathUri);
  62.             }
  63.         }
  64.         if (!$oldPathUri) {
  65.             $oldPathUri "/";
  66.         }
  67.         return $this->redirect($oldPathUri);
  68.     }
  69.     public function menu(Request $request$lang$currentRoute$codePays$authFrom null) {
  70.         $listValueParamSiteFooter $this->psm->getListValueParamSiteMenu($codePays'FUSACQ');
  71.         foreach ($listValueParamSiteFooter as $key => $item) {
  72.             $item['value'] = Utils::getLinkFromValueParam($item['value']);
  73.             $listValueParamSiteFooter[$key] = $item;
  74.         }
  75.         $nbAnnoncePanier 0;
  76.         $session $request->getSession();
  77.         if ($session) {
  78.             $userIdentity $session->get('user');
  79.             if (!empty($userIdentity)) {
  80.                 $panier $this->pm->getPanierByLoginUtilisateur($userIdentity->_get('login_utilisateur'));
  81.                 if (!empty($panier)) {
  82.                     $nbAnnoncePanier $this->calcule_nb_annonce($panier);
  83.                 }
  84.             }
  85.         }
  86.         $response $this->render(
  87.                 'core/menu.html.twig',
  88.                 [
  89.                     'controller_name' => 'CoreController',
  90.                     'codePaysWithUnderScore' => $codePays,
  91.                     'currentRoute' => $currentRoute,
  92.                     'codePays' => str_replace('_'''$codePays),
  93.                     'nb_bloc' => count($listValueParamSiteFooter),
  94.                     'lang' => $lang,
  95.                     'params_header' => $listValueParamSiteFooter,
  96.                     'nbAnnoncePanier' => $nbAnnoncePanier,
  97.                     'authFrom' => $authFrom
  98.                 ]
  99.         );
  100.         $response->setPublic();
  101.         $response->setMaxAge(43200); // 12heures
  102.         return $response;
  103.     }
  104.     /**
  105.      * @param $codePays
  106.      * @param $lang
  107.      * @return mixed
  108.      */
  109.     public function footer($codePays$lang) {
  110.         $listValueParamSiteFooter $this->psm->getListValueParamSiteFooter($codePays'FUSACQ');
  111.         foreach ($listValueParamSiteFooter as $key => $item) {
  112.             $item['value'] = Utils::getLinkFromValueParam($item['value']);
  113.             $listValueParamSiteFooter[$key] = $item;
  114.         }
  115.         $response $this->render(
  116.                 'core/footer.html.twig',
  117.                 [
  118.                     'controller_name' => 'CoreController',
  119.                     'codePaysWithUnderScore' => $codePays,
  120.                     'nb_bloc' => count($listValueParamSiteFooter),
  121.                     'lang' => $lang,
  122.                     'anneeEnCours' => date("Y"),
  123.                     'params_footer' => $listValueParamSiteFooter,
  124.                 ]
  125.         );
  126.         $response->setPublic();
  127.         $response->setMaxAge(43200); // 12heures
  128.         return $response;
  129.     }
  130.     public function pubFusacqExpert(Request $request$display_title$display_login$lang$codePays): Response {
  131.         $numeroTelephone "01 48 28 24 24"//A developper
  132.         $repoSociete $this->getDoctrine()->getRepository(Societes::class);
  133.         
  134.         $nb_participations_fonds $repoSociete->donne_nb_participations_fonds([]);
  135.         
  136.         return $this->render('core/pub_fusacq_expert.html.twig',
  137.                         [
  138.                             'display_title' => $display_title,
  139.                             'display_login' => $display_login,
  140.                             'lang' => $lang,
  141.                             'codePays' => str_replace('_'''$codePays),
  142.                             'numeroTelephone' => $numeroTelephone,
  143.                             'nb_participations_fonds' => $nb_participations_fonds
  144.         ]);
  145.     }
  146.     private function calcule_nb_annonce($panier) {
  147.         $nbAnnonce 0;
  148.         $panierV = array();
  149.         $panierA = array();
  150.         $panierR = array();
  151.         $panierCRO = array();
  152.         $panierPART = array();
  153.         $panierAH = array();
  154.         $panierFONDS = array();
  155.         if (!empty($panier["resV"])) {
  156.             $panierV $panier["resV"];
  157.             $nbAnnonce $nbAnnonce count($panierV);
  158.         }
  159.         if (!empty($panier["resA"])) {
  160.             $panierA $panier["resA"];
  161.             $nbAnnonce $nbAnnonce count($panierA);
  162.         }
  163.         if (!empty($panier["resR"])) {
  164.             $panierR $panier["resR"];
  165.             $nbAnnonce $nbAnnonce count($panierR);
  166.         }
  167.         if (!empty($panier["resBA"])) {
  168.             $panierBA $panier["resBA"];
  169.             $nbAnnonce $nbAnnonce count($panierBA);
  170.         }
  171.         if (!empty($panier["resCRO"])) {
  172.             $panierCRO $panier["resCRO"];
  173.             $nbAnnonce $nbAnnonce count($panierCRO);
  174.         }
  175.         if (!empty($panier["resPART"])) {
  176.             $panierPART $panier["resPART"];
  177.             $nbAnnonce $nbAnnonce count($panierPART);
  178.         }
  179.         if (!empty($panier["resAH"])) {
  180.             $panierAH $panier["resAH"];
  181.             $nbAnnonce $nbAnnonce count($panierAH);
  182.         }
  183.         if (!empty($panier["resFONDS"])) {
  184.             $panierFONDS=$panier["resFONDS"];
  185.             $nbAnnonce $nbAnnonce count($panierFONDS);
  186.         }
  187.         return $nbAnnonce;
  188.     }
  189. }