src/Controller/Athena/DefaultController.php line 642

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Athena;
  3. use App\Entity\Athena\Page;
  4. use App\Entity\Athena\User;
  5. use App\Entity\Athena\VideoTutorial;
  6. use App\Form\Athena\DeleteForm;
  7. use App\Service\Asclepios\ClinicService;
  8. use App\Service\Athena\ComingSoonLogoutService;
  9. use App\Service\Athena\ContextService;
  10. use App\Service\Athena\DatatableService;
  11. use App\Service\Athena\PageService;
  12. use App\Service\Athena\TranslationService;
  13. use App\Service\Hephaistos\DateService;
  14. use Doctrine\Persistence\ObjectRepository;
  15. use Exception;
  16. use ReflectionClass;
  17. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  18. use Symfony\Component\HttpFoundation\Cookie;
  19. use Symfony\Component\HttpFoundation\HeaderUtils;
  20. use Symfony\Component\HttpFoundation\JsonResponse;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpFoundation\RequestStack;
  23. use Symfony\Component\HttpFoundation\Response;
  24. use Symfony\Component\HttpKernel\Profiler\Profiler;
  25. use Symfony\Component\Routing\Annotation\Route;
  26. use Symfony\Component\Security\Core\Security;
  27. use Symfony\Contracts\Translation\TranslatorInterface;
  28. class DefaultController extends AbstractController
  29. {
  30.     const DEFAULT_TEMPLATE 'Athena/index';
  31.     const TEMPLATE_EXTENSION '.html.twig';
  32.     const STATUS_MESSAGE 'message';
  33.     const STATUS_WARNING 'warning';
  34.     const STATUS_ERROR 'error';
  35.     const STATUS_EXCEPTION 'exception';
  36.     const TAG_BREADCRUMB 'a-breadcrumb';
  37.     const TAG_BUTTONS 'a-buttons';
  38.     const TAG_JAVASCRIPT 'a-javascript';
  39.     const TAG_KEEP_MODAL_OPENED 'a-keep-modal-opened';
  40.     const TAG_MAIN 'a-main';
  41.     const TAG_MAIN_OVERTITLE 'a-main-overtitle';
  42.     const TAG_MAIN_SUBTITLE 'a-main-subtitle';
  43.     const TAG_MAIN_TITLE 'a-main-title';
  44.     const TAG_MODAL_TITLE 'a-modal-title';
  45.     const TAG_MODAL_CONTENT 'a-modal-content';
  46.     const TAG_MODAL_CLOSABLE 'a-modal-closable';
  47.     const TAG_ERROR_TITLE 'a-error-title';
  48.     const TAG_ERROR_CONTENT 'a-error-content';
  49.     const TAG_PREVENT_URL_UPDATE 'a-prevent-url-update';
  50.     const TAG_REDIRECT 'a-redirect';
  51.     const TAG_REDIRECT_WITHOUT_LOADER 'a-redirect-without-loader';
  52.     const TAG_REDRAW_BRICK_ID 'a-redraw-brick-id';
  53.     const TAG_REDRAW_BRICK_DATAS 'a-redraw-brick-datas';
  54.     const TAG_RELOAD_IFRAME 'a-reload-iframe';
  55.     const TAG_SET_VALUE 'a-set-value';
  56.     const TAG_STATUS 'a-status';
  57.     const TAG_TARGET_BLANK 'a-target-blank';
  58.     const TAG_FORM_BLANK 'a-form-blank';
  59.     const TAG_FORM_BLANK_DATAS 'a-form-blank-datas';
  60.     const TAG_FUNCTION_ON_LOAD 'a-function-on-load';
  61.     const TAG_SCROLL_TO_TOP 'a-scroll-content-to-top';
  62.     const TAG_KEEP_SIDEBAR_MODAL_OPENED 'a-keep-sidebar-modal-opened';
  63.     const TAG_SIDEBAR_MODAL_TITLE 'a-sidebar-modal-title';
  64.     const TAG_SIDEBAR_MODAL_CONTENT 'a-sidebar-modal-content';
  65.     const TAG_HIDE_MAIN_TITLE 'a-hide-main-title';
  66.     const TAG_SIDEBAR_MODAL_ICON 'a-sidebar-modal-icon';
  67.     const TAG_ONBOARDING 'a-onboarding';
  68.     const TAG_SET_INNER_HTML 'a-set-inner-html';
  69.     const TAG_VIDEO_TUTORIAL 'a-video-tutorial';
  70.     protected array $args;
  71.     protected array $cookies;
  72.     protected ClinicService $clinicService;
  73.     protected ContextService $context;
  74.     protected DateService $dateService;
  75.     protected DatatableService $datatableService;
  76.     protected string $domain;
  77.     protected string $entityClass;
  78.     protected string $entityName;
  79.     protected string $file;
  80.     protected string $fileDisposition HeaderUtils::DISPOSITION_ATTACHMENT;
  81.     protected string $fileName;
  82.     protected bool $isJson;
  83.     protected array $otherData;
  84.     protected array $extractData;
  85.     protected PageService $pageService;
  86.     protected ?Request $request;
  87.     protected string $routePrefix;
  88.     protected ?Security $security;
  89.     protected string $template;
  90.     protected TranslationService $translationService;
  91.     protected TranslatorInterface $translator;
  92.     private ComingSoonLogoutService $comingSoonLogoutService;
  93.     private static array $messagesFromService;
  94.     private bool $newDesign false;
  95.     public function __construct(
  96.         ClinicService           $clinicService,
  97.         DatatableService        $datatableService,
  98.         DateService             $dateService,
  99.         PageService             $pageService,
  100.         RequestStack            $requestStack,
  101.         Security                $security,
  102.         TranslationService      $translationService,
  103.         TranslatorInterface     $translator,
  104.         ContextService          $context,
  105.         ComingSoonLogoutService $comingSoonLogoutService
  106.     )
  107.     {
  108.         $this->comingSoonLogoutService $comingSoonLogoutService;
  109.         if ($this->comingSoonLogoutService->isComingSoon()) {
  110.             $this->comingSoonLogoutService->logoutAllConnectedUser();
  111.         }
  112.         $this->args = [];
  113.         $this->cookies = [];
  114.         $this->clinicService $clinicService;
  115.         $this->dateService $dateService;
  116.         $this->datatableService $datatableService;
  117.         $this->file '';
  118.         $this->fileName '';
  119.         $this->otherData = [];
  120.         $this->extractData = [];
  121.         $this->isJson false;
  122.         $this->pageService $pageService;
  123.         $this->request $requestStack->getCurrentRequest();
  124.         $this->security $security;
  125.         $this->template self::DEFAULT_TEMPLATE;
  126.         $this->translationService $translationService;
  127.         $this->translator $translator;
  128.         self::$messagesFromService = [];
  129.         $reflection = new ReflectionClass(get_class($this));
  130.         foreach ($reflection->getAttributes() as $attribute) {
  131.             if (isset($attribute->getArguments()['name'])) {
  132.                 if ('Symfony\Component\Routing\Annotation\Route' === $attribute->getName()) {
  133.                     $this->routePrefix $attribute->getArguments()['name'];
  134.                 } else {
  135.                     switch ($attribute->getArguments()[0]) {
  136.                         case 'entity':
  137.                             $this->entityClass $attribute->getArguments()['name'];
  138.                             $tabEntity explode('\\'$this->entityClass);
  139.                             $this->entityName end($tabEntity);
  140.                             break;
  141.                         case 'domain':
  142.                             $this->domain $attribute->getArguments()['name'];
  143.                             break;
  144.                     }
  145.                 }
  146.             }
  147.         }
  148.         $this->context $context;
  149.     }
  150.     public function getResponse(): Response
  151.     {
  152.         $clinicDatas = ['sign' => null];
  153.         if ($clinic $this->getContext()->get('clinic')) {
  154.             $clinicDatas = [
  155.                 'sign' => $clinic->getSign(),
  156.                 'slug' => $this->getParameter('prestashop.url') . '/mon-veterinaire/' $clinic->getSlug(),
  157.                 'hasShop' => $clinic->getClubvetShop(),
  158.                 'hasWebSite' => $clinic->getClubvetWeb(),
  159.                 'clinicSiteUrl' => $clinic->getClubvetWeb() ? $this->clinicService->getClinicDomain($clinic) : '',
  160.                 'hasAdvPhoneNumber' => $this->clinicService->getClinicSalesman($clinic)?->getAdvPhoneNumber() ?? false,
  161.                 'isVeterinary' =>
  162.                     in_array('ROLE_VETERINARY'$this->getUser()->getRoles()) ||
  163.                     in_array('ROLE_ASV_LIGHT'$this->getUser()->getRoles()) ||
  164.                     in_array('ROLE_ASV'$this->getUser()->getRoles()),
  165.                 'hasBusinessSoftware' => $this->security->isGranted('IS_IMPERSONATOR') ? true : (bool)$clinic->getBusinessSoftware(),
  166.             ];
  167.         }
  168.         foreach (self::$messagesFromService as $message) {
  169.             $this->addStatus($message['text'], $message['severity'], $message['domain']);
  170.         }
  171.         if ($this->file && $this->fileName) {
  172.             $response = new Response($this->file);
  173.             $response->headers->set('Content-Disposition'HeaderUtils::makeDisposition(
  174.                 $this->fileDisposition,
  175.                 $this->fileNamepreg_replace('#^.*\.#'md5($this->fileName) . '.'$this->fileName)
  176.             ));
  177.             if ($this->fileDisposition === HeaderUtils::DISPOSITION_INLINE) {
  178.                 $fileName explode('.'$this->fileName);
  179.                 $response->headers->set('Content-Type''application/' array_pop($fileName));
  180.             }
  181.             return $response;
  182.         }
  183.         if ('fetch' === $this->request->headers->get('A-Sending-Method') || $this->isJson) {
  184.             if (
  185.                 str_contains($this->request->getRequestUri(), 'admin/clinic') &&
  186.                 str_contains($this->request->getRequestUri(), 'choose') &&
  187.                 !str_contains($this->request->getRequestUri(), 'choosePricePlan')
  188.             ) {
  189.                 $this->setContent('searchClinicsUrl'$this->generateUrl('adminClinicSearchClinics'));
  190.                 $this->setContent('a-switch-clinic'$clinicDatas);
  191.             }
  192.             if ($page $this->getRepository(Page::class)->findOneByPath($this->request->getRequestUri())) {
  193.                 $breadcrumb = [];
  194.                 while ($page) {
  195.                     $breadcrumb[] = ['link' => $page->getPath(), 'label' => $this->translationService->getContent($page'label')];
  196.                     $page $page->getParent();
  197.                 }
  198.                 $this->args[self::TAG_BREADCRUMB] = array_reverse($breadcrumb);
  199.             }
  200.             if ($this->security->getUser() === null) {
  201.                 $response $this->json(['a-reload' => true]);
  202.             } else {
  203.                 if ('true' === $this->request->headers->get('A-Fetching-Menu')) {
  204.                     $this->setContent('a-pages'$this->pageService->getPages());
  205.                 }
  206.                 if (self::DEFAULT_TEMPLATE != $this->template) {
  207.                     $this->args[self::TAG_MAIN] = $this->renderView(
  208.                         $this->template self::TEMPLATE_EXTENSION,
  209.                         $this->args
  210.                     );
  211.                 }
  212.                 if (
  213.                     empty($this->args[self::TAG_PREVENT_URL_UPDATE])
  214.                     && !empty($this->args[self::TAG_MAIN])
  215.                 ) {
  216.                     // display video tutorial, if any, in header
  217.                     $this->args[self::TAG_VIDEO_TUTORIAL] = $this->getVideoTutorialUrl();
  218.                     if ($this->newDesign) {
  219.                         $this->addJS('document.body.classList.add(\'design-2025\');');
  220.                     } else {
  221.                         $this->addJS('document.body.classList.remove(\'design-2025\');');
  222.                     }
  223.                 }
  224. //                if ($clinic
  225. //                    && $clinic->getClubvetShop()
  226. //                    && empty($this->args[self::TAG_MODAL_CONTENT])
  227. //                    && empty($this->args[self::TAG_REDIRECT])
  228. //                    && empty($this->args[self::TAG_REDIRECT_WITHOUT_LOADER])
  229. //                    && !$this->request->cookies->get('alertHolidaySummer2025')
  230. //                ) {
  231. //                    $this->addCookie('alertHolidaySummer2025', '1');
  232. //                    if ($this->request->get('_route') !== 'adminAdministrationHolidayIndex') {
  233. //                        $this->setModal(
  234. //                            'Vous partez aussi en vacances ?',
  235. //                            '
  236. //                                <p class="mb-1">N’oubliez pas d’activer le mode vacances directement depuis votre espace vétérinaire ClubVET Shop afin d’avertir vos clients de votre absence.</p>
  237. //                                <p class="mb-1">
  238. //                                    <span class="font-bold">Bon à savoir</span> : les commandes d’abonnement de vos clients, prévues pendant la période de fermeture de la clinique, seront annulées.<br/>
  239. //                                    Les clients sont informés par e-mail à deux reprises : une première fois lors de l’envoi de votre message de congés, puis une seconde fois lors de l’annulation automatique, 3 jours avant la date prévue de réception.
  240. //                                </p>
  241. //                                <p class="flex justify-between gap-2">
  242. //                                    <a
  243. //                                        href="https://xs4xg.mjt.lu/nl3/IrJhnnAzmvnKaFmRsULMRQ?m=AUAAAU7EgGAAAAAAAAAAAKpkxpMAAAAAF1AAAAAAAA27zwBmqMe-pZ-NByaTSG-YlD08x2njaAANpOw&b=1e897e7e&e=dfc0cc58&x=clFl3uxmAix1csWcfeNWGg"
  244. //                                        target="_blank"
  245. //                                        class="bg-secondary text-center text-white rounded-lg align-middle cursor-pointer inline-flex items-center justify-center min-h-10 px-3"
  246. //                                    >
  247. //                                        <span class="material-symbols-outlined flex justify-center mr-2">help</span>
  248. //                                        Tutoriel
  249. //                                    </a>
  250. //                                    <a
  251. //                                        href="' . $this->generateUrl('adminAdministrationHolidayIndex') . '"
  252. //                                        a-click="fetch"
  253. //                                        a-modal="closer"
  254. //                                        class="bg-secondary text-center text-white rounded-lg align-middle cursor-pointer inline-flex items-center justify-center min-h-10 px-3"
  255. //                                    >
  256. //                                        <span class="material-symbols-outlined flex justify-center mr-2">beach_access</span>
  257. //                                        Activer le mode vacances
  258. //                                    </a>
  259. //                                '
  260. //                        );
  261. //                    }
  262. //                }
  263.                 $response $this->json($this->args);
  264.             }
  265.         } else {
  266.             if ($user $this->security->getUser()) {
  267.                 $this->args['user'] = [
  268.                     'firstname' => $user->getFirstname(),
  269.                     'lastname' => $user->getLastname(),
  270.                     'avatar' => $user->getAvatar()?->getUrl(),
  271.                     'onboardingStep' => $user->getOnboardingStep(),
  272.                     'screenResolutions' => $user->getScreenResolutions(),
  273.                 ];
  274.             }
  275.             $this->setContent('searchClinicsUrl'$this->generateUrl('adminClinicSearchClinics'));
  276.             $this->setContent('a-switch-clinic'$clinicDatas);
  277.             $this->setContent('canEditVideoTutorial'$this->canEditVideoTutorial());
  278.             $this->setContent('newDesign'$this->newDesign);
  279.             $response $this->render(
  280.                 $this->template self::TEMPLATE_EXTENSION,
  281.                 $this->args
  282.             );
  283.         }
  284.         if (count($this->cookies)) {
  285.             try {
  286.                 $expire $this->dateService->getDate(interval'P1Y');
  287.                 foreach ($this->cookies as $name => $value) {
  288.                     $response->headers->setCookie(new Cookie($name$value$expire));
  289.                 }
  290.             } catch (Exception $exception) {
  291.                 $this->addException($exception);
  292.             }
  293.         }
  294.         return $response;
  295.     }
  296.     public function setContent(string $keymixed $content, ?array $args null, ?string $domain null): self
  297.     {
  298.         $this->args[$key] = (is_null($args) ?
  299.             (is_string($content) ? $this->trans($content$domain) : $content) :
  300.             $this->renderView(
  301.                 $content self::TEMPLATE_EXTENSION,
  302.                 $args
  303.             )
  304.         );
  305.         return $this;
  306.     }
  307.     public function setMain(string $content, ?array $args null): self
  308.     {
  309.         return $this->setContent(self::TAG_MAIN$content$args);
  310.     }
  311.     public function setMainTitle(string $content, ?string $domain null): self
  312.     {
  313.         return $this->setContent(self::TAG_MAIN_TITLE$this->trans($content$domain));
  314.     }
  315.     public function hideMainTitle(): self
  316.     {
  317.         return $this->setContent(self::TAG_HIDE_MAIN_TITLEtrue);
  318.     }
  319.     public function setMainSubTitle(string $content, ?string $domain null): self
  320.     {
  321.         return $this->setContent(self::TAG_MAIN_SUBTITLE$this->trans($content$domain));
  322.     }
  323.     public function setMainOverTitle(string $content, ?string $domain null): self
  324.     {
  325.         return $this->setContent(self::TAG_MAIN_OVERTITLE$this->trans($content$domain));
  326.     }
  327.     public function setRedirect(string $url): self
  328.     {
  329.         return $this->setContent(self::TAG_REDIRECT$url);
  330.     }
  331.     public function setRedirectWithoutLoader(string $url): self
  332.     {
  333.         return $this->setContent(self::TAG_REDIRECT_WITHOUT_LOADER$url);
  334.     }
  335.     public function setModal(string $titlestring $content, ?array $args null, ?string $domain null): self
  336.     {
  337.         return $this
  338.             ->setContent(self::TAG_MODAL_TITLE$this->trans($title$domain))
  339.             ->setContent(self::TAG_MODAL_CONTENT$content$args)
  340.             ->setContent(self::TAG_MODAL_CLOSABLEtrue);
  341.     }
  342.     public function setUnclosableModal(string $titlestring $content, ?array $args null, ?string $domain null): self
  343.     {
  344.         return $this
  345.             ->setContent(self::TAG_MODAL_TITLE$this->trans($title$domain))
  346.             ->setContent(self::TAG_MODAL_CONTENT$content$args)
  347.             ->setContent(self::TAG_MODAL_CLOSABLEfalse);
  348.     }
  349.     public function setWaitingModal(string $filesstring $subjectstring $bodybool $plural false): self
  350.     {
  351.         return $this
  352.             ->addJS('Athena.programDeferredDeliveryCheck();')
  353.             ->setContent(self::TAG_MODAL_TITLE, ($plural 'Vos fichiers sont' 'Votre fichier est') . ' en cours de préparation')
  354.             ->setcontent(self::TAG_MODAL_CONTENT'Athena/DeferredDelivery/waitingModal', [
  355.                 'files' => $files,
  356.                 'plural' => $plural,
  357.                 'subject' => $subject,
  358.                 'body' => $body,
  359.             ])
  360.             ->setContent(self::TAG_MODAL_CLOSABLEfalse);
  361.     }
  362.     public function setSidebarModal(string $titlestring $contentstring $iconSb, ?array $args null, ?string $domain null): self
  363.     {
  364.         return $this
  365.             ->setContent(self::TAG_SIDEBAR_MODAL_TITLE$this->trans($title$domain))
  366.             ->setContent(self::TAG_SIDEBAR_MODAL_CONTENT$content$args)
  367.             ->setContent(self::TAG_SIDEBAR_MODAL_ICON$iconSb);
  368.     }
  369.     public function setError(string $titlestring $content, ?array $args null, ?string $domain null): self
  370.     {
  371.         return $this
  372.             ->setContent(self::TAG_ERROR_TITLE$this->trans($title$domain))
  373.             ->setContent(self::TAG_ERROR_CONTENT$content$args);
  374.     }
  375.     public function setTemplate(string $template): self
  376.     {
  377.         $this->template $template;
  378.         return $this;
  379.     }
  380.     public function setReloadIframe(): self
  381.     {
  382.         $this->args[self::TAG_RELOAD_IFRAME] = true;
  383.         return $this;
  384.     }
  385.     /**
  386.      * @param $key string|array
  387.      * @param $value ?string
  388.      * @return $this
  389.      */
  390.     public function setValue($key$value null): self
  391.     {
  392.         if (is_array($key)) {
  393.             $this->args[self::TAG_SET_VALUE] = json_encode($key);
  394.         } else {
  395.             $this->args[self::TAG_SET_VALUE] = json_encode(['key' => $key'value' => $value]);
  396.         }
  397.         return $this;
  398.     }
  399.     public function setInnerHTML(array $data): self
  400.     {
  401.         if (isset($this->args[self::TAG_SET_INNER_HTML])) {
  402.             $data array_merge(json_decode($this->args[self::TAG_SET_INNER_HTML], true), $data);
  403.         }
  404.         $this->args[self::TAG_SET_INNER_HTML] = json_encode($data);
  405.         return $this;
  406.     }
  407.     public function preventUrlUpdate(): self
  408.     {
  409.         $this->args[self::TAG_PREVENT_URL_UPDATE] = true;
  410.         return $this;
  411.     }
  412.     public function addCookie(string $namestring $value): self
  413.     {
  414.         $this->cookies[$name] = $value;
  415.         return $this;
  416.     }
  417.     public function addStatus(
  418.         string  $message,
  419.         string  $type self::STATUS_MESSAGE,
  420.         ?string $domain null
  421.     ): self
  422.     {
  423.         if (!isset($this->args[self::TAG_STATUS])) {
  424.             $this->args[self::TAG_STATUS] = [];
  425.         }
  426.         $this->args[self::TAG_STATUS][] = [
  427.             'text' => $this->trans($message$domain),
  428.             'severity' => $type,
  429.         ];
  430.         return $this;
  431.     }
  432.     public static function addStatusFromService(
  433.         string  $message,
  434.         string  $type self::STATUS_MESSAGE,
  435.         ?string $domain null
  436.     ): void
  437.     {
  438.         self::$messagesFromService[] = [
  439.             'text' => $message,
  440.             'severity' => $type,
  441.             'domain' => $domain,
  442.         ];
  443.     }
  444.     public function addButton(
  445.         string  $url,
  446.         string  $label,
  447.         string  $icon,
  448.         string  $class '',
  449.         ?string $domain null,
  450.         string  $wrapper '',
  451.         bool    $fetch true
  452.     ): self
  453.     {
  454.         if (!isset($this->args[self::TAG_BUTTONS])) {
  455.             $this->args[self::TAG_BUTTONS] = [];
  456.         }
  457.         $this->args[self::TAG_BUTTONS][] = [
  458.             'url' => $url,
  459.             'label' => $this->trans($label$domain),
  460.             'icon' => $icon,
  461.             'class' => $class,
  462.             'wrapper' => $wrapper,
  463.             'fetch' => $fetch,
  464.         ];
  465.         return $this;
  466.     }
  467.     public function addException(Exception $exception): self
  468.     {
  469.         return $this->setError('Exception'$exception->getMessage());
  470.     }
  471.     public function addJS(string $js): self
  472.     {
  473.         if (!isset($this->args[self::TAG_JAVASCRIPT])) {
  474.             $this->args[self::TAG_JAVASCRIPT] = '';
  475.         }
  476.         $this->args[self::TAG_JAVASCRIPT] .= $js;
  477.         return $this;
  478.     }
  479.     public function getRepository(string $class): ObjectRepository
  480.     {
  481.         return $this->getDoctrine()->getManager()->getRepository($class);
  482.     }
  483.     public function persist(): self
  484.     {
  485.         foreach (func_get_args() as $entity) {
  486.             $this->getDoctrine()->getManager()->persist($entity);
  487.         }
  488.         return $this;
  489.     }
  490.     public function remove(): self
  491.     {
  492.         foreach (func_get_args() as $entity) {
  493.             $this->getDoctrine()->getManager()->remove($entity);
  494.         }
  495.         return $this;
  496.     }
  497.     public function clear(): self
  498.     {
  499.         foreach (func_get_args() as $entity) {
  500.             $this->getDoctrine()->getManager()->clear($entity);
  501.         }
  502.         return $this;
  503.     }
  504.     public function detach(): self
  505.     {
  506.         foreach (func_get_args() as $entity) {
  507.             $this->getDoctrine()->getManager()->detach($entity);
  508.         }
  509.         return $this;
  510.     }
  511.     public function flush(): self
  512.     {
  513.         if (count(func_get_args())) {
  514.             foreach (func_get_args() as $entity) {
  515.                 $this->getDoctrine()->getManager()->flush($entity);
  516.             }
  517.         } else {
  518.             $this->getDoctrine()->getManager()->flush();
  519.         }
  520.         return $this;
  521.     }
  522.     public function trans(string $stringstring $domain null, array $args = [], ?string $locale null): string
  523.     {
  524.         return $this->translator->trans($string$args$domain$locale);
  525.     }
  526.     public function keepModalOpened(): self
  527.     {
  528.         $this->args[self::TAG_KEEP_MODAL_OPENED] = true;
  529.         return $this;
  530.     }
  531.     public function keepSideBarModalOpened(): self
  532.     {
  533.         $this->args[self::TAG_KEEP_SIDEBAR_MODAL_OPENED] = true;
  534.         return $this;
  535.     }
  536.     public function scrollToTop(): self
  537.     {
  538.         $this->args[self::TAG_SCROLL_TO_TOP] = true;
  539.         return $this;
  540.     }
  541.     public function openOnboarding($datas): self
  542.     {
  543.         $this->args[self::TAG_ONBOARDING] = json_encode($datas);
  544.         return $this;
  545.     }
  546.     public function redirectByFetch(string $url): Response
  547.     {
  548.         return $this
  549.             ->setMain(
  550.                 'Athena/redirect',
  551.                 [
  552.                     'url' => $url,
  553.                 ]
  554.             )
  555.             ->getResponse();
  556.     }
  557.     public function redirectToRouteByFetch(string $route, array $parameters = []): Response
  558.     {
  559.         return $this->redirectByFetch($this->generateUrl($route$parameters));
  560.     }
  561.     #[Route('/'name'home')]
  562.     public function home(): Response
  563.     {
  564.         return $this->redirectToRoute('admin');
  565.     }
  566.     #[Route('/admin'name'admin')]
  567.     public function admin(): Response
  568.     {
  569.         return $this->getResponse();
  570.     }
  571.     #[Route('/health_check'name'healthCheck')]
  572.     public function healthCheck(?Profiler $profiler): Response
  573.     {
  574.         $profiler?->disable();
  575.         $return = [];
  576.         try {
  577.             if (!$this->getRepository(User::class)->find(1)) {
  578.                 throw new \Exception('Problème de connexion à la DB'1null);
  579.             }
  580.             $return['DB'] = 'OK';
  581.         } catch (\Exception $e) {
  582.             return new Response(json_encode(['error' => $e->getCode(), 'message' => $e->getMessage(), 'line' => $e->getLine()]), 500);
  583.         }
  584.         return new Response(json_encode($return), 200);
  585.     }
  586.     public function handleGenericForm(
  587.         Request $request,
  588.         mixed   $object,
  589.         string  $type,
  590.         array   $optionsForRoute = [],
  591.         bool    $delete false,
  592.         array   $options = [],
  593.         ?object $service null,
  594.         ?string $preProcess null,
  595.         ?string $postProcess null,
  596.         ?string $updateProcess null,
  597.         ?string $validateProcess null,
  598.     ): object
  599.     {
  600.         if (is_string($object)) {
  601.             $object = new $object();
  602.         }
  603.         $form $this->createForm(
  604.             $type,
  605.             $object,
  606.             array_merge(
  607.                 ['action' => $this->generateUrl($request->attributes->get('_route'), $optionsForRoute)],
  608.                 $options
  609.             )
  610.         );
  611.         $form->handleRequest($request);
  612.         if ($form->isSubmitted()) {
  613.             if ($service && $validateProcess) {
  614.                 $service->$validateProcess($object$form);
  615.             }
  616.             if ($form->isValid()) {
  617.                 if ($service && $preProcess) {
  618.                     try {
  619.                         $service->$preProcess($object$form);
  620.                     } catch (\Exception $e) {
  621.                         $this->addException($e);
  622.                         return $form;
  623.                     }
  624.                 }
  625.                 if ($service && $updateProcess) {
  626.                     try {
  627.                         $service->$updateProcess($object$form);
  628.                     } catch (\Exception $e) {
  629.                         $this->addException($e);
  630.                         return $form;
  631.                     }
  632.                 } elseif ($object) {
  633.                     if ($delete) {
  634.                         $this->remove($object)->flush();
  635.                     } else {
  636.                         $this->persist($object)->flush();
  637.                     }
  638.                 }
  639.                 if ($service && $postProcess) {
  640.                     try {
  641.                         $service->$postProcess($object$form$this);
  642.                     } catch (\Exception $e) {
  643.                         $this->addException($e);
  644.                         return $form;
  645.                     }
  646.                 }
  647.                 return $object;
  648.             }
  649.         }
  650.         return $form;
  651.     }
  652.     public function getAvailableRoles(): array
  653.     {
  654.         $result = [];
  655.         foreach ($this->getParameter('security.role_hierarchy.roles') as $role => $roles) {
  656.             $result[$this->trans('User.controller.User.Roles.' $role'Athena')] = $role;
  657.         }
  658.         krsort($result);
  659.         if (!$this->security->isGranted('ROLE_SUPER_ADMIN')) {
  660.             unset($result['ROLE_SUPER_ADMIN']);
  661.         }
  662.         return $result;
  663.     }
  664.     public function getTranslatedAvailableRoles(): array
  665.     {
  666.         $result = [];
  667.         foreach ($this->getParameter('security.role_hierarchy.roles') as $role => $roles) {
  668.             $result[$role] = $this->trans('User.controller.User.Roles.' $role'Athena');
  669.         }
  670.         ksort($result);
  671.         if (!$this->security->isGranted('ROLE_SUPER_ADMIN')) {
  672.             unset($result['ROLE_SUPER_ADMIN']);
  673.         }
  674.         return $result;
  675.     }
  676.     public function _datatableIndex(
  677.         string  $template 'Athena/datatable',
  678.         bool    $addButton true,
  679.         bool    $searchField true,
  680.         array   $additionalButton = [],
  681.         ?string $getDatatableUrl null,
  682.         ?string $createUrl null
  683.     ): Response
  684.     {
  685.         // set filters from url
  686.         $search $this->request->query->get('search');
  687.         $filters $this->request->query->get('filters');
  688.         if ($search || $filters) {
  689.             $session $this->request->getSession();
  690.             $additionalSearchField = [];
  691.             $datatablesFilters $session->get('datatablesFilters', []);
  692.             if (isset($datatablesFilters[$this->routePrefix])) {
  693.                 $additionalSearchField $datatablesFilters[$this->routePrefix]['additionalSearchField'] ?? [];
  694.             }
  695.             if ($filters) {
  696.                 foreach ($filters as $field => $value) {
  697.                     if ('' !== $value) {
  698.                         $additionalSearchField[$field] = $value;
  699.                     } elseif (isset($additionalSearchField[$field])) {
  700.                         unset($additionalSearchField[$field]);
  701.                     }
  702.                 }
  703.             }
  704.             $datatablesFilters[$this->routePrefix] = [
  705.                 'search' => $search ?: $datatablesFilters[$this->routePrefix]['search'] ?? '',
  706.                 'additionalSearchField' => $additionalSearchField,
  707.             ];
  708.             $session->set('datatablesFilters'$datatablesFilters);
  709.         }
  710.         $this
  711.             ->setMainTitle(
  712.                 $this->translator->trans(
  713.                     $this->entityName '.controller.' $this->entityName '.main_title',
  714.                     [],
  715.                     $this->domain
  716.                 )
  717.             )
  718.             ->setMain(
  719.                 $template,
  720.                 [
  721.                     'datatableUrl' => $getDatatableUrl ?: $this->generateUrl($this->routePrefix 'GetDatatable'),
  722.                     'other' => $this->otherData,
  723.                     'searchField' => (int)$searchField
  724.                 ]
  725.             );
  726.         if ($addButton) {
  727.             $this->addButton(
  728.                 $createUrl ?: $this->generateUrl($this->routePrefix 'Create'),
  729.                 $this->entityName '.controller.' $this->entityName '.buttons.create',
  730.                 'add_circle_outline',
  731.                 '',
  732.                 $this->domain
  733.             );
  734.         }
  735.         if (!empty($additionalButton)) {
  736.             $this->addButton(
  737.                 $additionalButton['url'] ?? '',
  738.                 $additionalButton['text'] ?? '',
  739.                 $additionalButton['icon'] ?? '',
  740.                 '',
  741.                 $this->domain
  742.             );
  743.         }
  744.         return $this->getResponse();
  745.     }
  746.     public function _datatable(
  747.         int             $page 1,
  748.         int             $limit 1,
  749.         string          $sort 'none',
  750.         string          $search '',
  751.         string          $datatableTemplate 'Default',
  752.         ?ContextService $context null,
  753.         ?array          $preLoadedDatas null,
  754.         string          $templateForPreload '',
  755.         array           $optionsForPreload = [],
  756.         array           $additionalSearchField = [],
  757.         int             $countForPreload = -1
  758.     ): Response
  759.     {
  760.         // restore or save filters in session
  761.         $session $this->request->getSession();
  762.         $datatablesFilters $session->get('datatablesFilters', []);
  763.         if ($this->request->get('firstLoad'false)) {
  764.             if (isset($datatablesFilters[$this->routePrefix])) {
  765.                 $search $datatablesFilters[$this->routePrefix]['search'] ?? '';
  766.                 $additionalSearchField $datatablesFilters[$this->routePrefix]['additionalSearchField'] ?? [];
  767.             }
  768.         } else {
  769.             $datatablesFilters[$this->routePrefix] = [
  770.                 'search' => $search,
  771.                 'additionalSearchField' => $additionalSearchField,
  772.             ];
  773.             $session->set('datatablesFilters'$datatablesFilters);
  774.         }
  775.         $this->setContent(
  776.             'entity',
  777.             $this->translator->trans(
  778.                 $this->entityName '.template.index.entity.plural',
  779.                 [],
  780.                 $this->domain
  781.             )
  782.         );
  783.         $datatable $this->datatableService->buildDatatable(
  784.             $this->entityClass,
  785.             $page,
  786.             $limit,
  787.             $sort,
  788.             $search,
  789.             $datatableTemplate,
  790.             $context,
  791.             $preLoadedDatas,
  792.             $templateForPreload,
  793.             $optionsForPreload,
  794.             $additionalSearchField,
  795.             $countForPreload
  796.         );
  797.         foreach ($datatable as $key => $val) {
  798.             $this->setContent($key$val);
  799.         }
  800.         return $this->getResponse();
  801.     }
  802.     public function _create(
  803.         Request $request,
  804.         string  $formClass,
  805.         array   $optionsForRoute = [],
  806.         bool    $delete false,
  807.         array   $options = [],
  808.         ?object $service null,
  809.         ?string $preProcess null,
  810.         ?string $postProcess null,
  811.         ?string $updateProcess null,
  812.         ?string $validateProcess null,
  813.         bool    $modal true,
  814.         string  $content 'Athena/genericType',
  815.         array   $args = [],
  816.         bool    $returnRequest false,
  817.         string  $postUpdateMessage null,
  818.         string  $postUpdateStatus null,
  819.         array   $buttonAttribute = [],
  820.         ?string $entityName null,
  821.         ?object $object null,
  822.         ?string $postRedirectUrl null,
  823.     )
  824.     {
  825.         $return $this->handleGenericForm(
  826.             $request,
  827.             $object ?: $this->entityClass,
  828.             $formClass,
  829.             $optionsForRoute,
  830.             $delete,
  831.             $options,
  832.             $service,
  833.             $preProcess,
  834.             $postProcess,
  835.             $updateProcess,
  836.             $validateProcess
  837.         );
  838.         if ($return instanceof $this->entityClass) {
  839.             if ($postUpdateMessage) {
  840.                 $this->addStatus($postUpdateMessage$postUpdateStatus ?? self::STATUS_MESSAGE);
  841.             }
  842.             if ($postRedirectUrl) {
  843.                 return $this
  844.                     ->setRedirect($postRedirectUrl)
  845.                     ->getResponse();
  846.             } elseif ($returnRequest) {
  847.                 return $this->index($request);
  848.             } else {
  849.                 return $this->index();
  850.             }
  851.         } else {
  852.             if ($modal) {
  853.                 $this->setModal(
  854.                     ($entityName ?? $this->entityName) . '.controller.' . ($entityName ?? $this->entityName) . '.modal.createTitle',
  855.                     $content,
  856.                     array_merge($args, ['form' => $return->createView(), 'entity' => ($entityName ?? $this->entityName)]),
  857.                     $this->domain
  858.                 );
  859.             } else {
  860.                 $this->setMainTitle(
  861.                     $this->translator->trans(
  862.                         $this->entityName '.controller.' $this->entityName '.main.createTitle',
  863.                         [],
  864.                         $this->domain
  865.                     )
  866.                 )
  867.                     ->setMain(
  868.                         $content,
  869.                         array_merge($args, ['form' => $return->createView(), 'entity' => $this->entityName])
  870.                     );
  871.                 if ($buttonAttribute && !empty($buttonAttribute)) {
  872.                     $this->addButton(
  873.                         $this->generateUrl($buttonAttribute['url']),
  874.                         $this->entityName '.controller.' $this->entityName '.buttons.' $buttonAttribute['label'],
  875.                         $buttonAttribute['icon'],
  876.                         $buttonAttribute['class'],
  877.                         $buttonAttribute['transDomain']
  878.                     );
  879.                 }
  880.             }
  881.             return $this->getResponse();
  882.         }
  883.     }
  884.     public function _update(
  885.         Request $request,
  886.         object  $object,
  887.         string  $formClass,
  888.         array   $optionsForRoute = [],
  889.         bool    $delete false,
  890.         array   $options = [],
  891.         ?object $service null,
  892.         ?string $preProcess null,
  893.         ?string $postProcess null,
  894.         ?string $updateProcess null,
  895.         ?string $validateProcess null,
  896.         bool    $modal true,
  897.         string  $content 'Athena/genericType',
  898.         array   $args = [],
  899.         bool    $returnRequest false,
  900.         string  $postUpdateMessage null,
  901.         string  $postUpdateStatus null,
  902.         ?string $entityName null,
  903.         ?string $postRedirectUrl null,
  904.     ): Response
  905.     {
  906.         $return $this->handleGenericForm(
  907.             $request,
  908.             $object,
  909.             $formClass,
  910.             $optionsForRoute,
  911.             $delete,
  912.             $options,
  913.             $service,
  914.             $preProcess,
  915.             $postProcess,
  916.             $updateProcess,
  917.             $validateProcess
  918.         );
  919.         if ($return instanceof $this->entityClass) {
  920.             if ($postUpdateMessage) {
  921.                 $this->addStatus($postUpdateMessage$postUpdateStatus ?? self::STATUS_MESSAGE);
  922.             }
  923.             if ($postRedirectUrl) {
  924.                 return $this
  925.                     ->setRedirect($postRedirectUrl)
  926.                     ->getResponse();
  927.             } elseif ($returnRequest) {
  928.                 return $this->index($request);
  929.             } else {
  930.                 return $this->index();
  931.             }
  932.         } else {
  933.             if ($modal) {
  934.                 $this
  935.                     ->setModal(
  936.                         ($entityName ?? $this->entityName) . '.controller.' . ($entityName ?? $this->entityName) . '.modal.updateTitle',
  937.                         $content,
  938.                         array_merge($args, ['form' => $return->createView(), 'entity' => ($entityName ?? $this->entityName)]),
  939.                         $this->domain
  940.                     );
  941.             } else {
  942.                 $this->setMainTitle(
  943.                     $this->translator->trans(
  944.                         $this->entityName '.controller.' $this->entityName '.main.updateTitle',
  945.                         [],
  946.                         $this->domain
  947.                     )
  948.                 )
  949.                     ->setMain(
  950.                         $content,
  951.                         array_merge($args, ['form' => $return->createView(), 'entity' => $this->entityName])
  952.                     );
  953.             }
  954.             return $this->getResponse();
  955.         }
  956.     }
  957.     public function _delete(
  958.         Request $request,
  959.         object  $object,
  960.                 $optionsForRoute,
  961.         string  $postUpdateMessage null,
  962.         string  $postUpdateStatus null,
  963.         array   $options = [],
  964.         ?object $service null,
  965.         ?string $preProcess null,
  966.         ?string $postProcess null,
  967.         ?string $updateProcess null,
  968.         ?string $validateProcess null,
  969.         bool    $returnRequest false,
  970.         ?string $entityName null,
  971.         ?string $postRedirectUrl null,
  972.     )
  973.     {
  974.         if (($return $this->handleGenericForm(
  975.                 $request,
  976.                 $object,
  977.                 DeleteForm::class,
  978.                 $optionsForRoute,
  979.                 true,
  980.                 $options,
  981.                 $service,
  982.                 $preProcess,
  983.                 $postProcess,
  984.                 $updateProcess,
  985.                 $validateProcess
  986.             )) instanceof $this->entityClass) {
  987.             if ($postUpdateMessage) {
  988.                 $this->addStatus($postUpdateMessage$postUpdateStatus ?? self::STATUS_MESSAGE);
  989.             }
  990.             if ($postRedirectUrl) {
  991.                 return $this
  992.                     ->setRedirect($postRedirectUrl)
  993.                     ->getResponse();
  994.             } elseif ($returnRequest) {
  995.                 return $this->index($request);
  996.             } else {
  997.                 return $this->index();
  998.             }
  999.         } else {
  1000.             return $this
  1001.                 ->setModal(
  1002.                     ($entityName ?? $this->entityName) . '.controller.' . ($entityName ?? $this->entityName) . '.modal.deleteTitle',
  1003.                     'Athena/deleteType',
  1004.                     [
  1005.                         'form' => $return->createView(),
  1006.                         'entity' => $this->translator->trans(
  1007.                             ($entityName ?? $this->entityName) . '.controller.' . ($entityName ?? $this->entityName) . '.modal.entity',
  1008.                             [],
  1009.                             $this->domain
  1010.                         ),
  1011.                     ],
  1012.                     $this->domain
  1013.                 )
  1014.                 ->getResponse();
  1015.         }
  1016.     }
  1017.     public function _autocomplete(string $search, ?string $entityClass null): JsonResponse
  1018.     {
  1019.         $result = array();
  1020.         if ($search) {
  1021.             foreach ($this->getRepository($entityClass ?? $this->entityClass)->getAutocomplete($search) as $object) {
  1022.                 $result[] = ['id' => $object->getId(), 'text' => $object->_toAutocomplete()];
  1023.             }
  1024.         }
  1025.         return $this->json($result);
  1026.     }
  1027.     public function _show(
  1028.         string $content,
  1029.         bool   $modal false,
  1030.         array  $args = [],
  1031.         array  $translateParameters = []
  1032.     ): Response
  1033.     {
  1034.         if ($modal) {
  1035.             $this
  1036.                 ->setModal(
  1037.                     $this->entityName '.controller.' $this->entityName '.modal.showTitle',
  1038.                     $content,
  1039.                     array_merge($args, ['entity' => $this->entityName]),
  1040.                     $this->domain
  1041.                 );
  1042.         } else {
  1043.             $this->setMainTitle(
  1044.                 $this->translator->trans(
  1045.                     $this->entityName '.controller.' $this->entityName '.main.showTitle',
  1046.                     $translateParameters,
  1047.                     $this->domain
  1048.                 )
  1049.             )
  1050.                 ->setMain(
  1051.                     $content,
  1052.                     array_merge($args, ['entity' => $this->entityName])
  1053.                 );
  1054.         }
  1055.         return $this->getResponse();
  1056.     }
  1057.     public function getContext(): ContextService
  1058.     {
  1059.         return $this->context;
  1060.     }
  1061.     public function setTargetBlank(string $url, ?array $args null): self
  1062.     {
  1063.         return $this->setContent(self::TAG_TARGET_BLANK$url$args);
  1064.     }
  1065.     public function setFormTargetBlank(string $urlstring $datas, ?array $args null): self
  1066.     {
  1067.         return $this
  1068.             ->setContent(self::TAG_FORM_BLANK$url$args)
  1069.             ->setContent(self::TAG_FORM_BLANK_DATAS$datas$args);
  1070.     }
  1071.     public function setFunctionOnLoad(string $function): self
  1072.     {
  1073.         return $this->setContent(self::TAG_FUNCTION_ON_LOAD$function);
  1074.     }
  1075.     public function _extract(
  1076.         Request $request,
  1077.         mixed   $class '',
  1078.         string  $filename '',
  1079.         string  $search '',
  1080.         array   $additionalSearchFields = [],
  1081.         string  $datatableTemplate '',
  1082.                 $context null
  1083.     )
  1084.     {
  1085.         if (is_array($class)) {
  1086.             $object $class['data'];
  1087.             if (isset($request->request->all()['extract_fields'])) {
  1088.                 $columns = [];
  1089.                 foreach ($request->request->all() as $key => $value) {
  1090.                     if ($key !== 'extract_fields' && $value == 'on') {
  1091.                         $columns[] = $this->trans($key'fields');
  1092.                     }
  1093.                 }
  1094.                 if (empty($columns)) {
  1095.                     return $this->addStatus("Vous devez sélectionner une colonne pour l'extraction!"self::STATUS_ERROR)->setRedirect($this->generateUrl($this->routePrefix 'Index'))->getResponse();
  1096.                 } else {
  1097.                     $res $this->datatableService->filterArray($object$columns);
  1098.                     foreach ($res as &$line) {
  1099.                         foreach ($line as $key => $val) {
  1100.                             if (isset($class['options']['extract']['fields'][$key])) {
  1101.                                 $line[$this->trans($class['options']['extract']['fields'][$key], 'fields')] = $val;
  1102.                                 unset($line[$key]);
  1103.                             }
  1104.                         }
  1105.                     }
  1106.                     $fileName $this->datatableService->export_data_to_csv($res$filename);
  1107.                     $this->setTargetBlank($this->generateUrl($this->routePrefix 'DownloadExtract', ['filename' => $fileName]));
  1108.                     return $this->addStatus("Le fichier a bien été téléchargé!"self::STATUS_MESSAGE)->setRedirect($this->generateUrl($this->routePrefix 'Index'))
  1109.                         ->getResponse();
  1110.                 }
  1111.             }
  1112.             $params '';
  1113.             foreach ($additionalSearchFields as $param) {
  1114.                 $params $params '/' $param;
  1115.             }
  1116.             if (!empty($search)) {
  1117.                 $params $params '/' $search;
  1118.             }
  1119.             return $this
  1120.                 ->setModal(
  1121.                     $this->entityName '.controller.' $this->entityName '.modal.extractTitle',
  1122.                     'Athena/extractFields',
  1123.                     [
  1124.                         'url' => $this->generateUrl($this->routePrefix 'Extract') . $params,
  1125.                         'options' => $class['options']
  1126.                     ],
  1127.                     $this->domain
  1128.                 )
  1129.                 ->getResponse();
  1130.         } else {
  1131.             $object = new $class;
  1132.             if (isset($request->request->all()['extract_fields'])) {
  1133.                 $columns = [];
  1134.                 foreach ($request->request->all() as $key => $value) {
  1135.                     if ($key !== 'extract_fields' && $value == 'on') {
  1136.                         $columns[] = $key;
  1137.                     }
  1138.                 }
  1139.                 if (empty($columns)) {
  1140.                     return $this->addStatus("Vous devez sélectionner une colonne pour l'extraction!"self::STATUS_ERROR)->setRedirect($this->generateUrl($this->routePrefix 'Index'))->getResponse();
  1141.                 } else {
  1142.                     $dat $this->getRepository($class)->getDatatableForDownload($search$datatableTemplate$context$additionalSearchFields);
  1143.                     $arrayDat $this->datatableService->entityToArray($dat$columns$class);
  1144.                     $fileName $this->datatableService->export_data_to_csv($arrayDat$filename);
  1145.                     $this->setTargetBlank($this->generateUrl($this->routePrefix 'DownloadExtract', ['filename' => $fileName]));
  1146.                     return $this->addStatus("Le fichier a bien été téléchargé!"self::STATUS_MESSAGE)->setRedirect($this->generateUrl($this->routePrefix 'Index'))
  1147.                         ->getResponse();
  1148.                 }
  1149.             }
  1150.             $params '';
  1151.             foreach ($additionalSearchFields as $param) {
  1152.                 $params $params '/' $param;
  1153.             }
  1154.             if (!empty($search)) {
  1155.                 $params $params '/' $search;
  1156.             }
  1157.             return $this
  1158.                 ->setModal(
  1159.                     $this->entityName '.controller.' $this->entityName '.modal.extractTitle',
  1160.                     'Athena/extractFields',
  1161.                     [
  1162.                         'url' => $this->generateUrl($this->routePrefix 'Extract') . $params,
  1163.                         'options' => $object->_getMetadataDefault()
  1164.                     ],
  1165.                     $this->domain
  1166.                 )
  1167.                 ->getResponse();
  1168.         }
  1169.     }
  1170.     public function handleS3Files(array $datasstring $subjectstring $body): Response
  1171.     {
  1172.         if (isset($datas['s3Files'])) {
  1173.             $this->setFormTargetBlank($this->generateUrl('adminAwsS3Download'), json_encode($datas));
  1174.         } elseif (isset($datas['files'])) {
  1175.             $this->setWaitingModal(json_encode($datas['files']), $subject$body);
  1176.         } else {
  1177.             $this->addStatus('Une erreur est survenue lors de la création du fichier : ' print_r($datas1), self::STATUS_ERROR);
  1178.         }
  1179.         return $this->getResponse();
  1180.     }
  1181.     /**
  1182.      * @return false|string
  1183.      */
  1184.     public function getVideoTutorialUrl(?string $route null): string|false
  1185.     {
  1186.         $route ??= $this->request->attributes->get('_route');
  1187.         $videoTutorial $this->getRepository(VideoTutorial::class)->findOneByRoute($route);
  1188.         return $videoTutorial $this->generateUrl(
  1189.             'adminVideoViewerIndex',
  1190.             [
  1191.                 'videoUrl' => $videoTutorial->getUrl(),
  1192.                 'title' => $videoTutorial->getTitle() ?: 'Tutoriel vidéo',
  1193.             ]
  1194.         ) : false;
  1195.     }
  1196.     private function canEditVideoTutorial(): string
  1197.     {
  1198.         $user $this->getUser();
  1199.         if ($this->security->isGranted('IS_IMPERSONATOR')) {
  1200.             $user $this->security->getToken()->getOriginalToken()->getUser();
  1201.         }
  1202.         return in_array('ROLE_SUPER_ADMIN'$user?->getRoles(), true) ? '1' '0';
  1203.     }
  1204.     public function setNewDesign(): self
  1205.     {
  1206.         $this->newDesign true;
  1207.         return $this;
  1208.     }
  1209. }