src/Controller/WidgetAppelleTonEcController.php line 110

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\AccountingFirmRepository;
  4. use App\Repository\AuthorizedDomainRepository;
  5. use App\Services\WidgetMailing;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Qferrer\Mjml\Twig\MjmlExtension;
  8. use Response;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  14. use Symfony\Component\Mailer\MailerInterface;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Twig\Environment;
  17. class WidgetAppelleTonEcController extends AbstractController
  18. {
  19.   protected MjmlExtension $mjmlRenderer;
  20.   protected Environment $twig;
  21.   public function __construct(MailerInterface $mailerMjmlExtension $mjmlRendererEnvironment $twig)
  22.     {
  23.         $this->mjmlRenderer $mjmlRenderer;
  24.         $this->twig $twig;
  25.     }
  26.   #[Route('/check-appelle-ton-ec'name'w_appelle_ton_ec_check')]
  27.   public function ctrl_checkAppelleTonEc(Request $requestAccountingFirmRepository $repositorystring $prefix null): JsonResponse
  28.   {
  29.     $token $request->query->get('token');
  30.     $host $request->get('host');
  31.     if ($token && $host) {
  32.       $accountingFirm $repository->findOneBy(['appelleTonEcToken' => $token]);
  33.       $isAuthorized false;
  34.       if ($accountingFirm && in_array($host$accountingFirm->getListAuthorizedDomains())) {
  35.         $isAuthorized true;
  36.       }
  37.       $url $isAuthorized $accountingFirm->getAppelleTonEcWidgetUrl() : null;
  38.     } else {
  39.       $accountingFirm $repository->findOneBy(['host' => $host]);
  40.       $url $accountingFirm $prefix $this->generateUrl('w_appelle_ton_ec_get') : null;
  41.     }
  42.     return $this->json($url);
  43.   }
  44.   #[Route('/widget-appelle-ton-ec'name'w_appelle_ton_ec_get')]
  45.   public function ctrl_widgetAppelleTonEc(Request $requestAccountingFirmRepository $repositoryAuthorizedDomainRepository $domains)
  46.   {
  47.     $token $request->query->get('token');
  48.     $host $request->get('host');
  49.     if ($host != "preview") {
  50.       $accountingFirm $repository->findOneBy(['host' => $host]);
  51.       if (is_null($accountingFirm)) {
  52.         $domains $domains->findBy(['name' => $host]);
  53.         if (is_null($domains)) {
  54.           throw new NotFoundHttpException();
  55.         }
  56.         foreach ($domains as $dom) {
  57.           $tmp_ac $dom->getAccountingFirm();
  58.           if ($tmp_ac->getAppelleTonEcToken() == $token) {
  59.             $accountingFirm $tmp_ac;
  60.             break;
  61.           }
  62.         }
  63.       }
  64.       if (is_null($accountingFirm)) {
  65.         throw new NotFoundHttpException();
  66.       }
  67.     }
  68.     return $this->render('widget_appelle_ton_ec/content.html.twig', [
  69.       'cabinet' => $accountingFirm,
  70.       'videos' => $accountingFirm->getVideoAppelleTonEcs(),
  71.       'contactPath' => $accountingFirm->getActuv2UrlContact()
  72.     ]);
  73.   }
  74.   #[Route('/embed'name'w_appelle_ton_ec_embed')]
  75.   public function embed()
  76.   {
  77.     $root $this->getParameter('kernel.project_dir');
  78.     $path $root '/public/widgets/widget_appelle_ton_ec/widget_appelle_ton_ec.js';
  79.     return new BinaryFileResponse($path);
  80.   }
  81.   #[Route('/{filename}.{format}'name'w_appelle_ton_ec_files')]
  82.   public function appelle_ton_ec_files(string $filenamestring $format)
  83.   {
  84.       $allowed = array('png''jpg''jpeg''gif''js''svg''eot''ttf''woff');
  85.       if (in_array($format$allowed)) {
  86.           $root $this->getParameter('kernel.project_dir');
  87.           $path $root '/public/widget_appelle_ton_ec/' $filename '.' $format;
  88.           return new BinaryFileResponse($path);
  89.       }
  90.       return false;
  91.   }
  92. }