<?php
namespace App\Controller;
use App\Entity\Actuv2InfographieRse;
use App\Entity\ContactParticipationPlaceExpert;
use App\Entity\EmailBlacklist;
use App\Form\ContactParticipationPlaceExpertType;
use App\Repository\PodcastPrivateRepository;
use App\Services\HelpersFirmsService;
use DateTime;
use Exception;
use App\Services\WebSite;
use App\Services\QueriesV2Manager;
use App\Repository\AccountingFirmRepository;
use App\Repository\Actuv2BienetreRepository;
use App\Repository\Actuv2InfographieRseRepository;
use App\Repository\Actuv2PodcastRepository;
use App\Repository\Actuv2TransformationdigitaleRepository;
use Symfony\Component\HttpFoundation\Request;
use App\Repository\AuthorizedDomainRepository;
use App\Services\WidgetMailing;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use App\Repository\PodcastEpisodeRepository;
use GuzzleHttp\Client;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class WidgetActuController extends AbstractController
{
#[Route(path: '/check-widget-actu', name: 'check_Widget_actu')]
public function checkWidgetActu(Request $request, AccountingFirmRepository $repository, string $prefix = null): JsonResponse
{
$token = $request->query->get('token');
$host = $request->query->get('host');
if ($token && $host) {
$accountingFirm = $repository->findOneBy(['actuv2Token' => $token]);
$isAuthorized = false;
if ($accountingFirm && in_array($host, $accountingFirm->getListAuthorizedDomains())) {
$isAuthorized = true;
}
$url = $isAuthorized ? $accountingFirm->getActuv2Widgeturl() : null;
} else {
$accountingFirm = $repository->findOneBy(['host' => $host]);
$url = $accountingFirm ? $prefix . $this->generateUrl('widget_actu_home') : null;
}
return $this->json($url);
}
#[Route(path: '/widget-actu', name: 'widget_actu_home')]
public function widgetHome(Request $request, QueriesV2Manager $qm, AccountingFirmRepository $repository, AuthorizedDomainRepository $domains, WebSite $site, PodcastPrivateRepository $podcastPrivateRepository, Actuv2InfographieRseRepository $actuv2InfographieRseRepository, Actuv2TransformationdigitaleRepository $actuv2TransformationdigitaleRepository, Actuv2BienetreRepository $actuv2BienetreRepository, Actuv2PodcastRepository $actuv2PodcastRepository, HelpersFirmsService $helpersFirmsService): Response
{
$token = $request->query->get('token');
$host = $request->get('host');
$host = str_replace('www.', '', $host);
if ($host != "preview") {
$accountingFirm = $repository->findOneBy(['actuv2Token' => $token]);
//dd($accountingFirm);
if (is_null($accountingFirm)) {
$domains = $domains->findBy(['name' => $host]);
if (is_null($domains)) {
throw new NotFoundHttpException();
}
foreach ($domains as $dom) {
$tmp_ac = $dom->getAccountingFirm();
if ($tmp_ac->getActuv2Token() == $token) {
$accountingFirm = $tmp_ac;
break;
}
}
}
if (is_null($accountingFirm)) {
throw new NotFoundHttpException();
}
}
$date = $request->query->get('date', false);
$this->templateBase = '/';
$sondage = $qm->getSondage($date);
$template = null;
$renderparams = [];
$p = $request->getRequestUri();
$pos = strpos($p, '?');
if ($pos !== false) {
$p = substr($p, 0, $pos + 1) . str_replace('?', '&', substr($p, $pos + 1));
}
$route = parse_url($p);
if (isset($route['query'])) {
parse_str($route['query'], $query);
$page = isset($query['p']) ? $query['p'] : null;
$id = isset($query['id']) ? $query['id'] : null;
$search = isset($query['q']) ? $query['q'] : null;
$date = isset($query['date']) ? $query['date'] : null;
if ($accountingFirm->isActuv2OnlyPodcast()) {
$page = 'podcast.php';
if (!$id) {
$id = 'detail';
}
}
if (!empty($page) && !is_null($page)) {
switch ($page) {
case 'transformation-digitale.php':
$template = 'widget_actu_juridique_v2/details-transformation-digitale.html.twig';
if (isset($id)) {
$data = $actuv2TransformationdigitaleRepository->findOneBy(['id' => $id]);
} else {
$data = $qm->getTransformationDigitale($date);
}
$actus = $qm->getActualites();
$footer = $qm->getFooterData();
$histo = $qm->getHistoTransfo();
$hasVoteUseful = $qm->hasVoteUseful($id, 'transformation-digitale.php');
$renderparams = [
'data' => $data,
'actus' => array_chunk($actus, 3),
'footer' => $footer,
'help' => $qm->getHelp(),
'histo' => $histo,
'hasVoteUseful' => $hasVoteUseful
];
break;
case 'journal.php':
$template = 'widget_actu_juridique_v2/details-journal.html.twig';
if (isset($id)) {
$data = $qm->getJournalDetails($id);
} else {
$data = $qm->getJournal($date);
}
$footer = $qm->getFooterData();
$renderparams = [
'data' => $data,
'footer' => $footer,
'help' => $qm->getHelp(),
];
break;
case 'calendrier-fiscal.php':
if (!empty($id) && !is_null($id)) {
$template = 'widget_actu_juridique_v2/details-calendrier.html.twig';
$data = $qm->getCalendrierDetails($id);
$nextEvent = $qm->getNextEvent();
$actus = $qm->getActualites();
$footer = $qm->getFooterData();
$renderparams = [
'footer' => $footer,
'help' => $qm->getHelp(),
'data' => $data,
'actus' => array_chunk($actus, 3),
'nextEvent' => $nextEvent,
];
}
break;
case 'actualites-calendrier-fiscal.php':
if (!empty($date) && !is_null($date)) {
$template = 'widget_actu_juridique_v2/liste-calendrier.html.twig';
$data = $qm->getCalendrierListe($date);
$nextEvent = $qm->getNextEvent();
$footer = $qm->getFooterData();
try {
$dateActus = (new DateTime($date))->format("d/m/Y");
} catch (Exception $e) {
throw $e;
}
$renderparams = [
'footer' => $footer,
'help' => $qm->getHelp(),
'data' => $data,
'dateActus' => $dateActus,
'nextEvent' => $nextEvent,
];
}
break;
case 'actualite.php':
if (!empty($id) && !is_null($id)) {
$template = 'widget_actu_juridique_v2/details-actu.html.twig';
$footer = $qm->getFooterData();
$data = $qm->getActualitesDetails($id);
$nextEvent = $qm->getNextEvent();
$actus = $qm->getActualites();
$histo = $qm->getHistoActualites();
$hasVoteUseful = $qm->hasVoteUseful($id, 'actualite.php');
$renderparams = [
'footer' => $footer,
'help' => $qm->getHelp(),
'data' => $data,
'actus' => array_chunk($actus, 3),
'nextEvent' => $nextEvent,
'histo' => $histo,
'hasVoteUseful' => $hasVoteUseful
];
}
break;
case 'bien-etre.php':
$template = 'widget_actu_juridique_v2/details-bien-etre.html.twig';
if (isset($id)) {
$data = $actuv2BienetreRepository->findOneBy(['id' => $id]);
} else {
$data = $qm->getBienEtre($date);
}
$actus = $qm->getActualites();
$nextEvent = $qm->getNextEvent();
$footer = $qm->getFooterData();
$histo = $qm->getHistoBienEtre();
$hasVoteUseful = $qm->hasVoteUseful($id, 'bien-etre.php');
$renderparams = [
'footer' => $footer,
'help' => $qm->getHelp(),
'data' => $data,
'actus' => array_chunk($actus, 3),
'nextEvent' => $nextEvent,
'histo' => $histo,
'hasVoteUseful' => $hasVoteUseful
];
break;
case 'actualite-cabinet.php':
if (!empty($id) && !is_null($id)) {
$template = 'widget_actu_juridique_v2/details-actu-cabinet.html.twig';
$footer = $qm->getFooterData();
$data = $qm->getActualiteCabinetDetails($id);
$nextEvent = $qm->getNextEvent();
$actus = $qm->getActualites();
$hasVoteUseful = $qm->hasVoteUseful($id, 'actualite-cabinet.php');
$renderparams = [
'footer' => $footer,
'help' => $qm->getHelp(),
'data' => $data,
'actus' => array_chunk($actus, 3),
'nextEvent' => $nextEvent,
'hasVoteUseful' => $hasVoteUseful
];
}
break;
case 'recherche.php':
if (!empty($search) && !is_null($search)) {
$template = 'widget_actu_juridique_v2/liste-recherche.html.twig';
$data = $qm->search($search);
$footer = $qm->getFooterData();
$renderparams = [
'footer' => $footer,
'listResults' => $data,
'recherche' => $search,
];
}
break;
case 'participation.php':
$template = 'widget_actu_juridique_v2/participation.html.twig';
$nextEvent = $qm->getNextEvent();
$footer = $qm->getFooterData();
$renderparams = [
'footer' => $footer,
'help' => $qm->getHelp(),
];
break;
case 'infographie-rse.php':
$template = 'widget_actu_juridique_v2/infographie-rse.html.twig';
if (isset($id)) {
$infographie = $actuv2InfographieRseRepository->findOneBy(['id' => $id]);
} else {
$infographie = $qm->getInfographie($date);
}
$footer = $qm->getFooterData();
$infographieArchivage = $actuv2InfographieRseRepository->findAll();
$renderparams = [
'infographie' => $infographie,
'footer' => $footer,
'help' => $qm->getHelp(),
'archivages' => $infographieArchivage,
];
break;
case 'calendrier-juridique.php':
$template = 'widget_actu_juridique_v2/calendrier-juridique.html.twig';
$footer = $qm->getFooterData();
$renderparams = [
'nextEvent' => $qm->getNextEvent(),
'footer' => $footer,
'help' => $qm->getHelp(),
];
break;
case 'podcast.php':
$template = 'widget_actu_juridique_v2/podcast-detail.html.twig';
if ($id) {
if ($id == 'detail') {
$podcast = $qm->getPodcast($date);
} else {
$podcast = $podcastPrivateRepository->findOneBy(['id' => $id]);
}
} else {
$podcast = 'list';
}
$podcasts = $qm->getPodcastsObjects($date);
// $podcasts = [];
// foreach ($episodes as $episode) {
// // Stocker chaque épisode dans le nouvel array $episodes
// $podcasts[] = $episode->getPodcastEpisode();
// }
if ($podcast != "list") {
$idAusha = null;
if ($podcast->getIdAushaEpisodeEc()) {
$idAusha = $podcast->getIdAushaEpisodeEc();
}
$truncate = $podcast->getSubDescriptionTxt();
$chars = 550;
if (strlen($truncate) > $chars) {
$truncate = html_entity_decode($truncate) . " ";
$truncate = substr($truncate, 0, $chars);
$truncate = substr($truncate, 0, strrpos($truncate, ' '));
$truncate = $truncate . "...";
} else {
$truncate = null;
}
$renderparams = [
'podcast' => $podcast,
'idAusha' => $idAusha,
'truncate' => $truncate,
'episodes' => $podcasts,
'origin' => 'actu_mois'
];
} else {
$renderparams = [
'podcast' => $podcast,
'episodes' => $podcasts,
'origin' => 'actu_mois'
];
}
break;
case 'podcast-latest.php':
$template = 'widget_actu_juridique_v2/podcast-detail.html.twig';
$podcast = $qm->getPodcastLatest();
$podcasts = $qm->getPodcastsObjects($date);
$renderparams = [
'podcast' => $podcast[0],
'episodes' => $podcasts,
'origin' => 'actu_mois'
];
break;
case 'aide.php':
$template = 'widget_actu_juridique_v2/aide.html.twig';
$helper = $qm->getHelpById($id);
$footer = $qm->getFooterData();
$territoires = $helpersFirmsService->getTerritoiresFromContactsHelper($helper['help']['cache_indexation']['contacts']);
$renderparams = [
'helper' => $helper,
'footer' => $footer,
'help' => $qm->getHelp(),
'territoires' => $territoires,
];
break;
default:
// NOPE
break;
}
} else {
$template = 'widget_actu_juridique_v2/home.html.twig';
$aj['calendrier'] = $qm->getDates();
$nextEvent = $qm->getNextEvent();
//$actus = $qm->getActualites();
$footer = $qm->getFooterData($date);
$quizrh = $qm->getQuizRh($date);
$quizrhVote = $qm->getQuizRhVote($date);
$podcast = $qm->getPodcast($date);
$idAusha = null;
if ($podcast->getIdAushaEpisodeEc()) {
$idAusha = $podcast->getIdAushaEpisodeEc();
}
$renderparams = [
'actus' => $qm->getActualites($date),
'transformationDigitale' => $qm->getTransformationDigitale($date),
'infographie' => $qm->getInfographie($date),
'chiffreDuMois' => $qm->getChiffreDuMois($date),
'citation' => $qm->getCitation($date),
'help' => $qm->getHelp($date),
'bienEtre' => $qm->getBienEtre($date),
'podcast' => $podcast,
'idAusha' => $idAusha,
'episodes' => $qm->getPodcastsObjects($date),
'sondage' => [
'details' => $sondage,
'results' => $sondage ? $qm->getSondageResult($sondage['id']) : null,
],
'nextEvent' => $qm->getNextEvent(),
'previousPerdiods' => $qm->getPreviousPeriods(),
'quizrh' => $quizrh,
'quizrhVote' => $quizrhVote,
'quizElectronicInvoices' => $qm->getQuizElectronicInvoice($date),
'quizElectronicInvoicesVote' => $qm->getQuizElectronicInvoiceVote($date),
'origin' => 'actu_mois',
'nofooter' => true,
];
}
$renderparams['test'] = $request->getRequestUri();
} else {
$template = 'widget_actu_juridique_v2/home.html.twig';
$aj['calendrier'] = $qm->getDates();
$nextEvent = $qm->getNextEvent();
//$actus = $qm->getActualites();
$footer = $qm->getFooterData($date);
$quizrh = $qm->getQuizRh($date);
$quizrhVote = $qm->getQuizRhVote($date);
$podcast = $qm->getPodcast($date);
$idAusha = null;
if ($podcast->getIdAushaEpisodeEc()) {
$idAusha = $podcast->getIdAushaEpisodeEc();
}
$renderparams = [
'actus' => $qm->getActualites($date),
'transformationDigitale' => $qm->getTransformationDigitale($date),
'infographie' => $qm->getInfographie($date),
'chiffreDuMois' => $qm->getChiffreDuMois($date),
'citation' => $qm->getCitation($date),
'bienEtre' => $qm->getBienEtre($date),
'podcast' => $podcast,
'idAusha' => $idAusha,
'episodes' => $qm->getPodcastsObjects($date),
'sondage' => [
'details' => $sondage,
'results' => $sondage ? $qm->getSondageResult($sondage['id']) : null,
],
'nextEvent' => $qm->getNextEvent(),
'previousPerdiods' => $qm->getPreviousPeriods(),
'quizrh' => $quizrh,
'quizrhVote' => $quizrhVote,
'quizElectronicInvoices' => $qm->getQuizElectronicInvoice($date),
'quizElectronicInvoicesVote' => $qm->getQuizElectronicInvoiceVote($date),
'origin' => 'actu_mois',
'nofooter' => true,
];
}
$renderparams['socialSharingPage'] = $request->getUri();
$renderparams['getParams'] = $_GET;
$renderparams['cabinet'] = $accountingFirm;
$renderparams['cabinetWidgetUrl'] = $accountingFirm->getActuv2Widgeturl();
$renderparams['serverActuUrl'] = $site->getServerActuUrl();
// $renderparams['serverActuUrl'] = "http://actucontent.loc:8080"; // test line
$renderparams['serverUrl'] = "https://actucontent.lagence.expert";
// $renderparams['serverUrl'] = "http://agex-w-actu.loc:8000";
return $this->render($template, $renderparams);
}
#[Route(path: '/widget-footer', name: 'widget_actu_footer')]
public function footer(Request $request, AccountingFirmRepository $repository, QueriesV2Manager $qm, WebSite $site, AuthorizedDomainRepository $domains): Response
{
$token = $request->query->get('token');
$host = $request->get('host');
if ($host != "preview") {
$accountingFirm = $repository->findOneBy(['host' => $host]);
if (is_null($accountingFirm)) {
$domains = $domains->findBy(['name' => $host]);
if (is_null($domains)) {
throw new NotFoundHttpException();
}
foreach ($domains as $dom) {
$tmp_ac = $dom->getAccountingFirm();
if ($tmp_ac->getActuv2Token() == $token) {
$accountingFirm = $tmp_ac;
break;
}
}
}
if (is_null($accountingFirm)) {
throw new NotFoundHttpException();
}
}
$podcast = $qm->getPodcast();
$idAusha = null;
if ($podcast->getIdAushaEpisodeEc()) {
$idAusha = $podcast->getIdAushaEpisodeEc();
}
$podcasts = [];
if ($accountingFirm->isActuv2OnlyPodcast()) {
$podcasts = $qm->getPodcastsObjects();
}
$this->templateBase = '/';
return $this->render('widget_actu_juridique_v2/widget-footer.html.twig', [
'cabinet' => $accountingFirm,
'footer' => $qm->getFooterData(),
'episodes' => $podcasts,
'serverActuUrl' => $site->getServerActuUrl(),
'cabinetWidgetUrl' => $accountingFirm->getActuv2Widgeturl(),
'origin' => "actu_mois",
'podcast' => $podcast,
'idAusha' => $idAusha,
'help' => $qm->getHelp(),
// 'serverActuUrl' => "http://actucontent.loc:8000" // test line
]);
}
#[Route(path: '/widget-actu-primary', name: 'widget_actu_primary')]
public function widgetActuPrimary(Request $request, AccountingFirmRepository $repository, QueriesV2Manager $qm, WebSite $site, AuthorizedDomainRepository $domains): Response
{
$token = $request->query->get('token');
$host = $request->get('host');
if ($host != "preview") {
$accountingFirm = $repository->findOneBy(['host' => $host]);
if (is_null($accountingFirm)) {
$domains = $domains->findBy(['name' => $host]);
if (is_null($domains)) {
throw new NotFoundHttpException();
}
foreach ($domains as $dom) {
$tmp_ac = $dom->getAccountingFirm();
if ($tmp_ac->getActuv2Token() == $token) {
$accountingFirm = $tmp_ac;
break;
}
}
}
if (is_null($accountingFirm)) {
throw new NotFoundHttpException();
}
}
$this->templateBase = '/';
$p = $request->getRequestUri();
$pos = strpos($p, '?');
if ($pos !== false) {
$p = substr($p, 0, $pos + 1) . str_replace('?', '&', substr($p, $pos + 1));
}
$route = parse_url($p);
$date = null;
if (isset($route['query'])) {
parse_str($route['query'], $query);
$date = $query['date'] ?? null;
}
return $this->render('widget_actu_juridique_v2/widget-actu-primary.html.twig', [
'cabinet' => $accountingFirm,
'serverActuUrl' => $site->getServerActuUrl(),
'cabinetWidgetUrl' => $accountingFirm->getActuv2Widgeturl(),
'origin' => "actu_mois",
'actus' => $qm->getActualites($date),
// 'serverActuUrl' => "http://actucontent.loc:8000" // test line
]);
}
#[Route(path: '/widget-sondage', name: 'widget_sondage')]
public function widgetSondage(Request $request, AccountingFirmRepository $repository, QueriesV2Manager $qm, WebSite $site, AuthorizedDomainRepository $domains): Response
{
$token = $request->query->get('token');
$host = $request->get('host');
if ($host != "preview") {
$accountingFirm = $repository->findOneBy(['host' => $host]);
if (is_null($accountingFirm)) {
$domains = $domains->findBy(['name' => $host]);
if (is_null($domains)) {
throw new NotFoundHttpException();
}
foreach ($domains as $dom) {
$tmp_ac = $dom->getAccountingFirm();
if ($tmp_ac->getActuv2Token() == $token) {
$accountingFirm = $tmp_ac;
break;
}
}
}
if (is_null($accountingFirm)) {
throw new NotFoundHttpException();
}
}
$this->templateBase = '/';
$p = $request->getRequestUri();
$pos = strpos($p, '?');
if ($pos !== false) {
$p = substr($p, 0, $pos + 1) . str_replace('?', '&', substr($p, $pos + 1));
}
$route = parse_url($p);
$date = null;
if (isset($route['query'])) {
parse_str($route['query'], $query);
$date = $query['date'] ?? null;
}
$sondage = $qm->getSondage($date);
return $this->render('widget_actu_juridique_v2/widget-sondage.html.twig', [
'cabinet' => $accountingFirm,
'serverActuUrl' => $site->getServerActuUrl(),
'cabinetWidgetUrl' => $accountingFirm->getActuv2Widgeturl(),
'origin' => "actu_mois",
'sondage' => [
'details' => $sondage,
'results' => is_null($sondage) ? null : $qm->getSondageResult($sondage['id']),
],
// 'serverActuUrl' => "http://actucontent.loc:8000" // test line
]);
}
#[Route(path: '/widget-podcast', name: 'widget_podcast')]
public function widgetPodcast(Request $request, AccountingFirmRepository $repository, QueriesV2Manager $qm, WebSite $site, AuthorizedDomainRepository $domains): Response
{
$token = $request->query->get('token');
$host = $request->get('host');
if ($host != "preview") {
$accountingFirm = $repository->findOneBy(['host' => $host]);
if (is_null($accountingFirm)) {
$domains = $domains->findBy(['name' => $host]);
if (is_null($domains)) {
throw new NotFoundHttpException();
}
foreach ($domains as $dom) {
$tmp_ac = $dom->getAccountingFirm();
if ($tmp_ac->getActuv2Token() == $token) {
$accountingFirm = $tmp_ac;
break;
}
}
}
if (is_null($accountingFirm)) {
throw new NotFoundHttpException();
}
}
$this->templateBase = '/';
$p = $request->getRequestUri();
$pos = strpos($p, '?');
if ($pos !== false) {
$p = substr($p, 0, $pos + 1) . str_replace('?', '&', substr($p, $pos + 1));
}
$route = parse_url($p);
$date = null;
if (isset($route['query'])) {
parse_str($route['query'], $query);
$date = $query['date'] ?? null;
}
$podcast = $qm->getPodcast($date);
$idAusha = null;
if ($podcast->getIdAushaEpisodeEc()) {
$idAusha = $podcast->getIdAushaEpisodeEc();
}
return $this->render('widget_actu_juridique_v2/widget-podcast.html.twig', [
'cabinet' => $accountingFirm,
'serverActuUrl' => $site->getServerActuUrl(),
'cabinetWidgetUrl' => $accountingFirm->getActuv2Widgeturl(),
'origin' => "actu_mois",
'podcast' => $podcast,
'idAusha' => $idAusha,
// 'serverActuUrl' => "http://actucontent.loc:8000" // test line
]);
}
#[Route(path: '/widget-quizz', name: 'widget_quizz')]
public function widgetQuizz(Request $request, AccountingFirmRepository $repository, QueriesV2Manager $qm, WebSite $site, AuthorizedDomainRepository $domains): Response
{
$token = $request->query->get('token');
$host = $request->get('host');
if ($host != "preview") {
$accountingFirm = $repository->findOneBy(['host' => $host]);
if (is_null($accountingFirm)) {
$domains = $domains->findBy(['name' => $host]);
if (is_null($domains)) {
throw new NotFoundHttpException();
}
foreach ($domains as $dom) {
$tmp_ac = $dom->getAccountingFirm();
if ($tmp_ac->getActuv2Token() == $token) {
$accountingFirm = $tmp_ac;
break;
}
}
}
if (is_null($accountingFirm)) {
throw new NotFoundHttpException();
}
}
$this->templateBase = '/';
$p = $request->getRequestUri();
$pos = strpos($p, '?');
if ($pos !== false) {
$p = substr($p, 0, $pos + 1) . str_replace('?', '&', substr($p, $pos + 1));
}
$route = parse_url($p);
$date = null;
if (isset($route['query'])) {
parse_str($route['query'], $query);
$date = $query['date'] ?? null;
}
$quizrh = $qm->getQuizRh($date);
$quizrhVote = $qm->getQuizRhVote($date);
return $this->render('widget_actu_juridique_v2/widget-quizz.html.twig', [
'cabinet' => $accountingFirm,
'serverActuUrl' => $site->getServerActuUrl(),
'cabinetWidgetUrl' => $accountingFirm->getActuv2Widgeturl(),
'origin' => "actu_mois",
'quizrh' => $quizrh,
'quizrhVote' => $quizrhVote,
// 'serverActuUrl' => "http://actucontent.loc:8000" // test line
]);
}
#[Route(path: '/get-audio-ausha', name: 'w_actu_get_audio_ausha')]
#[Route(path: '/js/agex-actus-juridiques.min.js', name: 'w_actu_embed_old')]
public function getAudioAusha(Request $request)
{
$aushaId = $request->query->get('aushaid');
$aushaToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjczOTY4MjQ2MjU3NzJkYzA2M2ZkMTgyMzVlYzY4ZmFkZWE4MDNhMGI2NzI1NjQ1YzJkODEwM2E2YWYyMTMxZTJkZDZkYjU1NTMyMWQzM2NkIn0.eyJhdWQiOiIxIiwianRpIjoiNzM5NjgyNDYyNTc3MmRjMDYzZmQxODIzNWVjNjhmYWRlYTgwM2EwYjY3MjU2NDVjMmQ4MTAzYTZhZjIxMzFlMmRkNmRiNTU1MzIxZDMzY2QiLCJpYXQiOjE2NjMxNTQ4MTUsIm5iZiI6MTY2MzE1NDgxNSwiZXhwIjo3OTUyNDI4Nzk5LCJzdWIiOiIxMTMwNzEiLCJzY29wZXMiOlsic2hvd3MuaW5kZXhXaXRoR3JhbnRlZCIsInNob3dzLnNob3ciLCJzaG93cy5zaG93LmJ5X3B1YmxpY2lkIiwicGxheWxpc3RzLmluZGV4IiwicGxheWxpc3RzLnN0b3JlIiwicGxheWxpc3RzLnNob3ciLCJwbGF5bGlzdHMudXBkYXRlIiwicGxheWxpc3RzLmRlc3Ryb3kiLCJwbGF5bGlzdHMucG9kY2FzdC5zdG9yZSIsInBsYXlsaXN0cy5wb2RjYXN0LmRlc3Ryb3kiLCJwbGF5bGlzdHMucG9kY2FzdC5tb3ZlIiwicGxheWxpc3RzLmltYWdlLnN0b3JlIiwicGxheWxpc3RzLmltYWdlLmRlc3Ryb3kiLCJwb2RjYXN0cy52aWRlby5pbmRleCIsInBvZGNhc3RzLnZpZGVvLnNob3ciLCJzZWFzb25zLmluZGV4Iiwic2Vhc29ucy5zdG9yZSIsInNlYXNvbnMuc2hvdyIsInNlYXNvbnMuZGVzdHJveSIsInNob3dzLnBvZGNhc3RzLnNlYXNvbi51cGRhdGUiLCJjYW1wYWlnbnMuaW5kZXgiLCJjYW1wYWlnbnMuc2hvdyIsInBvZGNhc3RzLmluZGV4IiwicG9kY2FzdHMuc2hvdyIsInBvZGNhc3RzLnNob3cuYnlfcHVibGljaWQiLCJwb2RjYXN0cy5zdG9yZSIsInBvZGNhc3RzLnVwZGF0ZSIsInBvZGNhc3RzLmRlc3Ryb3kiLCJwb2RjYXN0cy5pbWFnZS5zdG9yZSIsInBvZGNhc3RzLmZpbGUuc3RvcmUiXX0.uWgOLN2_5LAKL9gB0Ij8V5PJjKrwRqAO_wVZ4l0vV73QPPF4MUDUzsYU-1hL4iFFPWanhg018EH_AGZvGdSdrZXqkzBPnqv6TxhL9aCVeayVwvgD-BQwPMJ3E7z27xREEhXH_r6f0d2t_J6SJexVh3AoT8fD2kUyFXh9B95ziWV-vULeHOqtWEZk01YctUyHLFWhIFzajgn8nSHb3hMYfbV4phapZqaegwCBSIxVPJz4yS3Ox0tbI5g-P6fAK5PlE1pKiPXabekYyUN4tPEmpMAQVURM3xcutBXUTMX0H6GCs0ih7KH3cI8SICVrldo3LkbAh8x4uuJJu2aNmv9qHpyxLi9wfmklyWMt0ROuf4dHPiDVLUfwmqnt9UEE4H5jP7hHcrMNCIRzerBgW0cCfKj0wJBtOuYpsqqBou2YTEyYja8uNEQbHpOQT4gT7CJxa575kqKsrTr9tS2k19BPdlxtBoIPQHcVpY9tQ1_TJro72kbE1ooJICZyFYTdHHPX77H4LClYcN4TxHxp8jTp6hXt_BjZbwU7Kl2PIxFV1diK62idKCtBjd_tvnUIuh7sKZeGn-YwCYVZVWRblYmZQ3tmPyje1ZJsgnY_nZIZ1TBwzZf3ucuPRxJJ4vPc3dXkxvLtWUs3bLWnACHCjhRA7LfMNDIlAZoRKHKQI6UNuiE";
$client = new Client(['base_uri' => 'https://developers.ausha.co/v1/podcasts/']);
$headers = [
'Authorization' => 'Bearer ' . $aushaToken,
'accept' => 'application/json',
'content-type' => 'application/json',
];
$ausha_mp3 = null;
$logFile = '../log_ausha.txt';
$origin = "PODCAST_PRIVATE_WidgetPodcastPrivateController";
$url = $aushaId;
$date = (new \DateTime())->format('Y-m-d H:i:s');
file_put_contents($logFile, "[$date] - origin => $origin - avant appel API\n", FILE_APPEND);
try {
$response = $client->request('GET', $aushaId, [
'headers' => $headers
]);
file_put_contents($logFile, "[$date] - origin => $origin - après appel API\n", FILE_APPEND);
if ($response->getStatusCode() === 200) {
file_put_contents($logFile, "succès à l'URL : $url\n", FILE_APPEND);
$ausha = json_decode($response->getBody()->getContents());
if ($ausha->data->audio_url) {
$ausha_mp3 = $ausha->data->audio_url;
}
}
} catch (\Exception $e) {
file_put_contents($logFile, "[$date] - origin => $origin - après appel API\n", FILE_APPEND);
file_put_contents($logFile, $e->getCode() . " - " . $e->getMessage() . "\n", FILE_APPEND);
}
file_put_contents($logFile, "--\n", FILE_APPEND);
return new JsonResponse([
'ausha_mp3' => $ausha_mp3
]);
}
#[Route(path: '/embed', name: 'w_actu_embed')]
#[Route(path: '/js/agex-actus-juridiques.min.js', name: 'w_actu_embed_old')]
public function embed(Request $request, AccountingFirmRepository $repository)
{
$root = $this->getParameter('kernel.project_dir');
$path = $root . '/public/widgets/actus-juridique/widget_actu.js';
$response = new BinaryFileResponse($path);
$response->headers->set('Content-Type', 'text/javascript');
return $response;
}
#[Route(path: '/{filename}.{format}', name: 'w_actu_files')]
public function actu_files(Request $request, string $filename, string $format)
{
$allowed = array('png', 'jpg', 'jpeg', 'gif', 'js', 'svg', 'eot', 'ttf', 'woff');
if (in_array($format, $allowed)) {
$root = $this->getParameter('kernel.project_dir');
$path = $root . '/public/widgets/actus-juridique/' . $filename . '.' . $format;
//dd(file_exists($path), $path, $request->getRequestFormat());
return new BinaryFileResponse($path);
}
return false;
}
#[Route(path: '/widget-dates', name: 'widget_actu_dates')]
public function dates(QueriesV2Manager $qm)
{
$tabData = $qm->getDates();
$tabDates = [];
foreach ($tabData as $lignes) {
foreach ($lignes as $ligne) {
$key = array_search($ligne['date'], array_column($tabDates, 'date'));
if ($key === false) { // cas date jamais ajoutée
$tabDates[] = ['date' => $ligne['date'], 'lien' => 'calendrier-fiscal.php?id=' . $ligne['id']];
} else { // cas date déjà ajoutée, donc plusieurs articles à la même date
$tabDates[$key] = ['date' => $ligne['date'], 'lien' => 'actualites-calendrier-fiscal.php?date=' . $ligne['date']];
}
}
}
return $this->json($tabDates);
}
#[Route(path: '/api/vote/', name: 'widget_actu_vote', methods: ['POST'])]
public function widgetVote(Request $request, QueriesV2Manager $qm): Response
{
$id = $request->get('id');
$value = $request->get('value');
$ip = $request->getClientIp();
$req = $qm->setSondageVote($id, $value, $ip);
return new Response($req);
}
#[Route(path: '/vote-useful', name: 'widget_actu_vote_useful', methods: ['POST'])]
public function widgetVoteUseful(Request $request, QueriesV2Manager $qm): JsonResponse
{
$origin = $request->headers->get('Origin');
// Décoder le JSON envoyé avec la requête
$data = json_decode($request->getContent(), true);
if (json_last_error() !== JSON_ERROR_NONE) {
return new JsonResponse(['success' => false, 'message' => 'Invalid JSON'], 400, [
'Access-Control-Allow-Origin' => $origin ?? '*',
]);
}
// Récupérer les valeurs du JSON
$id = $data['id'] ?? null;
$type = $data['type'] ?? null;
$value = $data['value'] ?? null;
$ip = $request->getClientIp();
// Appeler la méthode pour enregistrer le vote
$req = $qm->setUsefulVote($id, $ip, $type, $value);
return new JsonResponse(['success' => true, 'data' => $req], 200, [
'Access-Control-Allow-Origin' => $origin ?? '*',
]);
}
#[Route(path: '/vote-useful', name: 'widget_actu_vote_useful_options', methods: ['OPTIONS'])]
public function widgetVoteUsefulOptions(Request $request): Response
{
$origin = $request->headers->get('Origin');
return new Response('', 204, [
'Access-Control-Allow-Origin' => $origin ?? '*',
'Access-Control-Allow-Methods' => 'POST, OPTIONS',
'Access-Control-Allow-Headers' => 'Content-Type, Authorization',
'Access-Control-Max-Age' => '3600',
]);
}
#[Route(path: '/voterrh', name: 'widget_actu_voterrh', methods: ['GET'])]
public function widgetVoterrh(Request $request, QueriesV2Manager $qm)
{
$id = $request->get('id');
$reponse = $request->get('reponse');
$ip = $request->getClientIp();
$req = $qm->setQuizVote($id, $reponse, $ip);
return new Response($req);
}
#[Route(path: '/voter-electronic-invoice', name: 'widget_actu_voter_electronic_invoice', methods: ['GET'])]
public function widgetvoterElectronicInvoice(Request $request, QueriesV2Manager $qm)
{
$id = $request->get('id');
$reponse = $request->get('reponse');
$ip = $request->getClientIp();
$req = $qm->setElectronicInvoiceVote($id, $reponse, $ip);
return new Response($req);
}
#[Route(path: '/voter', name: 'widget_actu_voter', methods: ['GET'])]
public function widgetVoter(Request $request, QueriesV2Manager $qm)
{
$fromNewsletter = $request->get('from', false) === 'newsletter';
try {
$id = (int)$request->get('id', true);
$reponse = (int)$request->get('reponse', true);
$retour = $qm->setSondageVote($id, $reponse, $request->getClientIp());
$tabResult = $qm->getSondageResult($id);
} catch (\Exception $e) {
if (!$fromNewsletter) {
throw new \Exception($e->getMessage(), $e->getCode());
}
$retour = false;
}
// Dans le cas où l'on vote par la newsletter, on affiche un message
if ($fromNewsletter) {
$this->templateBase = '/';
return $this->render('widget_actu_juridique_v2/voter.html.twig', [
'retour' => $retour
]);
}
return $this->json([
"results" => $tabResult,
"erreur" => 0
]);
}
#[Route('/sendParticipation', name: 'widget_actu_send_form')]
public function rgpd_send(Request $request, EntityManagerInterface $em, AccountingFirmRepository $accountingFirmRepository, WidgetMailing $mailing)
{
dd("actu du mois");
$email = $request->get('email');
$tel = $request->get('tel');
$firstname = $request->get('firstname');
$linkedin = $request->get('linkedin');
$expertise = $request->get('expertise');
$idCabinet = $request->get('cabinet');
$cabinet = $accountingFirmRepository->findById($idCabinet);
if (!empty($email) && !empty($firstname) && !empty($tel) && !empty($cabinet) && !empty($linkedin) && !empty($expertise)) {
// Vérifier si l'email est dans la blacklist
$blacklistRepo = $em->getRepository(EmailBlacklist::class);
if ($blacklistRepo->isEmailBlacklisted($email)) {
// Incrémenter le compteur de tentatives
$blacklistedEmail = $blacklistRepo->findByEmail($email);
if ($blacklistedEmail) {
$blacklistedEmail->incrementBlockCount();
$em->persist($blacklistedEmail);
$em->flush();
}
return new JsonResponse(['status' => 'error', 'message' => 'Votre email est dans notre liste noire. Impossible d\'envoyer le message.'], 403);
}
$participationContact = new ContactParticipationPlaceExpert;
$participationContact->setEmail($email);
$participationContact->setPhone($tel);
$participationContact->setFirstname($firstname);
$participationContact->setLinkLinkedin($linkedin);
$participationContact->setExpertise($expertise);
$participationContact->setRgpd(true);
$participationContact->setAccountingFirm($cabinet);
$participationContact->setCreatedAt(new DateTimeImmutable());
$em->persist($participationContact);
$em->flush();
//send mail
$mailing->sendParticipationPalToAgenceExpert($cabinet, [ //Envoie à lagence.expert
'name' => $firstname,
'email' => $email,
'tel' => $tel,
'linkedin' => $linkedin,
'expertise' => $expertise,
]);
$mailing->sendParticipationPalToClient($cabinet, [ //Envoie au client
'name' => $firstname,
'email' => $email,
]);
return new JsonResponse('success');
}
return new JsonResponse('error');
}
}