src/Controller/DefaultController.php line 231

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\AAALog;
  4. use App\Entity\Catalogue3en1;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use EasyCorp\Bundle\EasyAdminBundle\Config\Assets;
  7. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  8. use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
  9. use EasyCorp\Bundle\EasyAdminBundle\Config\UserMenu;
  10. use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
  11. use App\Controller\AdminVehicleController;
  12. use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
  13. use App\Entity\Seats;
  14. use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  18. use Symfony\Component\HttpKernel\KernelInterface;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. use Doctrine\ORM\EntityManager;
  21. use App\Repository\VehicleRepository;
  22. use App\Repository\OTCDataRepository;
  23. use App\Repository\JRNLogRepository;
  24. use App\Repository\IssueRepository;
  25. use App\Form\Type\PrintersChoiceType;
  26. use App\Event\IssueEvent;
  27. use App\Entity\Vehicle;
  28. use App\Entity\User;
  29. use App\Entity\Bus;
  30. use App\Entity\COCData;
  31. use App\Entity\Printer;
  32. use App\Entity\Client;
  33. use App\Entity\FinancingCompany;
  34. use App\Entity\CO2Criteria;
  35. use App\Entity\JRNLog;
  36. use App\Entity\FDPGamma;
  37. use App\Entity\OTCData;
  38. use App\Entity\Issue;
  39. use App\Entity\JobLog;
  40. use Symfony\Component\Security\Core\User\UserInterface;
  41. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  42. use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
  43. use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\DashboardControllerInterface;
  44. use Symfony\Component\Messenger\MessageBusInterface;
  45. use Symfony\Contracts\Translation\TranslatorInterface;
  46. class DefaultController extends AbstractDashboardController implements DashboardControllerInterface
  47. {
  48.     /** @var JRNLogRepository $repoJRNLog */
  49.     private $repoJRNLog;
  50.     /** @var VehicleRepository $repoVehicle */
  51.     private $repoVehicle;
  52.     /** @var MessageLogRepository $repoJob */
  53.     private $repoJob;
  54.     /** @var OTCDataRepository $repoOTC */
  55.     private $repoOTC;
  56.     /** @var IssueRepository $repoOTC */
  57.     private $repoIssue;
  58.     private $authenticationUtils;
  59.     private $kernel;
  60.     private $translator;
  61.     private $adminUrlGenerator;
  62.     private $messageBus;
  63.     /**
  64.      * @param EntityManager $em
  65.      */
  66.     public function __construct(
  67.         private EntityManagerInterface $em,
  68.         AuthenticationUtils $authenticationUtils,
  69.         KernelInterface $kernel,
  70.         TranslatorInterface $translator,
  71.         AdminUrlGenerator $adminUrlGenerator,
  72.         MessageBusInterface $bus
  73.     ) {
  74.         $this->authenticationUtils $authenticationUtils;
  75.         $this->repoJRNLog   $em->getRepository(JRNLog::class);
  76.         $this->repoVehicle  $em->getRepository(Vehicle::class);
  77.         $this->repoOTC      $em->getRepository(OTCData::class);
  78.         $this->repoIssue    $em->getRepository(Issue::class);
  79.         $this->repoJob      $em->getRepository(JobLog::class);
  80.         $this->adminUrlGenerator $adminUrlGenerator;
  81.         $this->kernel $kernel;
  82.         $this->translator $translator;
  83.         $this->messageBus $bus;
  84.     }
  85.     public function configureDashboard(): Dashboard
  86.     {
  87.         return Dashboard::new()
  88.             ->disableUrlSignatures();
  89.     }
  90.     public function configureCrud(): Crud
  91.     {
  92.         return Crud::new()
  93.             ->overrideTemplates([
  94.                 'layout' => 'base.html.twig',
  95.                 'crud/index' => 'index.html.twig',
  96.             ]);
  97.     }
  98.     public function configureAssets(): Assets
  99.     {
  100.         return Assets::new()
  101.             ->addWebpackEncoreEntry('app');
  102.     }
  103.     public function configureMenuItems(): iterable
  104.     {
  105.         if($this->isGranted("ROLE_USERS")){
  106.             yield MenuItem::linkToDashboard('Dashboard''fa fa-home')->setPermission("ROLE_USERS");
  107.             yield MenuItem::subMenu('issue-list''fa fa-exclamation')->setSubItems([
  108.                 MenuItem::linkToCrud('Alert''fa fa-warning'Issue::class)
  109.                     ->setAction('index')
  110.                     ->setController(AdminIssueController::class),                    
  111.                 MenuItem::linkToCrud('Info''fa fa-info'Issue::class)
  112.                     ->setController(AdminWarningController::class)                    
  113.             ]);
  114.             $flowSubMenu = [];
  115.             if($this->isGranted("ROLE_HOMOLOGATION") || $this->isGranted("ROLE_LOGISTIC_BUS")){
  116.                 $flowSubMenu[] = MenuItem::linkToRoute('import-export''fa fa-cloud-download''import_export');
  117.             }
  118.             $flowSubMenu[] = MenuItem::linkToCrud('Log''fa fa-file-text'JobLog::class)->setAction('index')
  119.                                 ->setPermission("ROLE_USERS");
  120.             if($this->isGranted("ROLE_MARKETING") || $this->isGranted("ROLE_LOGISTIC_BUS") || $this->isGranted("ROLE_LOGISTIC")){
  121.                 $flowSubMenu[] = MenuItem::linkToCrud('JRNLog''fa fa-file-text'JRNLog::class)->setAction('index');
  122.             }
  123.             $flowSubMenu[] =  MenuItem::linkToCrud('acvdifflog''fa fa-file-text'AAALog::class)->setAction('index')
  124.                                 ->setController(AdminACVDiffController::class)
  125.                                 ->setPermission("ROLE_SUPERADMIN");
  126.             $flowSubMenu[] =  MenuItem::linkToCrud('avinvarlog''fa fa-file-text'AAALog::class)->setAction('index')
  127.                                 ->setController(AdminAAALogController::class)
  128.                                 ->setPermission("ROLE_SUPERADMIN");
  129.             yield MenuItem::subMenu('flow''fa fa-tasks')->setSubItems($flowSubMenu);
  130.         }
  131.         if($this->isGranted("ROLE_MARKETING") || $this->isGranted("ROLE_HOMOLOGATION") || $this->isGranted("ROLE_LOGISTIC") || $this->isGranted("ROLE_LOGISTIC_BUS")){
  132.             $vehicleSubMenu = [];
  133.             if($this->isGranted("ROLE_MARKETING") || $this->isGranted("ROLE_HOMOLOGATION") || $this->isGranted("ROLE_LOGISTIC") ){
  134.                 $vehicleSubMenu[] = MenuItem::linkToCrud('Truck''fa fa-truck'Vehicle::class)
  135.                                         ->setController(AdminVehicleController::class)
  136.                                         ->setAction('index');
  137.             }
  138.             if($this->isGranted("ROLE_MARKETING") || $this->isGranted("ROLE_LOGISTIC_BUS")){
  139.                 $vehicleSubMenu[] = MenuItem::linkToCrud('Bus''fa fa-bus'Bus::class)
  140.                                         ->setAction('index');
  141.             }
  142.             yield MenuItem::subMenu('vehicles''fa fa-car')->setSubItems($vehicleSubMenu);
  143.         }
  144.       
  145.         if($this->isGranted("ROLE_MARKETING") || $this->isGranted("ROLE_HOMOLOGATION") || $this->isGranted("ROLE_LOGISTIC")){
  146.             yield MenuItem::linkToCrud('customers''fa fa-user'Client::class)
  147.                 ->setAction('index');
  148.         }
  149.         if($this->isGranted("ROLE_ADMIN")){
  150.             yield MenuItem::linkToCrud('financing-companies''fa fa-building'FinancingCompany::class)
  151.                 ->setAction('index')
  152.                 ->setPermission('ROLE_ADMIN');
  153.         }
  154.         
  155.         yield MenuItem::subMenu('admin''fa fa-key')->setSubItems([
  156.             MenuItem::linkToCrud('users''fa fa-user'User::class),
  157.             MenuItem::linkToCrud('printers''fa fa-print'Printer::class)
  158.         ])->setPermission("ROLE_ADMIN");
  159.         
  160.         if($this->isGranted("ROLE_MARKETING") || $this->isGranted("ROLE_HOMOLOGATION")){
  161.             yield MenuItem::subMenu('parametrization''fa fa-cog')->setSubItems([
  162.                 MenuItem::linkToCrud('Catalogue3en1''fa fa-cogs'Catalogue3en1::class)
  163.                     ->setAction('index')
  164.                     ->setPermission('ROLE_SUPERADMIN'),
  165.                 MenuItem::linkToCrud('Seats''fa fa-street-view'Seats::class)
  166.                     ->setAction('index')
  167.                     ->setPermission("ROLE_HOMOLOGATION"),
  168.                 MenuItem::linkToCrud('FDPGamma''fa fa-cogs'FDPGamma::class)
  169.                     ->setAction('index')
  170.                     ->setPermission("ROLE_MARKETING"),
  171.                 MenuItem::linkToCrud('CO2Criteria''fa fa-leaf'CO2Criteria::class)
  172.                     ->setAction('index')
  173.                     ->setPermission("ROLE_HOMOLOGATION"),
  174.             ]);
  175.         }
  176.         if($this->isGranted("ROLE_HOMOLOGATION")){
  177.             yield MenuItem::subMenu('homologation''fa fa-sitemap')->setSubItems([
  178.                 MenuItem::linkToCrud('otc''fa fa-cogs'OTCData::class)->setAction('index'),
  179.                 MenuItem::linkToCrud('coc''fa fa-cogs'COCData::class)->setAction('index'),
  180.             ]);
  181.         }
  182.     }
  183.     
  184.     public function configureUserMenu(UserInterface $user): UserMenu
  185.     {
  186.         $userMenuItems = [MenuItem::section(), MenuItem::linkToLogout('__ea__user.sign_out''fa-sign-out')];
  187.         $userMenuItems[] = MenuItem::linkToRoute('settings.label''settings''settings');
  188.         if ($this->isGranted(Permission::EA_EXIT_IMPERSONATION)) {
  189.             $userMenuItems[] = MenuItem::linkToExitImpersonation('__ea__user.exit_impersonation''fa-user-lock');
  190.         }
  191.         $userName '';
  192.         
  193.         if (method_exists($user'getUsername')) {
  194.             $userName $user->getUsername();
  195.         } elseif (method_exists($user'getUserIdentifier')) {
  196.             $userName $user->getUserIdentifier();
  197.         } elseif (method_exists($user'__toString')) {
  198.             $userName = (string) $user;
  199.         }
  200.         return UserMenu::new()
  201.             ->displayUserName()
  202.             ->displayUserAvatar()
  203.             ->setName($userName)
  204.             ->setAvatarUrl(null)
  205.             ->setMenuItems($userMenuItems);
  206.     }
  207.     /** @Route("/", name="homepage") */
  208.     public function homepage(): Response
  209.     {
  210.         return $this->redirectToRoute('easyadmin');
  211.     }
  212.     /** @Route("/admin", name="easyadmin") */
  213.     public function index(): Response
  214.     {
  215.         return $this->indexAction();
  216.     }
  217.     public function indexAction()
  218.     {
  219.         ini_set('max_execution_time''300');
  220.         $panels = [
  221.             $this->isGranted("ROLE_MARKETING") || $this->isGranted("ROLE_LOGISTIC_BUS")
  222.                 ? $this->createJRNPanel() : false,
  223.             $this->isGranted("ROLE_LOGISTIC")
  224.                 ? $this->createCDFSPanel() : false,
  225.             $this->isGranted("ROLE_HOMOLOGATION") || $this->isGranted("ROLE_MARKETING") || $this->isGranted("ROLE_LOGISTIC")
  226.                 ? $this->createSAPPanel() : false,
  227.             $this->isGranted("ROLE_HOMOLOGATION")
  228.                 ? $this->createOTCPanel() : false,
  229.             $this->isGranted("ROLE_HOMOLOGATION") || $this->isGranted("ROLE_LOGISTIC")
  230.                 ? $this->create3en1Panel() : false,
  231.             $this->isGranted("ROLE_SUPERADMIN")
  232.                 ? $this->createErrorsPanel() : false,
  233.             $this->isGranted("ROLE_HOMOLOGATION") || $this->isGranted("ROLE_SUPERADMIN")
  234.                 ? $this->createECOCPanel() : false,
  235.         ];
  236.         $panels $this->removeUnusedPanels($panels);
  237.         $panels $this->setConstantPanelRowCount($panels);
  238.         return $this->render('Default/index.html.twig', ["panels" => $panels]);
  239.     }
  240.     private function removeUnusedPanels($panels)
  241.     {
  242.         $panels array_filter($panels);
  243.         foreach ($panels as &$panel) {
  244.             $panel["values"] = array_filter($panel["values"]);
  245.             $panel["alerts"] = array_filter(isset($panel["alerts"]) ? $panel["alerts"] : []);
  246.         }
  247.         return $panels;
  248.     }
  249.     private static function setConstantPanelRowCount($panels)
  250.     {
  251.         if (!count($panels)) return [];
  252.         $maxLines max(array_map(function ($p) {
  253.             return count($p["values"]) + count($p["alerts"]);
  254.         }, $panels));
  255.         // Note: the line filler goes above the alert panels if these are present
  256.         foreach ($panels as &$panel)
  257.             $panel["values"] += array_fill(0$maxLines count($panel["alerts"]), []);
  258.         return $panels;
  259.     }
  260.     //region Top Level Panel Creators
  261.     private function createJRNPanel()
  262.     {
  263.         return [
  264.             "title" => [
  265.                 "raw" => "JRN",
  266.                 "link" => $this->adminUrlGenerator->setController(AdminJRNLogController::class)->generateUrl()
  267.             ],
  268.             "values" => [
  269.                 $this->getCountSinceLastUpdateForBrandSubPanel(JRNLog::IVECO"IVECO"),
  270.                 $this->getCountSinceLastUpdateForBrandSubPanel(JRNLog::IVECO_BUS"IVECO BUS"),
  271.                 $this->getCountSinceLastUpdateForBrandSubPanel(JRNLog::IRISBUS"IRIS BUS"),
  272.                 $this->getInfoLinkSubPanelIfOlderThan(IssueEvent::JRN$this->repoJob->findLastCreatedAtImport("jrn")),
  273.             ]
  274.         ];
  275.     }
  276.     private function createCDFSPanel()
  277.     {
  278.         $lastCreatedAtImport $this->repoJob->findLastCreatedAtImport("cdfs");
  279.         $formattedDate $this->formatDate($lastCreatedAtImport);
  280.         $runNumber $this->repoVehicle->findFirstRunNumberAfter($lastCreatedAtImport);
  281.         return [
  282.             "title" => ["raw" => "<span class=\"title-span\">CDFS:</span> {$formattedDate}{$runNumber}"],
  283.             "values" => [
  284.                 [
  285.                     "value" => $this->repoVehicle->countCDFSImportAfter($lastCreatedAtImport),
  286.                     "label" => "treated vehicles",
  287.                 ],
  288.                 $this->getInfoLinkSubPanelIfOlderThan(IssueEvent::CDFS$lastCreatedAtImport),
  289.             ],
  290.             "alerts" => [$this->getNewIssueAlert(IssueEvent::CDFS$lastCreatedAtImport)]
  291.         ];
  292.     }
  293.     private function createSAPPanel()
  294.     {
  295.         $lastCreateDateSAPImport $this->repoJob->findLastCreatedAtImport("sap");
  296.         $formattedDate $this->formatDate($lastCreateDateSAPImport);
  297.         return [
  298.             "title" => ["raw" => "<span class=\"title-span\">SAP:</span> {$formattedDate}"],
  299.             "values" => [
  300.                 [
  301.                     "value" => $this->repoVehicle->countSAPImportAfter($lastCreateDateSAPImport),
  302.                     "label" => "treated vehicles",
  303.                 ],
  304.                 $this->getInfoLinkSubPanelIfOlderThan(IssueEvent::SAP$lastCreateDateSAPImport),
  305.             ],
  306.             "alerts" => [
  307.                 $this->isGranted("ROLE_HOMOLOGATION") ? $this->getNewSapPersonAlert(IssueEvent::SAP_CLIENT"Alert! New client")  : false,
  308.                 $this->isGranted("ROLE_MARKETING")    ? $this->getNewSapPersonAlert(IssueEvent::SAP,        "Alert! New FDP")     : false,
  309.             ]
  310.         ];
  311.     }
  312.     private function createOTCPanel()
  313.     {
  314.         $lastCreateDateOTCImport $this->repoJob->findLastCreatedAtImport("otc");
  315.         $formattedDate $this->formatDate($lastCreateDateOTCImport);
  316.         $lastOTCNumReception $this->repoOTC->findLastNumReception();
  317.         return [
  318.             "title" => ["raw" => "<span class=\"title-span\">OTC:</span> {$formattedDate}{$lastOTCNumReception}"],
  319.             "values" => [
  320.                 [
  321.                     "value" => $this->repoVehicle->countOTCByNumReception($lastOTCNumReception),
  322.                     "label" => "concerned vehicles",
  323.                     "link" => $this->generateUrl_SearchByLastOTCNumber($lastOTCNumReception)
  324.                 ],
  325.                 $this->getInfoLinkSubPanelIfOlderThan(IssueEvent::OTC$lastCreateDateOTCImport),
  326.             ]
  327.         ];
  328.     }
  329.     private function create3en1Panel()
  330.     {
  331.         return [
  332.             "title" => ["raw" => "3en1"],
  333.             "values" => [[
  334.                 "value" => $this->repoVehicle->countPrintableGrand(true),
  335.                 "label" => "3en1 to print_KA",
  336.                 "link" => $this->generateUrl_SearchByPrintableGrand(true)
  337.             ], [
  338.                 "value" => $this->repoVehicle->countPrintableGrand(false),
  339.                 "label" => "3en1 to print_DEALERS",
  340.                 "link" => $this->generateUrl_SearchByPrintableGrand(false)
  341.             ]]
  342.         ];
  343.     }
  344.     private function createErrorsPanel()
  345.     {
  346.         return [
  347.             "title" => ["label" => "Errors AAA"],
  348.             "values" => [
  349.                 $this->getErrorSubPanelForError(IssueEvent::AAA_DEPOT"Errors in sending"),
  350.                 $this->getErrorSubPanelForError(IssueEvent::AAA_RETRAIT_REJE"Errors REJE"),
  351.                 $this->getErrorSubPanelForError(IssueEvent::AAA_RETRAIT_REJG"Errors REJG"),
  352.                 $this->getInfoLinkSubPanelIfOlderThan(IssueEvent::AAA, new \DateTime()),
  353.             ]
  354.         ];
  355.     }
  356.     private function createECOCPanel()
  357.     {
  358.         $job $this->repoJob->findByLastEcocImport();
  359.         $lastECOCImportJob = !$job "" $job->getCreatedAt();
  360.         $formattedDate $this->formatDate($lastECOCImportJob);
  361.         return [
  362.             "title" => ["raw" => "<span class=\"title-span\">eCOC:</span> {$formattedDate}"],
  363.             "values" => [
  364.                 [
  365.                     "value" => $this->repoVehicle->countECOCImportAfter($lastECOCImportJob),
  366.                     "label" => "treated vehicles",
  367.                 ],
  368.                 $this->getInfoLinkSubPanelIfOlderThan(IssueEvent::ECOC_IMPORT$lastECOCImportJob),
  369.             ],
  370.             "alerts" => [$this->getNewIssueAlert(IssueEvent::ECOC_IMPORT$lastECOCImportJob)]
  371.         ];
  372.     }
  373.     //endregion
  374.     //region Generate Search URLs
  375.     private function generateUrl_SearchByLastOTCNumber($lastOTCNumReception)
  376.     {
  377.         return $this->adminUrlGenerator
  378.                     ->setController(AdminVehicleController::class)
  379.                     ->setAction('index')
  380.                     ->set("filters[otc--numReception][value]"$lastOTCNumReception)
  381.                     ->set("filters[otc--numReception][comparison]""=");
  382.     }
  383.     private function generateUrl_SearchByPrintableGrand($isGrandCompte)
  384.     {
  385.         $adminUrlGenerator $this->container->get(AdminUrlGenerator::class);
  386.         return $adminUrlGenerator
  387.             ->setController(AdminVehicleController::class)
  388.             ->setAction('index')
  389.             ->set('filters[positioned]'"1")
  390.             ->set('filters[clientInvoice--isGrandCompte]'$isGrandCompte "1" "0")
  391.             ->set('filters[printableStatus][comparison]''=')
  392.             ->set('filters[printableStatus][value]''printable');
  393.     }
  394.     private function generateUrl_ShowWarningList($queryType)
  395.     {
  396.         $adminUrlGenerator $this->container->get(AdminUrlGenerator::class);
  397.         return $adminUrlGenerator
  398.                     ->setController(AdminWarningController::class)
  399.                     ->setAction('index')
  400.                     ->set('filters[type][value]'$queryType)
  401.                     ->set('filters[type][comparison]''=');
  402.     }
  403.     private function generateUrl_GenericSearchQuery($query)
  404.     {
  405.         $adminUrlGenerator $this->container->get(AdminUrlGenerator::class);
  406.         $adminUrlGenerator
  407.             ->setController(AdminIssueController::class)
  408.             ->setAction('index');
  409.         foreach($query as $key => $value){
  410.             $adminUrlGenerator
  411.                 ->set("filters[$key][comparison])","=")
  412.                 ->set("filters[$key][value])",$value);
  413.         }
  414.         return $adminUrlGenerator->generateUrl();
  415.     }
  416.     //endregion
  417.     //region Sub Panels Creators
  418.     private function getErrorSubPanelForError($type$label)
  419.     {
  420.         return ($value $this->repoIssue->countBy(["status" => Issue::STATUS_NEW"type" => $type"priority" => Issue::$PRIORITY_ERROR])) ? [
  421.             "value" => $value,
  422.             "label" => $label,
  423.             "alert" => true,
  424.             "link" => $this->generateUrl_GenericSearchQuery(["status" => Issue::STATUS_NEW"type" => $type"priority" => Issue::$PRIORITY_ERROR]),
  425.         ] : false;
  426.     }
  427.     private function getInfoLinkSubPanelIfOlderThan($type$createdAt)
  428.     {
  429.         return $this->repoIssue->countBy(["priority" => Issue::$PRIORITY_INFO"type" => $type"createdAt>=" => $createdAt]) ? [
  430.             "label" => "show.action",
  431.             "link" => $this->generateUrl_ShowWarningList($type),
  432.         ] : false;
  433.     }
  434.     private function getCountSinceLastUpdateForBrandSubPanel($type$label)
  435.     {
  436.         $lastImport $this->repoJRNLog->findLastRegistrationDateByBrand($type);
  437.         return [
  438.             "value" => $this->repoJRNLog->countByBrandFromDate($type$lastImport),
  439.             "label" => $label,
  440.             "date" => $lastImport
  441.         ];
  442.     }
  443.     private function getNewSapPersonAlert($personType$label)
  444.     {
  445.         return $this->repoIssue->countBy(["type" => $personType"status" => Issue::STATUS_NEW"priority" => Issue::$PRIORITY_ERROR]) ? [
  446.             "label" => $label,
  447.             "link" => $this->generateUrl_GenericSearchQuery(["type" => $personType]),
  448.             "alert" => true,
  449.         ] : false;
  450.     }
  451.     private function getNewIssueAlert($type$lastCreateDateImport)
  452.     {
  453.         return $this->repoIssue->countBy(["type" => $type"status" => Issue::STATUS_NEW"priority" => Issue::$PRIORITY_ERROR"createdAt>=" => $lastCreateDateImport]) ? [
  454.             "label" => "Alert!",
  455.             "link" => $this->generateUrl_GenericSearchQuery(["type" => $type"status" => Issue::STATUS_NEW])
  456.         ] : false;
  457.     }
  458.     //endregion
  459.     private function formatDate($date)
  460.     {
  461.         return $date $date->format("d/m/Y H:i:s") : '';
  462.     }
  463.     /** @Route("/testsecure", name="testsecure") */
  464.     public function testAction()
  465.     {
  466.         return new Response('
  467.             <<!DOCTYPE html>
  468.             <html>
  469.             <head>
  470.                 <title>IRIS</title>
  471.             </head>
  472.             <body>
  473.                 <h1>This resource is secured</h1>
  474.                 <p>You are: </p>' print_r($this->getUser(), true) . '
  475.             </body>
  476.             </html>
  477.             ');
  478.     }
  479.     /**
  480.      * @Route("/login", name="login")
  481.      */
  482.     public function loginAction(Request $request)
  483.     {
  484.         // KEEP LOGIN BACKDOOR
  485.         // if (($this->getParameter('kernel.environment') == 'qua' ||
  486.         //         $this->getParameter('kernel.environment') == 'prod' ||
  487.         //         $this->getUser() instanceof User) &&
  488.         //     strpos($request->getUri(), 'coolinternal.it') === false
  489.         // ) {
  490.         //     return $this->redirectToRoute('homepage');
  491.         // }
  492.         $error $this->authenticationUtils->getLastAuthenticationError();
  493.         $lastUsername $this->authenticationUtils->getLastUsername();
  494.         return $this->render('login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  495.     }
  496.     /**
  497.      * @Route("/logout", name="logout")
  498.      */
  499.     public function logoutAction()
  500.     {
  501.         return;
  502.     }
  503.     /**
  504.      * @Route("/settings", name="settings")
  505.      * @param Request $request
  506.      * @return Response
  507.      */
  508.     public function settingsAction(Request $request)
  509.     {
  510.         $user $this->getUser();
  511.         $form $this->createPrinterForm($user);
  512.         $form->handleRequest($request);
  513.         if ($form->isSubmitted() && $form->isValid()) {
  514.             $this->get('session')->getFlashBag()->set('success'$this->translator->trans('batch.success'));
  515.             $em $this->em;
  516.             $em->flush();
  517.         }
  518.         return $this->render('Default/settings.html.twig', [
  519.             'base_dir' => realpath($this->kernel->getProjectDir() . '/..'),
  520.             'form' => $form->createView()
  521.         ]);
  522.     }
  523.     private function createPrinterForm($user)
  524.     {
  525.         return $this->createFormBuilder($user)
  526.             ->add('printer'PrintersChoiceType::class, ['expanded' => true'label' => 'printer.label'])
  527.             ->add('send'SubmitType::class, ['label' => 'printer.save'])
  528.             ->getForm();
  529.     }
  530. }