From 0c7d3d87c521f6a006d30bb697e7b7ff058e104a Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sat, 2 Sep 2023 23:17:09 +0200 Subject: [PATCH] make domains visible --- src/Controller/DomainsController.php | 67 ++++++++++++++++++++++++++++ src/Repository/DomainsRepository.php | 9 ++++ templates/base.html.twig | 8 ++++ templates/domains/index.html.twig | 50 +++++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 src/Controller/DomainsController.php create mode 100644 templates/domains/index.html.twig diff --git a/src/Controller/DomainsController.php b/src/Controller/DomainsController.php new file mode 100644 index 0000000..8946c8b --- /dev/null +++ b/src/Controller/DomainsController.php @@ -0,0 +1,67 @@ +em = $em; + $this->router = $router; + $this->translator = $translator; + } + + #[Route('/domains', name: 'app_domains')] + public function index(): Response + { + $this->denyAccessUnlessGranted('ROLE_ADMIN'); + + $pages=array("page"=>1,"next" => false,"prev" => false); + + if(isset($_GET["page"]) && $_GET["page"] > 0) + { + $pages["page"] = intval($_GET["page"]); + } else { + $pages["page"] = 1; + } + + if(isset($_GET["perpage"]) && $_GET["perpage"] > 0) + { + $pages["perpage"] = intval($_GET["perpage"]); + } else { + $pages["perpage"] = 17; + } + + $repository = $this->em->getRepository(Domains::class); + $domains = $repository->findAll(array(),array('fqdn' => 'DESC'),$pages["perpage"], ($pages["page"]-1)*$pages["perpage"]); + $totaldomains = $repository->getTotalRows(); + + if(count($domains) == 0 && $totaldomains != 0 ) { return $this->redirectToRoute('app_domains'); } + + if($totaldomains/$pages["perpage"] > $pages["page"]) { $pages["next"] = true; } + if($pages["page"]-1 > 0) { $pages["prev"] = true; } + + return $this->render('domains/index.html.twig', [ + 'domains' => $domains, + 'pages' => $pages, + 'menuactive' => 'domains', + 'breadcrumbs' => array('0' => array('name' => $this->translator->trans("Domains"), 'url' => $this->router->generate('app_domains'))), + ]); + } +} diff --git a/src/Repository/DomainsRepository.php b/src/Repository/DomainsRepository.php index d0e6098..9dc15bd 100644 --- a/src/Repository/DomainsRepository.php +++ b/src/Repository/DomainsRepository.php @@ -55,4 +55,13 @@ public function findSelectedRoles($user_id): array ->getResult() ; } + + public function getTotalRows(): int + { + return $this->createQueryBuilder('d') + ->select('count(d.id)') + ->getQuery() + ->getOneOrNullResult()[1] + ; + } } diff --git a/templates/base.html.twig b/templates/base.html.twig index ed76c85..ef538e8 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -67,6 +67,14 @@ Logs +