src/Controller/WidgetActuController.php line 861

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Actuv2InfographieRse;
  4. use App\Entity\ContactParticipationPlaceExpert;
  5. use App\Entity\EmailBlacklist;
  6. use App\Form\ContactParticipationPlaceExpertType;
  7. use App\Repository\PodcastPrivateRepository;
  8. use App\Services\HelpersFirmsService;
  9. use DateTime;
  10. use Exception;
  11. use App\Services\WebSite;
  12. use App\Services\QueriesV2Manager;
  13. use App\Repository\AccountingFirmRepository;
  14. use App\Repository\Actuv2BienetreRepository;
  15. use App\Repository\Actuv2InfographieRseRepository;
  16. use App\Repository\Actuv2PodcastRepository;
  17. use App\Repository\Actuv2TransformationdigitaleRepository;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use App\Repository\AuthorizedDomainRepository;
  20. use App\Services\WidgetMailing;
  21. use DateTimeImmutable;
  22. use Doctrine\ORM\EntityManagerInterface;
  23. use App\Repository\PodcastEpisodeRepository;
  24. use GuzzleHttp\Client;
  25. use Symfony\Component\HttpFoundation\Response;
  26. use Symfony\Component\Routing\Annotation\Route;
  27. use Symfony\Component\HttpFoundation\JsonResponse;
  28. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  29. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  30. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  31. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  32. class WidgetActuController extends AbstractController
  33. {
  34.     #[Route(path'/check-widget-actu'name'check_Widget_actu')]
  35.     public function checkWidgetActu(Request $requestAccountingFirmRepository $repositorystring $prefix null): JsonResponse
  36.     {
  37.         $token $request->query->get('token');
  38.         $host $request->query->get('host');
  39.         if ($token && $host) {
  40.             $accountingFirm $repository->findOneBy(['actuv2Token' => $token]);
  41.             $isAuthorized false;
  42.             if ($accountingFirm && in_array($host$accountingFirm->getListAuthorizedDomains())) {
  43.                 $isAuthorized true;
  44.             }
  45.             $url $isAuthorized $accountingFirm->getActuv2Widgeturl() : null;
  46.         } else {
  47.             $accountingFirm $repository->findOneBy(['host' => $host]);
  48.             $url $accountingFirm $prefix $this->generateUrl('widget_actu_home') : null;
  49.         }
  50.         return $this->json($url);
  51.     }
  52.     #[Route(path'/widget-actu'name'widget_actu_home')]
  53.     public function widgetHome(Request $requestQueriesV2Manager $qmAccountingFirmRepository $repositoryAuthorizedDomainRepository $domainsWebSite $sitePodcastPrivateRepository $podcastPrivateRepositoryActuv2InfographieRseRepository $actuv2InfographieRseRepositoryActuv2TransformationdigitaleRepository $actuv2TransformationdigitaleRepositoryActuv2BienetreRepository $actuv2BienetreRepositoryActuv2PodcastRepository $actuv2PodcastRepositoryHelpersFirmsService $helpersFirmsService): Response
  54.     {
  55.         $token $request->query->get('token');
  56.         $host $request->get('host');
  57.         $host str_replace('www.'''$host);
  58.         if ($host != "preview") {
  59.             $accountingFirm $repository->findOneBy(['actuv2Token' => $token]);
  60.             //dd($accountingFirm);
  61.             if (is_null($accountingFirm)) {
  62.                 $domains $domains->findBy(['name' => $host]);
  63.                 if (is_null($domains)) {
  64.                     throw new NotFoundHttpException();
  65.                 }
  66.                 foreach ($domains as $dom) {
  67.                     $tmp_ac $dom->getAccountingFirm();
  68.                     if ($tmp_ac->getActuv2Token() == $token) {
  69.                         $accountingFirm $tmp_ac;
  70.                         break;
  71.                     }
  72.                 }
  73.             }
  74.             if (is_null($accountingFirm)) {
  75.                 throw new NotFoundHttpException();
  76.             }
  77.         }
  78.         $date $request->query->get('date'false);
  79.         $this->templateBase '/';
  80.         $sondage $qm->getSondage($date);
  81.         $template null;
  82.         $renderparams = [];
  83.         $p $request->getRequestUri();
  84.         $pos strpos($p'?');
  85.         if ($pos !== false) {
  86.             $p substr($p0$pos 1) . str_replace('?''&'substr($p$pos 1));
  87.         }
  88.         $route parse_url($p);
  89.         if (isset($route['query'])) {
  90.             parse_str($route['query'], $query);
  91.             $page = isset($query['p']) ? $query['p'] : null;
  92.             $id = isset($query['id']) ? $query['id'] : null;
  93.             $search = isset($query['q']) ? $query['q'] : null;
  94.             $date = isset($query['date']) ? $query['date'] : null;
  95.             if ($accountingFirm->isActuv2OnlyPodcast()) {
  96.                 $page 'podcast.php';
  97.                 if (!$id) {
  98.                     $id 'detail';
  99.                 }
  100.             }
  101.             if (!empty($page) && !is_null($page)) {
  102.                 switch ($page) {
  103.                     case 'transformation-digitale.php':
  104.                         $template 'widget_actu_juridique_v2/details-transformation-digitale.html.twig';
  105.                         if (isset($id)) {
  106.                             $data $actuv2TransformationdigitaleRepository->findOneBy(['id' => $id]);
  107.                         } else {
  108.                             $data $qm->getTransformationDigitale($date);
  109.                         }
  110.                         $actus $qm->getActualites();
  111.                         $footer $qm->getFooterData();
  112.                         $histo $qm->getHistoTransfo();
  113.                         $hasVoteUseful $qm->hasVoteUseful($id'transformation-digitale.php');
  114.                         $renderparams = [
  115.                             'data' => $data,
  116.                             'actus' => array_chunk($actus3),
  117.                             'footer' => $footer,
  118.                             'help' => $qm->getHelp(),
  119.                             'histo' => $histo,
  120.                             'hasVoteUseful' => $hasVoteUseful
  121.                         ];
  122.                         break;
  123.                     case 'journal.php':
  124.                         $template 'widget_actu_juridique_v2/details-journal.html.twig';
  125.                         if (isset($id)) {
  126.                             $data $qm->getJournalDetails($id);
  127.                         } else {
  128.                             $data $qm->getJournal($date);
  129.                         }
  130.                         $footer $qm->getFooterData();
  131.                         $renderparams = [
  132.                             'data' => $data,
  133.                             'footer' => $footer,
  134.                             'help' => $qm->getHelp(),
  135.                         ];
  136.                         break;
  137.                     case 'calendrier-fiscal.php':
  138.                         if (!empty($id) && !is_null($id)) {
  139.                             $template 'widget_actu_juridique_v2/details-calendrier.html.twig';
  140.                             $data $qm->getCalendrierDetails($id);
  141.                             $nextEvent $qm->getNextEvent();
  142.                             $actus $qm->getActualites();
  143.                             $footer $qm->getFooterData();
  144.                             $renderparams = [
  145.                                 'footer' => $footer,
  146.                                 'help' => $qm->getHelp(),
  147.                                 'data' => $data,
  148.                                 'actus' => array_chunk($actus3),
  149.                                 'nextEvent' => $nextEvent,
  150.                             ];
  151.                         }
  152.                         break;
  153.                     case 'actualites-calendrier-fiscal.php':
  154.                         if (!empty($date) && !is_null($date)) {
  155.                             $template 'widget_actu_juridique_v2/liste-calendrier.html.twig';
  156.                             $data $qm->getCalendrierListe($date);
  157.                             $nextEvent $qm->getNextEvent();
  158.                             $footer $qm->getFooterData();
  159.                             try {
  160.                                 $dateActus = (new DateTime($date))->format("d/m/Y");
  161.                             } catch (Exception $e) {
  162.                                 throw $e;
  163.                             }
  164.                             $renderparams = [
  165.                                 'footer' => $footer,
  166.                                 'help' => $qm->getHelp(),
  167.                                 'data' => $data,
  168.                                 'dateActus' => $dateActus,
  169.                                 'nextEvent' => $nextEvent,
  170.                             ];
  171.                         }
  172.                         break;
  173.                     case 'actualite.php':
  174.                         if (!empty($id) && !is_null($id)) {
  175.                             $template 'widget_actu_juridique_v2/details-actu.html.twig';
  176.                             $footer $qm->getFooterData();
  177.                             $data $qm->getActualitesDetails($id);
  178.                             $nextEvent $qm->getNextEvent();
  179.                             $actus $qm->getActualites();
  180.                             $histo $qm->getHistoActualites();
  181.                             $hasVoteUseful $qm->hasVoteUseful($id'actualite.php');
  182.                             $renderparams = [
  183.                                 'footer' => $footer,
  184.                                 'help' => $qm->getHelp(),
  185.                                 'data' => $data,
  186.                                 'actus' => array_chunk($actus3),
  187.                                 'nextEvent' => $nextEvent,
  188.                                 'histo' => $histo,
  189.                                 'hasVoteUseful' => $hasVoteUseful
  190.                             ];
  191.                         }
  192.                         break;
  193.                     case 'bien-etre.php':
  194.                         $template 'widget_actu_juridique_v2/details-bien-etre.html.twig';
  195.                         if (isset($id)) {
  196.                             $data $actuv2BienetreRepository->findOneBy(['id' => $id]);
  197.                         } else {
  198.                             $data $qm->getBienEtre($date);
  199.                         }
  200.                         $actus $qm->getActualites();
  201.                         $nextEvent $qm->getNextEvent();
  202.                         $footer $qm->getFooterData();
  203.                         $histo $qm->getHistoBienEtre();
  204.                         $hasVoteUseful $qm->hasVoteUseful($id'bien-etre.php');
  205.                         $renderparams = [
  206.                             'footer' => $footer,
  207.                             'help' => $qm->getHelp(),
  208.                             'data' => $data,
  209.                             'actus' => array_chunk($actus3),
  210.                             'nextEvent' => $nextEvent,
  211.                             'histo' => $histo,
  212.                             'hasVoteUseful' => $hasVoteUseful
  213.                         ];
  214.                         break;
  215.                     case 'actualite-cabinet.php':
  216.                         if (!empty($id) && !is_null($id)) {
  217.                             $template 'widget_actu_juridique_v2/details-actu-cabinet.html.twig';
  218.                             $footer $qm->getFooterData();
  219.                             $data $qm->getActualiteCabinetDetails($id);
  220.                             $nextEvent $qm->getNextEvent();
  221.                             $actus $qm->getActualites();
  222.                             $hasVoteUseful $qm->hasVoteUseful($id'actualite-cabinet.php');
  223.                             $renderparams = [
  224.                                 'footer' => $footer,
  225.                                 'help' => $qm->getHelp(),
  226.                                 'data' => $data,
  227.                                 'actus' => array_chunk($actus3),
  228.                                 'nextEvent' => $nextEvent,
  229.                                 'hasVoteUseful' => $hasVoteUseful
  230.                             ];
  231.                         }
  232.                         break;
  233.                     case 'recherche.php':
  234.                         if (!empty($search) && !is_null($search)) {
  235.                             $template 'widget_actu_juridique_v2/liste-recherche.html.twig';
  236.                             $data $qm->search($search);
  237.                             $footer $qm->getFooterData();
  238.                             $renderparams = [
  239.                                 'footer' => $footer,
  240.                                 'listResults' => $data,
  241.                                 'recherche' => $search,
  242.                             ];
  243.                         }
  244.                         break;
  245.                     case 'participation.php':
  246.                         $template 'widget_actu_juridique_v2/participation.html.twig';
  247.                         $nextEvent $qm->getNextEvent();
  248.                         $footer $qm->getFooterData();
  249.                         $renderparams = [
  250.                             'footer' => $footer,
  251.                             'help' => $qm->getHelp(),
  252.                         ];
  253.                         break;
  254.                     case 'infographie-rse.php':
  255.                         $template 'widget_actu_juridique_v2/infographie-rse.html.twig';
  256.                         if (isset($id)) {
  257.                             $infographie $actuv2InfographieRseRepository->findOneBy(['id' => $id]);
  258.                         } else {
  259.                             $infographie $qm->getInfographie($date);
  260.                         }
  261.                         $footer $qm->getFooterData();
  262.                         $infographieArchivage $actuv2InfographieRseRepository->findAll();
  263.                         $renderparams = [
  264.                             'infographie' => $infographie,
  265.                             'footer' => $footer,
  266.                             'help' => $qm->getHelp(),
  267.                             'archivages' => $infographieArchivage,
  268.                         ];
  269.                         break;
  270.                     case 'calendrier-juridique.php':
  271.                         $template 'widget_actu_juridique_v2/calendrier-juridique.html.twig';
  272.                         $footer $qm->getFooterData();
  273.                         $renderparams = [
  274.                             'nextEvent' => $qm->getNextEvent(),
  275.                             'footer' => $footer,
  276.                             'help' => $qm->getHelp(),
  277.                         ];
  278.                         break;
  279.                     case 'podcast.php':
  280.                         $template 'widget_actu_juridique_v2/podcast-detail.html.twig';
  281.                         if ($id) {
  282.                             if ($id == 'detail') {
  283.                                 $podcast $qm->getPodcast($date);
  284.                             } else {
  285.                                 $podcast $podcastPrivateRepository->findOneBy(['id' => $id]);
  286.                             }
  287.                         } else {
  288.                             $podcast 'list';
  289.                         }
  290.                         $podcasts $qm->getPodcastsObjects($date);
  291.                         // $podcasts = [];
  292.                         // foreach ($episodes as $episode) {
  293.                         //     // Stocker chaque épisode dans le nouvel array $episodes
  294.                         //     $podcasts[] = $episode->getPodcastEpisode();
  295.                         // }
  296.                         if ($podcast != "list") {
  297.                             $idAusha null;
  298.                             if ($podcast->getIdAushaEpisodeEc()) {
  299.                                 $idAusha $podcast->getIdAushaEpisodeEc();
  300.                             }
  301.                             $truncate $podcast->getSubDescriptionTxt();
  302.                             $chars 550;
  303.                             if (strlen($truncate) > $chars) {
  304.                                 $truncate html_entity_decode($truncate) . " ";
  305.                                 $truncate substr($truncate0$chars);
  306.                                 $truncate substr($truncate0strrpos($truncate' '));
  307.                                 $truncate $truncate "...";
  308.                             } else {
  309.                                 $truncate null;
  310.                             }
  311.                             $renderparams = [
  312.                                 'podcast' => $podcast,
  313.                                 'idAusha' => $idAusha,
  314.                                 'truncate' => $truncate,
  315.                                 'episodes' => $podcasts,
  316.                                 'origin' => 'actu_mois'
  317.                             ];
  318.                         } else {
  319.                             $renderparams = [
  320.                                 'podcast' => $podcast,
  321.                                 'episodes' => $podcasts,
  322.                                 'origin' => 'actu_mois'
  323.                             ];
  324.                         }
  325.                         break;
  326.                     case 'podcast-latest.php':
  327.                         $template 'widget_actu_juridique_v2/podcast-detail.html.twig';
  328.                         $podcast $qm->getPodcastLatest();
  329.                         $podcasts $qm->getPodcastsObjects($date);
  330.                         $renderparams = [
  331.                             'podcast' => $podcast[0],
  332.                             'episodes' => $podcasts,
  333.                             'origin' => 'actu_mois'
  334.                         ];
  335.                         break;
  336.                     case 'aide.php':
  337.                         $template 'widget_actu_juridique_v2/aide.html.twig';
  338.                         $helper $qm->getHelpById($id);
  339.                         $footer $qm->getFooterData();
  340.                         $territoires $helpersFirmsService->getTerritoiresFromContactsHelper($helper['help']['cache_indexation']['contacts']);
  341.                         $renderparams = [
  342.                             'helper' => $helper,
  343.                             'footer' => $footer,
  344.                             'help' => $qm->getHelp(),
  345.                             'territoires' => $territoires,
  346.                         ];
  347.                         break;
  348.                     default:
  349.                         // NOPE
  350.                         break;
  351.                 }
  352.             } else {
  353.                 $template 'widget_actu_juridique_v2/home.html.twig';
  354.                 $aj['calendrier'] = $qm->getDates();
  355.                 $nextEvent $qm->getNextEvent();
  356.                 //$actus = $qm->getActualites();
  357.                 $footer $qm->getFooterData($date);
  358.                 $quizrh $qm->getQuizRh($date);
  359.                 $quizrhVote $qm->getQuizRhVote($date);
  360.                 $podcast $qm->getPodcast($date);
  361.                 $idAusha null;
  362.                 if ($podcast->getIdAushaEpisodeEc()) {
  363.                     $idAusha $podcast->getIdAushaEpisodeEc();
  364.                 }
  365.                 $renderparams = [
  366.                     'actus' => $qm->getActualites($date),
  367.                     'transformationDigitale' => $qm->getTransformationDigitale($date),
  368.                     'infographie' => $qm->getInfographie($date),
  369.                     'chiffreDuMois' => $qm->getChiffreDuMois($date),
  370.                     'citation' => $qm->getCitation($date),
  371.                     'help' => $qm->getHelp($date),
  372.                     'bienEtre' => $qm->getBienEtre($date),
  373.                     'podcast' => $podcast,
  374.                     'idAusha' => $idAusha,
  375.                     'episodes' => $qm->getPodcastsObjects($date),
  376.                     'sondage' => [
  377.                         'details' => $sondage,
  378.                         'results' => $sondage $qm->getSondageResult($sondage['id']) : null,
  379.                     ],
  380.                     'nextEvent' => $qm->getNextEvent(),
  381.                     'previousPerdiods' => $qm->getPreviousPeriods(),
  382.                     'quizrh' => $quizrh,
  383.                     'quizrhVote' => $quizrhVote,
  384.                     'quizElectronicInvoices' => $qm->getQuizElectronicInvoice($date),
  385.                     'quizElectronicInvoicesVote' => $qm->getQuizElectronicInvoiceVote($date),
  386.                     'origin' => 'actu_mois',
  387.                     'nofooter' => true,
  388.                 ];
  389.             }
  390.             $renderparams['test'] = $request->getRequestUri();
  391.         } else {
  392.             $template 'widget_actu_juridique_v2/home.html.twig';
  393.             $aj['calendrier'] = $qm->getDates();
  394.             $nextEvent $qm->getNextEvent();
  395.             //$actus = $qm->getActualites();
  396.             $footer $qm->getFooterData($date);
  397.             $quizrh $qm->getQuizRh($date);
  398.             $quizrhVote $qm->getQuizRhVote($date);
  399.             $podcast $qm->getPodcast($date);
  400.             $idAusha null;
  401.             if ($podcast->getIdAushaEpisodeEc()) {
  402.                 $idAusha $podcast->getIdAushaEpisodeEc();
  403.             }
  404.             $renderparams = [
  405.                 'actus' => $qm->getActualites($date),
  406.                 'transformationDigitale' => $qm->getTransformationDigitale($date),
  407.                 'infographie' => $qm->getInfographie($date),
  408.                 'chiffreDuMois' => $qm->getChiffreDuMois($date),
  409.                 'citation' => $qm->getCitation($date),
  410.                 'bienEtre' => $qm->getBienEtre($date),
  411.                 'podcast' => $podcast,
  412.                 'idAusha' => $idAusha,
  413.                 'episodes' => $qm->getPodcastsObjects($date),
  414.                 'sondage' => [
  415.                     'details' => $sondage,
  416.                     'results' => $sondage $qm->getSondageResult($sondage['id']) : null,
  417.                 ],
  418.                 'nextEvent' => $qm->getNextEvent(),
  419.                 'previousPerdiods' => $qm->getPreviousPeriods(),
  420.                 'quizrh' => $quizrh,
  421.                 'quizrhVote' => $quizrhVote,
  422.                 'quizElectronicInvoices' => $qm->getQuizElectronicInvoice($date),
  423.                 'quizElectronicInvoicesVote' => $qm->getQuizElectronicInvoiceVote($date),
  424.                 'origin' => 'actu_mois',
  425.                 'nofooter' => true,
  426.             ];
  427.         }
  428.         $renderparams['socialSharingPage'] = $request->getUri();
  429.         $renderparams['getParams'] = $_GET;
  430.         $renderparams['cabinet'] = $accountingFirm;
  431.         $renderparams['cabinetWidgetUrl'] = $accountingFirm->getActuv2Widgeturl();
  432.         $renderparams['serverActuUrl'] = $site->getServerActuUrl();
  433. //        $renderparams['serverActuUrl'] = "http://actucontent.loc:8080";  // test line
  434.         $renderparams['serverUrl'] = "https://actucontent.lagence.expert";
  435. //         $renderparams['serverUrl'] = "http://agex-w-actu.loc:8000";
  436.         return $this->render($template$renderparams);
  437.     }
  438.     #[Route(path'/widget-footer'name'widget_actu_footer')]
  439.     public function footer(Request $requestAccountingFirmRepository $repositoryQueriesV2Manager $qmWebSite $siteAuthorizedDomainRepository $domains): Response
  440.     {
  441.         $token $request->query->get('token');
  442.         $host $request->get('host');
  443.         if ($host != "preview") {
  444.             $accountingFirm $repository->findOneBy(['host' => $host]);
  445.             if (is_null($accountingFirm)) {
  446.                 $domains $domains->findBy(['name' => $host]);
  447.                 if (is_null($domains)) {
  448.                     throw new NotFoundHttpException();
  449.                 }
  450.                 foreach ($domains as $dom) {
  451.                     $tmp_ac $dom->getAccountingFirm();
  452.                     if ($tmp_ac->getActuv2Token() == $token) {
  453.                         $accountingFirm $tmp_ac;
  454.                         break;
  455.                     }
  456.                 }
  457.             }
  458.             if (is_null($accountingFirm)) {
  459.                 throw new NotFoundHttpException();
  460.             }
  461.         }
  462.         $podcast $qm->getPodcast();
  463.         $idAusha null;
  464.         if ($podcast->getIdAushaEpisodeEc()) {
  465.             $idAusha $podcast->getIdAushaEpisodeEc();
  466.         }
  467.         $podcasts = [];
  468.         if ($accountingFirm->isActuv2OnlyPodcast()) {
  469.             $podcasts $qm->getPodcastsObjects();
  470.         }
  471.         $this->templateBase '/';
  472.         return $this->render('widget_actu_juridique_v2/widget-footer.html.twig', [
  473.             'cabinet' => $accountingFirm,
  474.             'footer' => $qm->getFooterData(),
  475.             'episodes' => $podcasts,
  476.             'serverActuUrl' => $site->getServerActuUrl(),
  477.             'cabinetWidgetUrl' => $accountingFirm->getActuv2Widgeturl(),
  478.             'origin' => "actu_mois",
  479.             'podcast' => $podcast,
  480.             'idAusha' => $idAusha,
  481.             'help' => $qm->getHelp(),
  482.             // 'serverActuUrl' => "http://actucontent.loc:8000" // test line
  483.         ]);
  484.     }
  485.     #[Route(path'/widget-actu-primary'name'widget_actu_primary')]
  486.     public function widgetActuPrimary(Request $requestAccountingFirmRepository $repositoryQueriesV2Manager $qmWebSite $siteAuthorizedDomainRepository $domains): Response
  487.     {
  488.         $token $request->query->get('token');
  489.         $host $request->get('host');
  490.         if ($host != "preview") {
  491.             $accountingFirm $repository->findOneBy(['host' => $host]);
  492.             if (is_null($accountingFirm)) {
  493.                 $domains $domains->findBy(['name' => $host]);
  494.                 if (is_null($domains)) {
  495.                     throw new NotFoundHttpException();
  496.                 }
  497.                 foreach ($domains as $dom) {
  498.                     $tmp_ac $dom->getAccountingFirm();
  499.                     if ($tmp_ac->getActuv2Token() == $token) {
  500.                         $accountingFirm $tmp_ac;
  501.                         break;
  502.                     }
  503.                 }
  504.             }
  505.             if (is_null($accountingFirm)) {
  506.                 throw new NotFoundHttpException();
  507.             }
  508.         }
  509.         $this->templateBase '/';
  510.         $p $request->getRequestUri();
  511.         $pos strpos($p'?');
  512.         if ($pos !== false) {
  513.             $p substr($p0$pos 1) . str_replace('?''&'substr($p$pos 1));
  514.         }
  515.         $route parse_url($p);
  516.         $date null;
  517.         if (isset($route['query'])) {
  518.             parse_str($route['query'], $query);
  519.             $date $query['date'] ?? null;
  520.         }
  521.         return $this->render('widget_actu_juridique_v2/widget-actu-primary.html.twig', [
  522.             'cabinet' => $accountingFirm,
  523.             'serverActuUrl' => $site->getServerActuUrl(),
  524.             'cabinetWidgetUrl' => $accountingFirm->getActuv2Widgeturl(),
  525.             'origin' => "actu_mois",
  526.             'actus' => $qm->getActualites($date),
  527.             // 'serverActuUrl' => "http://actucontent.loc:8000" // test line
  528.         ]);
  529.     }
  530.     #[Route(path'/widget-sondage'name'widget_sondage')]
  531.     public function widgetSondage(Request $requestAccountingFirmRepository $repositoryQueriesV2Manager $qmWebSite $siteAuthorizedDomainRepository $domains): Response
  532.     {
  533.         $token $request->query->get('token');
  534.         $host $request->get('host');
  535.         if ($host != "preview") {
  536.             $accountingFirm $repository->findOneBy(['host' => $host]);
  537.             if (is_null($accountingFirm)) {
  538.                 $domains $domains->findBy(['name' => $host]);
  539.                 if (is_null($domains)) {
  540.                     throw new NotFoundHttpException();
  541.                 }
  542.                 foreach ($domains as $dom) {
  543.                     $tmp_ac $dom->getAccountingFirm();
  544.                     if ($tmp_ac->getActuv2Token() == $token) {
  545.                         $accountingFirm $tmp_ac;
  546.                         break;
  547.                     }
  548.                 }
  549.             }
  550.             if (is_null($accountingFirm)) {
  551.                 throw new NotFoundHttpException();
  552.             }
  553.         }
  554.         $this->templateBase '/';
  555.         $p $request->getRequestUri();
  556.         $pos strpos($p'?');
  557.         if ($pos !== false) {
  558.             $p substr($p0$pos 1) . str_replace('?''&'substr($p$pos 1));
  559.         }
  560.         $route parse_url($p);
  561.         $date null;
  562.         if (isset($route['query'])) {
  563.             parse_str($route['query'], $query);
  564.             $date $query['date'] ?? null;
  565.         }
  566.         $sondage $qm->getSondage($date);
  567.         return $this->render('widget_actu_juridique_v2/widget-sondage.html.twig', [
  568.             'cabinet' => $accountingFirm,
  569.             'serverActuUrl' => $site->getServerActuUrl(),
  570.             'cabinetWidgetUrl' => $accountingFirm->getActuv2Widgeturl(),
  571.             'origin' => "actu_mois",
  572.             'sondage' => [
  573.                 'details' => $sondage,
  574.                 'results' => is_null($sondage) ? null $qm->getSondageResult($sondage['id']),
  575.             ],
  576.             // 'serverActuUrl' => "http://actucontent.loc:8000" // test line
  577.         ]);
  578.     }
  579.     #[Route(path'/widget-podcast'name'widget_podcast')]
  580.     public function widgetPodcast(Request $requestAccountingFirmRepository $repositoryQueriesV2Manager $qmWebSite $siteAuthorizedDomainRepository $domains): Response
  581.     {
  582.         $token $request->query->get('token');
  583.         $host $request->get('host');
  584.         if ($host != "preview") {
  585.             $accountingFirm $repository->findOneBy(['host' => $host]);
  586.             if (is_null($accountingFirm)) {
  587.                 $domains $domains->findBy(['name' => $host]);
  588.                 if (is_null($domains)) {
  589.                     throw new NotFoundHttpException();
  590.                 }
  591.                 foreach ($domains as $dom) {
  592.                     $tmp_ac $dom->getAccountingFirm();
  593.                     if ($tmp_ac->getActuv2Token() == $token) {
  594.                         $accountingFirm $tmp_ac;
  595.                         break;
  596.                     }
  597.                 }
  598.             }
  599.             if (is_null($accountingFirm)) {
  600.                 throw new NotFoundHttpException();
  601.             }
  602.         }
  603.         $this->templateBase '/';
  604.         $p $request->getRequestUri();
  605.         $pos strpos($p'?');
  606.         if ($pos !== false) {
  607.             $p substr($p0$pos 1) . str_replace('?''&'substr($p$pos 1));
  608.         }
  609.         $route parse_url($p);
  610.         $date null;
  611.         if (isset($route['query'])) {
  612.             parse_str($route['query'], $query);
  613.             $date $query['date'] ?? null;
  614.         }
  615.         $podcast $qm->getPodcast($date);
  616.         $idAusha null;
  617.         if ($podcast->getIdAushaEpisodeEc()) {
  618.             $idAusha $podcast->getIdAushaEpisodeEc();
  619.         }
  620.         return $this->render('widget_actu_juridique_v2/widget-podcast.html.twig', [
  621.             'cabinet' => $accountingFirm,
  622.             'serverActuUrl' => $site->getServerActuUrl(),
  623.             'cabinetWidgetUrl' => $accountingFirm->getActuv2Widgeturl(),
  624.             'origin' => "actu_mois",
  625.             'podcast' => $podcast,
  626.             'idAusha' => $idAusha,
  627.             // 'serverActuUrl' => "http://actucontent.loc:8000" // test line
  628.         ]);
  629.     }
  630.     #[Route(path'/widget-quizz'name'widget_quizz')]
  631.     public function widgetQuizz(Request $requestAccountingFirmRepository $repositoryQueriesV2Manager $qmWebSite $siteAuthorizedDomainRepository $domains): Response
  632.     {
  633.         $token $request->query->get('token');
  634.         $host $request->get('host');
  635.         if ($host != "preview") {
  636.             $accountingFirm $repository->findOneBy(['host' => $host]);
  637.             if (is_null($accountingFirm)) {
  638.                 $domains $domains->findBy(['name' => $host]);
  639.                 if (is_null($domains)) {
  640.                     throw new NotFoundHttpException();
  641.                 }
  642.                 foreach ($domains as $dom) {
  643.                     $tmp_ac $dom->getAccountingFirm();
  644.                     if ($tmp_ac->getActuv2Token() == $token) {
  645.                         $accountingFirm $tmp_ac;
  646.                         break;
  647.                     }
  648.                 }
  649.             }
  650.             if (is_null($accountingFirm)) {
  651.                 throw new NotFoundHttpException();
  652.             }
  653.         }
  654.         $this->templateBase '/';
  655.         $p $request->getRequestUri();
  656.         $pos strpos($p'?');
  657.         if ($pos !== false) {
  658.             $p substr($p0$pos 1) . str_replace('?''&'substr($p$pos 1));
  659.         }
  660.         $route parse_url($p);
  661.         $date null;
  662.         if (isset($route['query'])) {
  663.             parse_str($route['query'], $query);
  664.             $date $query['date'] ?? null;
  665.         }
  666.         $quizrh $qm->getQuizRh($date);
  667.         $quizrhVote $qm->getQuizRhVote($date);
  668.         return $this->render('widget_actu_juridique_v2/widget-quizz.html.twig', [
  669.             'cabinet' => $accountingFirm,
  670.             'serverActuUrl' => $site->getServerActuUrl(),
  671.             'cabinetWidgetUrl' => $accountingFirm->getActuv2Widgeturl(),
  672.             'origin' => "actu_mois",
  673.             'quizrh' => $quizrh,
  674.             'quizrhVote' => $quizrhVote,
  675.             // 'serverActuUrl' => "http://actucontent.loc:8000" // test line
  676.         ]);
  677.     }
  678.     #[Route(path'/get-audio-ausha'name'w_actu_get_audio_ausha')]
  679.     #[Route(path'/js/agex-actus-juridiques.min.js'name'w_actu_embed_old')]
  680.     public function getAudioAusha(Request $request)
  681.     {
  682.         $aushaId $request->query->get('aushaid');
  683.         $aushaToken "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjczOTY4MjQ2MjU3NzJkYzA2M2ZkMTgyMzVlYzY4ZmFkZWE4MDNhMGI2NzI1NjQ1YzJkODEwM2E2YWYyMTMxZTJkZDZkYjU1NTMyMWQzM2NkIn0.eyJhdWQiOiIxIiwianRpIjoiNzM5NjgyNDYyNTc3MmRjMDYzZmQxODIzNWVjNjhmYWRlYTgwM2EwYjY3MjU2NDVjMmQ4MTAzYTZhZjIxMzFlMmRkNmRiNTU1MzIxZDMzY2QiLCJpYXQiOjE2NjMxNTQ4MTUsIm5iZiI6MTY2MzE1NDgxNSwiZXhwIjo3OTUyNDI4Nzk5LCJzdWIiOiIxMTMwNzEiLCJzY29wZXMiOlsic2hvd3MuaW5kZXhXaXRoR3JhbnRlZCIsInNob3dzLnNob3ciLCJzaG93cy5zaG93LmJ5X3B1YmxpY2lkIiwicGxheWxpc3RzLmluZGV4IiwicGxheWxpc3RzLnN0b3JlIiwicGxheWxpc3RzLnNob3ciLCJwbGF5bGlzdHMudXBkYXRlIiwicGxheWxpc3RzLmRlc3Ryb3kiLCJwbGF5bGlzdHMucG9kY2FzdC5zdG9yZSIsInBsYXlsaXN0cy5wb2RjYXN0LmRlc3Ryb3kiLCJwbGF5bGlzdHMucG9kY2FzdC5tb3ZlIiwicGxheWxpc3RzLmltYWdlLnN0b3JlIiwicGxheWxpc3RzLmltYWdlLmRlc3Ryb3kiLCJwb2RjYXN0cy52aWRlby5pbmRleCIsInBvZGNhc3RzLnZpZGVvLnNob3ciLCJzZWFzb25zLmluZGV4Iiwic2Vhc29ucy5zdG9yZSIsInNlYXNvbnMuc2hvdyIsInNlYXNvbnMuZGVzdHJveSIsInNob3dzLnBvZGNhc3RzLnNlYXNvbi51cGRhdGUiLCJjYW1wYWlnbnMuaW5kZXgiLCJjYW1wYWlnbnMuc2hvdyIsInBvZGNhc3RzLmluZGV4IiwicG9kY2FzdHMuc2hvdyIsInBvZGNhc3RzLnNob3cuYnlfcHVibGljaWQiLCJwb2RjYXN0cy5zdG9yZSIsInBvZGNhc3RzLnVwZGF0ZSIsInBvZGNhc3RzLmRlc3Ryb3kiLCJwb2RjYXN0cy5pbWFnZS5zdG9yZSIsInBvZGNhc3RzLmZpbGUuc3RvcmUiXX0.uWgOLN2_5LAKL9gB0Ij8V5PJjKrwRqAO_wVZ4l0vV73QPPF4MUDUzsYU-1hL4iFFPWanhg018EH_AGZvGdSdrZXqkzBPnqv6TxhL9aCVeayVwvgD-BQwPMJ3E7z27xREEhXH_r6f0d2t_J6SJexVh3AoT8fD2kUyFXh9B95ziWV-vULeHOqtWEZk01YctUyHLFWhIFzajgn8nSHb3hMYfbV4phapZqaegwCBSIxVPJz4yS3Ox0tbI5g-P6fAK5PlE1pKiPXabekYyUN4tPEmpMAQVURM3xcutBXUTMX0H6GCs0ih7KH3cI8SICVrldo3LkbAh8x4uuJJu2aNmv9qHpyxLi9wfmklyWMt0ROuf4dHPiDVLUfwmqnt9UEE4H5jP7hHcrMNCIRzerBgW0cCfKj0wJBtOuYpsqqBou2YTEyYja8uNEQbHpOQT4gT7CJxa575kqKsrTr9tS2k19BPdlxtBoIPQHcVpY9tQ1_TJro72kbE1ooJICZyFYTdHHPX77H4LClYcN4TxHxp8jTp6hXt_BjZbwU7Kl2PIxFV1diK62idKCtBjd_tvnUIuh7sKZeGn-YwCYVZVWRblYmZQ3tmPyje1ZJsgnY_nZIZ1TBwzZf3ucuPRxJJ4vPc3dXkxvLtWUs3bLWnACHCjhRA7LfMNDIlAZoRKHKQI6UNuiE";
  684.         $client = new Client(['base_uri' => 'https://developers.ausha.co/v1/podcasts/']);
  685.         $headers = [
  686.             'Authorization' => 'Bearer ' $aushaToken,
  687.             'accept' => 'application/json',
  688.             'content-type' => 'application/json',
  689.         ];
  690.         $ausha_mp3 null;
  691.         $logFile '../log_ausha.txt';
  692.         $origin "PODCAST_PRIVATE_WidgetPodcastPrivateController";
  693.         $url $aushaId;
  694.         $date = (new \DateTime())->format('Y-m-d H:i:s');
  695.         file_put_contents($logFile"[$date] - origin => $origin - avant appel API\n"FILE_APPEND);
  696.         try {
  697.             $response $client->request('GET'$aushaId, [
  698.                 'headers' => $headers
  699.             ]);
  700.             file_put_contents($logFile"[$date] - origin => $origin - après appel API\n"FILE_APPEND);
  701.             if ($response->getStatusCode() === 200) {
  702.                 file_put_contents($logFile"succès à l'URL : $url\n"FILE_APPEND);
  703.                 $ausha json_decode($response->getBody()->getContents());
  704.                 if ($ausha->data->audio_url) {
  705.                     $ausha_mp3 $ausha->data->audio_url;
  706.                 }
  707.             }
  708.         } catch (\Exception $e) {
  709.             file_put_contents($logFile"[$date] - origin => $origin - après appel API\n"FILE_APPEND);
  710.             file_put_contents($logFile$e->getCode() . " - " $e->getMessage() . "\n"FILE_APPEND);
  711.         }
  712.         file_put_contents($logFile"--\n"FILE_APPEND);
  713.         return new JsonResponse([
  714.             'ausha_mp3' => $ausha_mp3
  715.         ]);
  716.     }
  717.     #[Route(path'/embed'name'w_actu_embed')]
  718.     #[Route(path'/js/agex-actus-juridiques.min.js'name'w_actu_embed_old')]
  719.     public function embed(Request $requestAccountingFirmRepository $repository)
  720.     {
  721.         $root $this->getParameter('kernel.project_dir');
  722.         $path $root '/public/widgets/actus-juridique/widget_actu.js';
  723.         $response = new BinaryFileResponse($path);
  724.         $response->headers->set('Content-Type''text/javascript');
  725.         return $response;
  726.     }
  727.     #[Route(path'/{filename}.{format}'name'w_actu_files')]
  728.     public function actu_files(Request $requeststring $filenamestring $format)
  729.     {
  730.         $allowed = array('png''jpg''jpeg''gif''js''svg''eot''ttf''woff');
  731.         if (in_array($format$allowed)) {
  732.             $root $this->getParameter('kernel.project_dir');
  733.             $path $root '/public/widgets/actus-juridique/' $filename '.' $format;
  734.             //dd(file_exists($path), $path, $request->getRequestFormat());
  735.             return new BinaryFileResponse($path);
  736.         }
  737.         return false;
  738.     }
  739.     #[Route(path'/widget-dates'name'widget_actu_dates')]
  740.     public function dates(QueriesV2Manager $qm)
  741.     {
  742.         $tabData $qm->getDates();
  743.         $tabDates = [];
  744.         foreach ($tabData as $lignes) {
  745.             foreach ($lignes as $ligne) {
  746.                 $key array_search($ligne['date'], array_column($tabDates'date'));
  747.                 if ($key === false) { // cas date jamais ajoutée
  748.                     $tabDates[] = ['date' => $ligne['date'], 'lien' => 'calendrier-fiscal.php?id=' $ligne['id']];
  749.                 } else { // cas date déjà ajoutée, donc plusieurs articles à la même date
  750.                     $tabDates[$key] = ['date' => $ligne['date'], 'lien' => 'actualites-calendrier-fiscal.php?date=' $ligne['date']];
  751.                 }
  752.             }
  753.         }
  754.         return $this->json($tabDates);
  755.     }
  756.     #[Route(path'/api/vote/'name'widget_actu_vote'methods: ['POST'])]
  757.     public function widgetVote(Request $requestQueriesV2Manager $qm): Response
  758.     {
  759.         $id $request->get('id');
  760.         $value $request->get('value');
  761.         $ip $request->getClientIp();
  762.         $req $qm->setSondageVote($id$value$ip);
  763.         return new Response($req);
  764.     }
  765.     #[Route(path'/vote-useful'name'widget_actu_vote_useful'methods: ['POST'])]
  766.     public function widgetVoteUseful(Request $requestQueriesV2Manager $qm): JsonResponse
  767.     {
  768.         $origin $request->headers->get('Origin');
  769.         // Décoder le JSON envoyé avec la requête
  770.         $data json_decode($request->getContent(), true);
  771.         if (json_last_error() !== JSON_ERROR_NONE) {
  772.             return new JsonResponse(['success' => false'message' => 'Invalid JSON'], 400, [
  773.                 'Access-Control-Allow-Origin' => $origin ?? '*',
  774.             ]);
  775.         }
  776.         // Récupérer les valeurs du JSON
  777.         $id $data['id'] ?? null;
  778.         $type $data['type'] ?? null;
  779.         $value $data['value'] ?? null;
  780.         $ip $request->getClientIp();
  781.         // Appeler la méthode pour enregistrer le vote
  782.         $req $qm->setUsefulVote($id$ip$type$value);
  783.         return new JsonResponse(['success' => true'data' => $req], 200, [
  784.             'Access-Control-Allow-Origin' => $origin ?? '*',
  785.         ]);
  786.     }
  787.     #[Route(path'/vote-useful'name'widget_actu_vote_useful_options'methods: ['OPTIONS'])]
  788.     public function widgetVoteUsefulOptions(Request $request): Response
  789.     {
  790.         $origin $request->headers->get('Origin');
  791.         return new Response(''204, [
  792.             'Access-Control-Allow-Origin' => $origin ?? '*',
  793.             'Access-Control-Allow-Methods' => 'POST, OPTIONS',
  794.             'Access-Control-Allow-Headers' => 'Content-Type, Authorization',
  795.             'Access-Control-Max-Age' => '3600',
  796.         ]);
  797.     }
  798.     #[Route(path'/voterrh'name'widget_actu_voterrh'methods: ['GET'])]
  799.     public function widgetVoterrh(Request $requestQueriesV2Manager $qm)
  800.     {
  801.         $id $request->get('id');
  802.         $reponse $request->get('reponse');
  803.         $ip $request->getClientIp();
  804.         $req $qm->setQuizVote($id$reponse$ip);
  805.         return new Response($req);
  806.     }
  807.     #[Route(path'/voter-electronic-invoice'name'widget_actu_voter_electronic_invoice'methods: ['GET'])]
  808.     public function widgetvoterElectronicInvoice(Request $requestQueriesV2Manager $qm)
  809.     {
  810.         $id $request->get('id');
  811.         $reponse $request->get('reponse');
  812.         $ip $request->getClientIp();
  813.         $req $qm->setElectronicInvoiceVote($id$reponse$ip);
  814.         return new Response($req);
  815.     }
  816.     #[Route(path'/voter'name'widget_actu_voter'methods: ['GET'])]
  817.     public function widgetVoter(Request $requestQueriesV2Manager $qm)
  818.     {
  819.         $fromNewsletter $request->get('from'false) === 'newsletter';
  820.         try {
  821.             $id = (int)$request->get('id'true);
  822.             $reponse = (int)$request->get('reponse'true);
  823.             $retour $qm->setSondageVote($id$reponse$request->getClientIp());
  824.             $tabResult $qm->getSondageResult($id);
  825.         } catch (\Exception $e) {
  826.             if (!$fromNewsletter) {
  827.                 throw new \Exception($e->getMessage(), $e->getCode());
  828.             }
  829.             $retour false;
  830.         }
  831.         // Dans le cas où l'on vote par la newsletter, on affiche un message
  832.         if ($fromNewsletter) {
  833.             $this->templateBase '/';
  834.             return $this->render('widget_actu_juridique_v2/voter.html.twig', [
  835.                 'retour' => $retour
  836.             ]);
  837.         }
  838.         return $this->json([
  839.             "results" => $tabResult,
  840.             "erreur" => 0
  841.         ]);
  842.     }
  843.     #[Route('/sendParticipation'name'widget_actu_send_form')]
  844.     public function rgpd_send(Request $requestEntityManagerInterface $emAccountingFirmRepository $accountingFirmRepositoryWidgetMailing $mailing)
  845.     {
  846.         dd("actu du mois");
  847.         $email $request->get('email');
  848.         $tel $request->get('tel');
  849.         $firstname $request->get('firstname');
  850.         $linkedin $request->get('linkedin');
  851.         $expertise $request->get('expertise');
  852.         $idCabinet $request->get('cabinet');
  853.         $cabinet $accountingFirmRepository->findById($idCabinet);
  854.         if (!empty($email) && !empty($firstname) && !empty($tel) && !empty($cabinet) && !empty($linkedin) && !empty($expertise)) {
  855.             // Vérifier si l'email est dans la blacklist
  856.             $blacklistRepo $em->getRepository(EmailBlacklist::class);
  857.             if ($blacklistRepo->isEmailBlacklisted($email)) {
  858.                 // Incrémenter le compteur de tentatives
  859.                 $blacklistedEmail $blacklistRepo->findByEmail($email);
  860.                 if ($blacklistedEmail) {
  861.                     $blacklistedEmail->incrementBlockCount();
  862.                     $em->persist($blacklistedEmail);
  863.                     $em->flush();
  864.                 }
  865.                 return new JsonResponse(['status' => 'error''message' => 'Votre email est dans notre liste noire. Impossible d\'envoyer le message.'], 403);
  866.             }
  867.             $participationContact = new ContactParticipationPlaceExpert;
  868.             $participationContact->setEmail($email);
  869.             $participationContact->setPhone($tel);
  870.             $participationContact->setFirstname($firstname);
  871.             $participationContact->setLinkLinkedin($linkedin);
  872.             $participationContact->setExpertise($expertise);
  873.             $participationContact->setRgpd(true);
  874.             $participationContact->setAccountingFirm($cabinet);
  875.             $participationContact->setCreatedAt(new DateTimeImmutable());
  876.             $em->persist($participationContact);
  877.             $em->flush();
  878.             //send mail
  879.             $mailing->sendParticipationPalToAgenceExpert($cabinet, [ //Envoie à lagence.expert
  880.                 'name' => $firstname,
  881.                 'email' => $email,
  882.                 'tel' => $tel,
  883.                 'linkedin' => $linkedin,
  884.                 'expertise' => $expertise,
  885.             ]);
  886.             $mailing->sendParticipationPalToClient($cabinet, [ //Envoie au client
  887.                 'name' => $firstname,
  888.                 'email' => $email,
  889.             ]);
  890.             return new JsonResponse('success');
  891.         }
  892.         return new JsonResponse('error');
  893.     }
  894. }