src/Controller/WidgetActuController.php line 863

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.                     'journal' => $qm->getJournal($date),
  368.                     'transformationDigitale' => $qm->getTransformationDigitale($date),
  369.                     'infographie' => $qm->getInfographie($date),
  370.                     'chiffreDuMois' => $qm->getChiffreDuMois($date),
  371.                     'citation' => $qm->getCitation($date),
  372.                     'help' => $qm->getHelp($date),
  373.                     'bienEtre' => $qm->getBienEtre($date),
  374.                     'podcast' => $podcast,
  375.                     'idAusha' => $idAusha,
  376.                     'episodes' => $qm->getPodcastsObjects($date),
  377.                     'sondage' => [
  378.                         'details' => $sondage,
  379.                         'results' => $sondage $qm->getSondageResult($sondage['id']) : null,
  380.                     ],
  381.                     'nextEvent' => $qm->getNextEvent(),
  382.                     'previousPerdiods' => $qm->getPreviousPeriods(),
  383.                     'quizrh' => $quizrh,
  384.                     'quizrhVote' => $quizrhVote,
  385.                     'quizElectronicInvoices' => $qm->getQuizElectronicInvoice($date),
  386.                     'quizElectronicInvoicesVote' => $qm->getQuizElectronicInvoiceVote($date),
  387.                     'origin' => 'actu_mois',
  388.                     'nofooter' => true,
  389.                 ];
  390.             }
  391.             $renderparams['test'] = $request->getRequestUri();
  392.         } else {
  393.             $template 'widget_actu_juridique_v2/home.html.twig';
  394.             $aj['calendrier'] = $qm->getDates();
  395.             $nextEvent $qm->getNextEvent();
  396.             //$actus = $qm->getActualites();
  397.             $footer $qm->getFooterData($date);
  398.             $quizrh $qm->getQuizRh($date);
  399.             $quizrhVote $qm->getQuizRhVote($date);
  400.             $podcast $qm->getPodcast($date);
  401.             $idAusha null;
  402.             if ($podcast->getIdAushaEpisodeEc()) {
  403.                 $idAusha $podcast->getIdAushaEpisodeEc();
  404.             }
  405.             $renderparams = [
  406.                 'actus' => $qm->getActualites($date),
  407.                 'journal' => $qm->getJournal($date),
  408.                 'transformationDigitale' => $qm->getTransformationDigitale($date),
  409.                 'infographie' => $qm->getInfographie($date),
  410.                 'chiffreDuMois' => $qm->getChiffreDuMois($date),
  411.                 'citation' => $qm->getCitation($date),
  412.                 'bienEtre' => $qm->getBienEtre($date),
  413.                 'podcast' => $podcast,
  414.                 'idAusha' => $idAusha,
  415.                 'episodes' => $qm->getPodcastsObjects($date),
  416.                 'sondage' => [
  417.                     'details' => $sondage,
  418.                     'results' => $sondage $qm->getSondageResult($sondage['id']) : null,
  419.                 ],
  420.                 'nextEvent' => $qm->getNextEvent(),
  421.                 'previousPerdiods' => $qm->getPreviousPeriods(),
  422.                 'quizrh' => $quizrh,
  423.                 'quizrhVote' => $quizrhVote,
  424.                 'quizElectronicInvoices' => $qm->getQuizElectronicInvoice($date),
  425.                 'quizElectronicInvoicesVote' => $qm->getQuizElectronicInvoiceVote($date),
  426.                 'origin' => 'actu_mois',
  427.                 'nofooter' => true,
  428.             ];
  429.         }
  430.         $renderparams['socialSharingPage'] = $request->getUri();
  431.         $renderparams['getParams'] = $_GET;
  432.         $renderparams['cabinet'] = $accountingFirm;
  433.         $renderparams['cabinetWidgetUrl'] = $accountingFirm->getActuv2Widgeturl();
  434.         $renderparams['serverActuUrl'] = $site->getServerActuUrl();
  435. //        $renderparams['serverActuUrl'] = "http://actucontent.loc:8080";  // test line
  436.         $renderparams['serverUrl'] = "https://actucontent.lagence.expert";
  437. //         $renderparams['serverUrl'] = "http://agex-w-actu.loc:8000";
  438.         return $this->render($template$renderparams);
  439.     }
  440.     #[Route(path'/widget-footer'name'widget_actu_footer')]
  441.     public function footer(Request $requestAccountingFirmRepository $repositoryQueriesV2Manager $qmWebSite $siteAuthorizedDomainRepository $domains): Response
  442.     {
  443.         $token $request->query->get('token');
  444.         $host $request->get('host');
  445.         if ($host != "preview") {
  446.             $accountingFirm $repository->findOneBy(['host' => $host]);
  447.             if (is_null($accountingFirm)) {
  448.                 $domains $domains->findBy(['name' => $host]);
  449.                 if (is_null($domains)) {
  450.                     throw new NotFoundHttpException();
  451.                 }
  452.                 foreach ($domains as $dom) {
  453.                     $tmp_ac $dom->getAccountingFirm();
  454.                     if ($tmp_ac->getActuv2Token() == $token) {
  455.                         $accountingFirm $tmp_ac;
  456.                         break;
  457.                     }
  458.                 }
  459.             }
  460.             if (is_null($accountingFirm)) {
  461.                 throw new NotFoundHttpException();
  462.             }
  463.         }
  464.         $podcast $qm->getPodcast();
  465.         $idAusha null;
  466.         if ($podcast->getIdAushaEpisodeEc()) {
  467.             $idAusha $podcast->getIdAushaEpisodeEc();
  468.         }
  469.         $podcasts = [];
  470.         if ($accountingFirm->isActuv2OnlyPodcast()) {
  471.             $podcasts $qm->getPodcastsObjects();
  472.         }
  473.         $this->templateBase '/';
  474.         return $this->render('widget_actu_juridique_v2/widget-footer.html.twig', [
  475.             'cabinet' => $accountingFirm,
  476.             'footer' => $qm->getFooterData(),
  477.             'episodes' => $podcasts,
  478.             'serverActuUrl' => $site->getServerActuUrl(),
  479.             'cabinetWidgetUrl' => $accountingFirm->getActuv2Widgeturl(),
  480.             'origin' => "actu_mois",
  481.             'podcast' => $podcast,
  482.             'idAusha' => $idAusha,
  483.             'help' => $qm->getHelp(),
  484.             // 'serverActuUrl' => "http://actucontent.loc:8000" // test line
  485.         ]);
  486.     }
  487.     #[Route(path'/widget-actu-primary'name'widget_actu_primary')]
  488.     public function widgetActuPrimary(Request $requestAccountingFirmRepository $repositoryQueriesV2Manager $qmWebSite $siteAuthorizedDomainRepository $domains): Response
  489.     {
  490.         $token $request->query->get('token');
  491.         $host $request->get('host');
  492.         if ($host != "preview") {
  493.             $accountingFirm $repository->findOneBy(['host' => $host]);
  494.             if (is_null($accountingFirm)) {
  495.                 $domains $domains->findBy(['name' => $host]);
  496.                 if (is_null($domains)) {
  497.                     throw new NotFoundHttpException();
  498.                 }
  499.                 foreach ($domains as $dom) {
  500.                     $tmp_ac $dom->getAccountingFirm();
  501.                     if ($tmp_ac->getActuv2Token() == $token) {
  502.                         $accountingFirm $tmp_ac;
  503.                         break;
  504.                     }
  505.                 }
  506.             }
  507.             if (is_null($accountingFirm)) {
  508.                 throw new NotFoundHttpException();
  509.             }
  510.         }
  511.         $this->templateBase '/';
  512.         $p $request->getRequestUri();
  513.         $pos strpos($p'?');
  514.         if ($pos !== false) {
  515.             $p substr($p0$pos 1) . str_replace('?''&'substr($p$pos 1));
  516.         }
  517.         $route parse_url($p);
  518.         $date null;
  519.         if (isset($route['query'])) {
  520.             parse_str($route['query'], $query);
  521.             $date $query['date'] ?? null;
  522.         }
  523.         return $this->render('widget_actu_juridique_v2/widget-actu-primary.html.twig', [
  524.             'cabinet' => $accountingFirm,
  525.             'serverActuUrl' => $site->getServerActuUrl(),
  526.             'cabinetWidgetUrl' => $accountingFirm->getActuv2Widgeturl(),
  527.             'origin' => "actu_mois",
  528.             'actus' => $qm->getActualites($date),
  529.             // 'serverActuUrl' => "http://actucontent.loc:8000" // test line
  530.         ]);
  531.     }
  532.     #[Route(path'/widget-sondage'name'widget_sondage')]
  533.     public function widgetSondage(Request $requestAccountingFirmRepository $repositoryQueriesV2Manager $qmWebSite $siteAuthorizedDomainRepository $domains): Response
  534.     {
  535.         $token $request->query->get('token');
  536.         $host $request->get('host');
  537.         if ($host != "preview") {
  538.             $accountingFirm $repository->findOneBy(['host' => $host]);
  539.             if (is_null($accountingFirm)) {
  540.                 $domains $domains->findBy(['name' => $host]);
  541.                 if (is_null($domains)) {
  542.                     throw new NotFoundHttpException();
  543.                 }
  544.                 foreach ($domains as $dom) {
  545.                     $tmp_ac $dom->getAccountingFirm();
  546.                     if ($tmp_ac->getActuv2Token() == $token) {
  547.                         $accountingFirm $tmp_ac;
  548.                         break;
  549.                     }
  550.                 }
  551.             }
  552.             if (is_null($accountingFirm)) {
  553.                 throw new NotFoundHttpException();
  554.             }
  555.         }
  556.         $this->templateBase '/';
  557.         $p $request->getRequestUri();
  558.         $pos strpos($p'?');
  559.         if ($pos !== false) {
  560.             $p substr($p0$pos 1) . str_replace('?''&'substr($p$pos 1));
  561.         }
  562.         $route parse_url($p);
  563.         $date null;
  564.         if (isset($route['query'])) {
  565.             parse_str($route['query'], $query);
  566.             $date $query['date'] ?? null;
  567.         }
  568.         $sondage $qm->getSondage($date);
  569.         return $this->render('widget_actu_juridique_v2/widget-sondage.html.twig', [
  570.             'cabinet' => $accountingFirm,
  571.             'serverActuUrl' => $site->getServerActuUrl(),
  572.             'cabinetWidgetUrl' => $accountingFirm->getActuv2Widgeturl(),
  573.             'origin' => "actu_mois",
  574.             'sondage' => [
  575.                 'details' => $sondage,
  576.                 'results' => is_null($sondage) ? null $qm->getSondageResult($sondage['id']),
  577.             ],
  578.             // 'serverActuUrl' => "http://actucontent.loc:8000" // test line
  579.         ]);
  580.     }
  581.     #[Route(path'/widget-podcast'name'widget_podcast')]
  582.     public function widgetPodcast(Request $requestAccountingFirmRepository $repositoryQueriesV2Manager $qmWebSite $siteAuthorizedDomainRepository $domains): Response
  583.     {
  584.         $token $request->query->get('token');
  585.         $host $request->get('host');
  586.         if ($host != "preview") {
  587.             $accountingFirm $repository->findOneBy(['host' => $host]);
  588.             if (is_null($accountingFirm)) {
  589.                 $domains $domains->findBy(['name' => $host]);
  590.                 if (is_null($domains)) {
  591.                     throw new NotFoundHttpException();
  592.                 }
  593.                 foreach ($domains as $dom) {
  594.                     $tmp_ac $dom->getAccountingFirm();
  595.                     if ($tmp_ac->getActuv2Token() == $token) {
  596.                         $accountingFirm $tmp_ac;
  597.                         break;
  598.                     }
  599.                 }
  600.             }
  601.             if (is_null($accountingFirm)) {
  602.                 throw new NotFoundHttpException();
  603.             }
  604.         }
  605.         $this->templateBase '/';
  606.         $p $request->getRequestUri();
  607.         $pos strpos($p'?');
  608.         if ($pos !== false) {
  609.             $p substr($p0$pos 1) . str_replace('?''&'substr($p$pos 1));
  610.         }
  611.         $route parse_url($p);
  612.         $date null;
  613.         if (isset($route['query'])) {
  614.             parse_str($route['query'], $query);
  615.             $date $query['date'] ?? null;
  616.         }
  617.         $podcast $qm->getPodcast($date);
  618.         $idAusha null;
  619.         if ($podcast->getIdAushaEpisodeEc()) {
  620.             $idAusha $podcast->getIdAushaEpisodeEc();
  621.         }
  622.         return $this->render('widget_actu_juridique_v2/widget-podcast.html.twig', [
  623.             'cabinet' => $accountingFirm,
  624.             'serverActuUrl' => $site->getServerActuUrl(),
  625.             'cabinetWidgetUrl' => $accountingFirm->getActuv2Widgeturl(),
  626.             'origin' => "actu_mois",
  627.             'podcast' => $podcast,
  628.             'idAusha' => $idAusha,
  629.             // 'serverActuUrl' => "http://actucontent.loc:8000" // test line
  630.         ]);
  631.     }
  632.     #[Route(path'/widget-quizz'name'widget_quizz')]
  633.     public function widgetQuizz(Request $requestAccountingFirmRepository $repositoryQueriesV2Manager $qmWebSite $siteAuthorizedDomainRepository $domains): Response
  634.     {
  635.         $token $request->query->get('token');
  636.         $host $request->get('host');
  637.         if ($host != "preview") {
  638.             $accountingFirm $repository->findOneBy(['host' => $host]);
  639.             if (is_null($accountingFirm)) {
  640.                 $domains $domains->findBy(['name' => $host]);
  641.                 if (is_null($domains)) {
  642.                     throw new NotFoundHttpException();
  643.                 }
  644.                 foreach ($domains as $dom) {
  645.                     $tmp_ac $dom->getAccountingFirm();
  646.                     if ($tmp_ac->getActuv2Token() == $token) {
  647.                         $accountingFirm $tmp_ac;
  648.                         break;
  649.                     }
  650.                 }
  651.             }
  652.             if (is_null($accountingFirm)) {
  653.                 throw new NotFoundHttpException();
  654.             }
  655.         }
  656.         $this->templateBase '/';
  657.         $p $request->getRequestUri();
  658.         $pos strpos($p'?');
  659.         if ($pos !== false) {
  660.             $p substr($p0$pos 1) . str_replace('?''&'substr($p$pos 1));
  661.         }
  662.         $route parse_url($p);
  663.         $date null;
  664.         if (isset($route['query'])) {
  665.             parse_str($route['query'], $query);
  666.             $date $query['date'] ?? null;
  667.         }
  668.         $quizrh $qm->getQuizRh($date);
  669.         $quizrhVote $qm->getQuizRhVote($date);
  670.         return $this->render('widget_actu_juridique_v2/widget-quizz.html.twig', [
  671.             'cabinet' => $accountingFirm,
  672.             'serverActuUrl' => $site->getServerActuUrl(),
  673.             'cabinetWidgetUrl' => $accountingFirm->getActuv2Widgeturl(),
  674.             'origin' => "actu_mois",
  675.             'quizrh' => $quizrh,
  676.             'quizrhVote' => $quizrhVote,
  677.             // 'serverActuUrl' => "http://actucontent.loc:8000" // test line
  678.         ]);
  679.     }
  680.     #[Route(path'/get-audio-ausha'name'w_actu_get_audio_ausha')]
  681.     #[Route(path'/js/agex-actus-juridiques.min.js'name'w_actu_embed_old')]
  682.     public function getAudioAusha(Request $request)
  683.     {
  684.         $aushaId $request->query->get('aushaid');
  685.         $aushaToken "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjczOTY4MjQ2MjU3NzJkYzA2M2ZkMTgyMzVlYzY4ZmFkZWE4MDNhMGI2NzI1NjQ1YzJkODEwM2E2YWYyMTMxZTJkZDZkYjU1NTMyMWQzM2NkIn0.eyJhdWQiOiIxIiwianRpIjoiNzM5NjgyNDYyNTc3MmRjMDYzZmQxODIzNWVjNjhmYWRlYTgwM2EwYjY3MjU2NDVjMmQ4MTAzYTZhZjIxMzFlMmRkNmRiNTU1MzIxZDMzY2QiLCJpYXQiOjE2NjMxNTQ4MTUsIm5iZiI6MTY2MzE1NDgxNSwiZXhwIjo3OTUyNDI4Nzk5LCJzdWIiOiIxMTMwNzEiLCJzY29wZXMiOlsic2hvd3MuaW5kZXhXaXRoR3JhbnRlZCIsInNob3dzLnNob3ciLCJzaG93cy5zaG93LmJ5X3B1YmxpY2lkIiwicGxheWxpc3RzLmluZGV4IiwicGxheWxpc3RzLnN0b3JlIiwicGxheWxpc3RzLnNob3ciLCJwbGF5bGlzdHMudXBkYXRlIiwicGxheWxpc3RzLmRlc3Ryb3kiLCJwbGF5bGlzdHMucG9kY2FzdC5zdG9yZSIsInBsYXlsaXN0cy5wb2RjYXN0LmRlc3Ryb3kiLCJwbGF5bGlzdHMucG9kY2FzdC5tb3ZlIiwicGxheWxpc3RzLmltYWdlLnN0b3JlIiwicGxheWxpc3RzLmltYWdlLmRlc3Ryb3kiLCJwb2RjYXN0cy52aWRlby5pbmRleCIsInBvZGNhc3RzLnZpZGVvLnNob3ciLCJzZWFzb25zLmluZGV4Iiwic2Vhc29ucy5zdG9yZSIsInNlYXNvbnMuc2hvdyIsInNlYXNvbnMuZGVzdHJveSIsInNob3dzLnBvZGNhc3RzLnNlYXNvbi51cGRhdGUiLCJjYW1wYWlnbnMuaW5kZXgiLCJjYW1wYWlnbnMuc2hvdyIsInBvZGNhc3RzLmluZGV4IiwicG9kY2FzdHMuc2hvdyIsInBvZGNhc3RzLnNob3cuYnlfcHVibGljaWQiLCJwb2RjYXN0cy5zdG9yZSIsInBvZGNhc3RzLnVwZGF0ZSIsInBvZGNhc3RzLmRlc3Ryb3kiLCJwb2RjYXN0cy5pbWFnZS5zdG9yZSIsInBvZGNhc3RzLmZpbGUuc3RvcmUiXX0.uWgOLN2_5LAKL9gB0Ij8V5PJjKrwRqAO_wVZ4l0vV73QPPF4MUDUzsYU-1hL4iFFPWanhg018EH_AGZvGdSdrZXqkzBPnqv6TxhL9aCVeayVwvgD-BQwPMJ3E7z27xREEhXH_r6f0d2t_J6SJexVh3AoT8fD2kUyFXh9B95ziWV-vULeHOqtWEZk01YctUyHLFWhIFzajgn8nSHb3hMYfbV4phapZqaegwCBSIxVPJz4yS3Ox0tbI5g-P6fAK5PlE1pKiPXabekYyUN4tPEmpMAQVURM3xcutBXUTMX0H6GCs0ih7KH3cI8SICVrldo3LkbAh8x4uuJJu2aNmv9qHpyxLi9wfmklyWMt0ROuf4dHPiDVLUfwmqnt9UEE4H5jP7hHcrMNCIRzerBgW0cCfKj0wJBtOuYpsqqBou2YTEyYja8uNEQbHpOQT4gT7CJxa575kqKsrTr9tS2k19BPdlxtBoIPQHcVpY9tQ1_TJro72kbE1ooJICZyFYTdHHPX77H4LClYcN4TxHxp8jTp6hXt_BjZbwU7Kl2PIxFV1diK62idKCtBjd_tvnUIuh7sKZeGn-YwCYVZVWRblYmZQ3tmPyje1ZJsgnY_nZIZ1TBwzZf3ucuPRxJJ4vPc3dXkxvLtWUs3bLWnACHCjhRA7LfMNDIlAZoRKHKQI6UNuiE";
  686.         $client = new Client(['base_uri' => 'https://developers.ausha.co/v1/podcasts/']);
  687.         $headers = [
  688.             'Authorization' => 'Bearer ' $aushaToken,
  689.             'accept' => 'application/json',
  690.             'content-type' => 'application/json',
  691.         ];
  692.         $ausha_mp3 null;
  693.         $logFile '../log_ausha.txt';
  694.         $origin "PODCAST_PRIVATE_WidgetPodcastPrivateController";
  695.         $url $aushaId;
  696.         $date = (new \DateTime())->format('Y-m-d H:i:s');
  697.         file_put_contents($logFile"[$date] - origin => $origin - avant appel API\n"FILE_APPEND);
  698.         try {
  699.             $response $client->request('GET'$aushaId, [
  700.                 'headers' => $headers
  701.             ]);
  702.             file_put_contents($logFile"[$date] - origin => $origin - après appel API\n"FILE_APPEND);
  703.             if ($response->getStatusCode() === 200) {
  704.                 file_put_contents($logFile"succès à l'URL : $url\n"FILE_APPEND);
  705.                 $ausha json_decode($response->getBody()->getContents());
  706.                 if ($ausha->data->audio_url) {
  707.                     $ausha_mp3 $ausha->data->audio_url;
  708.                 }
  709.             }
  710.         } catch (\Exception $e) {
  711.             file_put_contents($logFile"[$date] - origin => $origin - après appel API\n"FILE_APPEND);
  712.             file_put_contents($logFile$e->getCode() . " - " $e->getMessage() . "\n"FILE_APPEND);
  713.         }
  714.         file_put_contents($logFile"--\n"FILE_APPEND);
  715.         return new JsonResponse([
  716.             'ausha_mp3' => $ausha_mp3
  717.         ]);
  718.     }
  719.     #[Route(path'/embed'name'w_actu_embed')]
  720.     #[Route(path'/js/agex-actus-juridiques.min.js'name'w_actu_embed_old')]
  721.     public function embed(Request $requestAccountingFirmRepository $repository)
  722.     {
  723.         $root $this->getParameter('kernel.project_dir');
  724.         $path $root '/public/widgets/actus-juridique/widget_actu.js';
  725.         $response = new BinaryFileResponse($path);
  726.         $response->headers->set('Content-Type''text/javascript');
  727.         return $response;
  728.     }
  729.     #[Route(path'/{filename}.{format}'name'w_actu_files')]
  730.     public function actu_files(Request $requeststring $filenamestring $format)
  731.     {
  732.         $allowed = array('png''jpg''jpeg''gif''js''svg''eot''ttf''woff');
  733.         if (in_array($format$allowed)) {
  734.             $root $this->getParameter('kernel.project_dir');
  735.             $path $root '/public/widgets/actus-juridique/' $filename '.' $format;
  736.             //dd(file_exists($path), $path, $request->getRequestFormat());
  737.             return new BinaryFileResponse($path);
  738.         }
  739.         return false;
  740.     }
  741.     #[Route(path'/widget-dates'name'widget_actu_dates')]
  742.     public function dates(QueriesV2Manager $qm)
  743.     {
  744.         $tabData $qm->getDates();
  745.         $tabDates = [];
  746.         foreach ($tabData as $lignes) {
  747.             foreach ($lignes as $ligne) {
  748.                 $key array_search($ligne['date'], array_column($tabDates'date'));
  749.                 if ($key === false) { // cas date jamais ajoutée
  750.                     $tabDates[] = ['date' => $ligne['date'], 'lien' => 'calendrier-fiscal.php?id=' $ligne['id']];
  751.                 } else { // cas date déjà ajoutée, donc plusieurs articles à la même date
  752.                     $tabDates[$key] = ['date' => $ligne['date'], 'lien' => 'actualites-calendrier-fiscal.php?date=' $ligne['date']];
  753.                 }
  754.             }
  755.         }
  756.         return $this->json($tabDates);
  757.     }
  758.     #[Route(path'/api/vote/'name'widget_actu_vote'methods: ['POST'])]
  759.     public function widgetVote(Request $requestQueriesV2Manager $qm): Response
  760.     {
  761.         $id $request->get('id');
  762.         $value $request->get('value');
  763.         $ip $request->getClientIp();
  764.         $req $qm->setSondageVote($id$value$ip);
  765.         return new Response($req);
  766.     }
  767.     #[Route(path'/vote-useful'name'widget_actu_vote_useful'methods: ['POST'])]
  768.     public function widgetVoteUseful(Request $requestQueriesV2Manager $qm): JsonResponse
  769.     {
  770.         $origin $request->headers->get('Origin');
  771.         // Décoder le JSON envoyé avec la requête
  772.         $data json_decode($request->getContent(), true);
  773.         if (json_last_error() !== JSON_ERROR_NONE) {
  774.             return new JsonResponse(['success' => false'message' => 'Invalid JSON'], 400, [
  775.                 'Access-Control-Allow-Origin' => $origin ?? '*',
  776.             ]);
  777.         }
  778.         // Récupérer les valeurs du JSON
  779.         $id $data['id'] ?? null;
  780.         $type $data['type'] ?? null;
  781.         $value $data['value'] ?? null;
  782.         $ip $request->getClientIp();
  783.         // Appeler la méthode pour enregistrer le vote
  784.         $req $qm->setUsefulVote($id$ip$type$value);
  785.         return new JsonResponse(['success' => true'data' => $req], 200, [
  786.             'Access-Control-Allow-Origin' => $origin ?? '*',
  787.         ]);
  788.     }
  789.     #[Route(path'/vote-useful'name'widget_actu_vote_useful_options'methods: ['OPTIONS'])]
  790.     public function widgetVoteUsefulOptions(Request $request): Response
  791.     {
  792.         $origin $request->headers->get('Origin');
  793.         return new Response(''204, [
  794.             'Access-Control-Allow-Origin' => $origin ?? '*',
  795.             'Access-Control-Allow-Methods' => 'POST, OPTIONS',
  796.             'Access-Control-Allow-Headers' => 'Content-Type, Authorization',
  797.             'Access-Control-Max-Age' => '3600',
  798.         ]);
  799.     }
  800.     #[Route(path'/voterrh'name'widget_actu_voterrh'methods: ['GET'])]
  801.     public function widgetVoterrh(Request $requestQueriesV2Manager $qm)
  802.     {
  803.         $id $request->get('id');
  804.         $reponse $request->get('reponse');
  805.         $ip $request->getClientIp();
  806.         $req $qm->setQuizVote($id$reponse$ip);
  807.         return new Response($req);
  808.     }
  809.     #[Route(path'/voter-electronic-invoice'name'widget_actu_voter_electronic_invoice'methods: ['GET'])]
  810.     public function widgetvoterElectronicInvoice(Request $requestQueriesV2Manager $qm)
  811.     {
  812.         $id $request->get('id');
  813.         $reponse $request->get('reponse');
  814.         $ip $request->getClientIp();
  815.         $req $qm->setElectronicInvoiceVote($id$reponse$ip);
  816.         return new Response($req);
  817.     }
  818.     #[Route(path'/voter'name'widget_actu_voter'methods: ['GET'])]
  819.     public function widgetVoter(Request $requestQueriesV2Manager $qm)
  820.     {
  821.         $fromNewsletter $request->get('from'false) === 'newsletter';
  822.         try {
  823.             $id = (int)$request->get('id'true);
  824.             $reponse = (int)$request->get('reponse'true);
  825.             $retour $qm->setSondageVote($id$reponse$request->getClientIp());
  826.             $tabResult $qm->getSondageResult($id);
  827.         } catch (\Exception $e) {
  828.             if (!$fromNewsletter) {
  829.                 throw new \Exception($e->getMessage(), $e->getCode());
  830.             }
  831.             $retour false;
  832.         }
  833.         // Dans le cas où l'on vote par la newsletter, on affiche un message
  834.         if ($fromNewsletter) {
  835.             $this->templateBase '/';
  836.             return $this->render('widget_actu_juridique_v2/voter.html.twig', [
  837.                 'retour' => $retour
  838.             ]);
  839.         }
  840.         return $this->json([
  841.             "results" => $tabResult,
  842.             "erreur" => 0
  843.         ]);
  844.     }
  845.     #[Route('/sendParticipation'name'widget_actu_send_form')]
  846.     public function rgpd_send(Request $requestEntityManagerInterface $emAccountingFirmRepository $accountingFirmRepositoryWidgetMailing $mailing)
  847.     {
  848.         dd("actu du mois");
  849.         $email $request->get('email');
  850.         $tel $request->get('tel');
  851.         $firstname $request->get('firstname');
  852.         $linkedin $request->get('linkedin');
  853.         $expertise $request->get('expertise');
  854.         $idCabinet $request->get('cabinet');
  855.         $cabinet $accountingFirmRepository->findById($idCabinet);
  856.         if (!empty($email) && !empty($firstname) && !empty($tel) && !empty($cabinet) && !empty($linkedin) && !empty($expertise)) {
  857.             // Vérifier si l'email est dans la blacklist
  858.             $blacklistRepo $em->getRepository(EmailBlacklist::class);
  859.             if ($blacklistRepo->isEmailBlacklisted($email)) {
  860.                 // Incrémenter le compteur de tentatives
  861.                 $blacklistedEmail $blacklistRepo->findByEmail($email);
  862.                 if ($blacklistedEmail) {
  863.                     $blacklistedEmail->incrementBlockCount();
  864.                     $em->persist($blacklistedEmail);
  865.                     $em->flush();
  866.                 }
  867.                 return new JsonResponse(['status' => 'error''message' => 'Votre email est dans notre liste noire. Impossible d\'envoyer le message.'], 403);
  868.             }
  869.             $participationContact = new ContactParticipationPlaceExpert;
  870.             $participationContact->setEmail($email);
  871.             $participationContact->setPhone($tel);
  872.             $participationContact->setFirstname($firstname);
  873.             $participationContact->setLinkLinkedin($linkedin);
  874.             $participationContact->setExpertise($expertise);
  875.             $participationContact->setRgpd(true);
  876.             $participationContact->setAccountingFirm($cabinet);
  877.             $participationContact->setCreatedAt(new DateTimeImmutable());
  878.             $em->persist($participationContact);
  879.             $em->flush();
  880.             //send mail
  881.             $mailing->sendParticipationPalToAgenceExpert($cabinet, [ //Envoie à lagence.expert
  882.                 'name' => $firstname,
  883.                 'email' => $email,
  884.                 'tel' => $tel,
  885.                 'linkedin' => $linkedin,
  886.                 'expertise' => $expertise,
  887.             ]);
  888.             $mailing->sendParticipationPalToClient($cabinet, [ //Envoie au client
  889.                 'name' => $firstname,
  890.                 'email' => $email,
  891.             ]);
  892.             return new JsonResponse('success');
  893.         }
  894.         return new JsonResponse('error');
  895.     }
  896. }