Skip to content

Commit

Permalink
make domains visible
Browse files Browse the repository at this point in the history
  • Loading branch information
antedebaas committed Sep 2, 2023
1 parent d7b3c2f commit 0c7d3d8
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/Controller/DomainsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

use App\Entity\Domains;

use App\Repository\DomainsRepository;

class DomainsController extends AbstractController
{
private $em;
private $router;
private $translator;

public function __construct(EntityManagerInterface $em, UrlGeneratorInterface $router, TranslatorInterface $translator)
{
$this->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'))),
]);
}
}
9 changes: 9 additions & 0 deletions src/Repository/DomainsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
;
}
}
8 changes: 8 additions & 0 deletions templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
<span class="ms-2">Logs</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link{% if menuactive == "domains" %} active{% endif %}" href="{{ path('app_domains') }}">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" d="M16.5 12a4.5 4.5 0 11-9 0 4.5 4.5 0 019 0zm0 0c0 1.657 1.007 3 2.25 3S21 13.657 21 12a9 9 0 10-2.636 6.364M16.5 12V8.25" />
</svg>
<span class="ms-2">Domains</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link{% if menuactive == "users" %} active{% endif %}" href="{{ path('app_users') }}">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
Expand Down
50 changes: 50 additions & 0 deletions templates/domains/index.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{% extends 'base.html.twig' %}

{% block title %}Domains{% endblock %}

{% block body %}
<div class="row">
<div class="col-12 col-xl-12 mb-4 mb-lg-0">
<div class="card">
<h5 class="card-header">Domains</h5>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">Id</th>
<th scope="col">Domain FQDN</th>
<th scope="col">Total reports</th>
</tr>
</thead>
<tbody>
{% for domain in domains %}
<tr>
<th scope="row">{{ domain.id }}</th>
<td>{{ domain.fqdn }}</td>
<td>{{ domain.reports|length }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="clearfix">
<span class="float-start">&nbsp;</span>
<span class="float-end">
{% if pages.prev %}
<a href="{{ path('app_logs', {page: pages.page - 1, perpage: pages.perpage }) }}" class="btn btn-sm btn-secondary">&lt;</a>
{% else %}
<a href="#" class="btn btn-sm btn-light" disabled>&lt;</a>
{% endif %}
{% if pages.next %}
<a href="{{ path('app_logs', {page: pages.page + 1, perpage: pages.perpage }) }}" class="btn btn-sm btn-secondary">&gt;</a>
{% else %}
<a href="#" class="btn btn-sm btn-light" disabled>&gt;</a>
{% endif %}
</span>
</div>

</div>
</div>
</div>
{% endblock %}

0 comments on commit 0c7d3d8

Please sign in to comment.