From 82ad817ad35b1f676fc4e60431856edfe81349cb Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Thu, 16 Apr 2026 01:35:08 +0200 Subject: [PATCH] asdasd --- modules/kea/pages/index.php | 11 ++++------- src/Repository/KeaHostRepository.php | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/modules/kea/pages/index.php b/modules/kea/pages/index.php index 10b20dc..ecd1166 100644 --- a/modules/kea/pages/index.php +++ b/modules/kea/pages/index.php @@ -36,14 +36,11 @@ try { } $repo = new KeaHostRepository($pdo, $metadataRepo); - $hosts = $repo->findAll(50); - $stats['total'] = count($hosts); + $hosts = $repo->findAll(200); + $stats['reservations'] = $repo->countReservations(); + $stats['leases'] = $repo->countLeases(); + $stats['total'] = $stats['reservations'] + $stats['leases']; foreach ($hosts as $host) { - if (($host['source'] ?? '') === 'lease') { - $stats['leases']++; - } else { - $stats['reservations']++; - } $group = trim((string)($host['metadata']['group_name'] ?? '')); if ($group !== '') { $stats['groups'][$group] = ($stats['groups'][$group] ?? 0) + 1; diff --git a/src/Repository/KeaHostRepository.php b/src/Repository/KeaHostRepository.php index cd2088b..f843059 100644 --- a/src/Repository/KeaHostRepository.php +++ b/src/Repository/KeaHostRepository.php @@ -74,6 +74,16 @@ final class KeaHostRepository )))); } + public function countReservations(): int + { + return $this->countTableRows('hosts'); + } + + public function countLeases(): int + { + return $this->countTableRows('lease4'); + } + private function findReservations(int $limit): array { if (!$this->tableExists('hosts')) { @@ -238,6 +248,16 @@ final class KeaHostRepository return in_array((string)$e->getCode(), ['42P01', '42S02'], true); } + private function countTableRows(string $table): int + { + if (!$this->tableExists($table)) { + return 0; + } + + $stmt = $this->pdo->query('SELECT COUNT(*) FROM ' . $table); + return (int)$stmt->fetchColumn(); + } + /** * Erstellt eine neue Host-Reservierung inkl. Metadaten. *