asdasd
This commit is contained in:
@@ -36,14 +36,11 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$repo = new KeaHostRepository($pdo, $metadataRepo);
|
$repo = new KeaHostRepository($pdo, $metadataRepo);
|
||||||
$hosts = $repo->findAll(50);
|
$hosts = $repo->findAll(200);
|
||||||
$stats['total'] = count($hosts);
|
$stats['reservations'] = $repo->countReservations();
|
||||||
|
$stats['leases'] = $repo->countLeases();
|
||||||
|
$stats['total'] = $stats['reservations'] + $stats['leases'];
|
||||||
foreach ($hosts as $host) {
|
foreach ($hosts as $host) {
|
||||||
if (($host['source'] ?? '') === 'lease') {
|
|
||||||
$stats['leases']++;
|
|
||||||
} else {
|
|
||||||
$stats['reservations']++;
|
|
||||||
}
|
|
||||||
$group = trim((string)($host['metadata']['group_name'] ?? ''));
|
$group = trim((string)($host['metadata']['group_name'] ?? ''));
|
||||||
if ($group !== '') {
|
if ($group !== '') {
|
||||||
$stats['groups'][$group] = ($stats['groups'][$group] ?? 0) + 1;
|
$stats['groups'][$group] = ($stats['groups'][$group] ?? 0) + 1;
|
||||||
|
|||||||
@@ -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
|
private function findReservations(int $limit): array
|
||||||
{
|
{
|
||||||
if (!$this->tableExists('hosts')) {
|
if (!$this->tableExists('hosts')) {
|
||||||
@@ -238,6 +248,16 @@ final class KeaHostRepository
|
|||||||
return in_array((string)$e->getCode(), ['42P01', '42S02'], true);
|
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.
|
* Erstellt eine neue Host-Reservierung inkl. Metadaten.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user