src/Controller/DefaultController.php line 543

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