Add search, filters and pages to the central registry
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
821c799225
commit
7cdb431fd4
7 files changed
+158
-18
No files matched your search
@@ -10,6 +10,9 @@ namespace Zentrale;
|
||||
*/
|
||||
final class Anwendung
|
||||
{
|
||||
/** Zeilen je Seite in der Übersicht. */
|
||||
private const PRO_SEITE = 25;
|
||||
|
||||
private \PDO $db;
|
||||
|
||||
/** @param array<string, mixed> $config */
|
||||
@@ -113,17 +116,56 @@ final class Anwendung
|
||||
{
|
||||
$neueste = $fassungen->neueste();
|
||||
$alle = $bestand->alle($neueste['version'] ?? null);
|
||||
|
||||
// Die Zähler oben sind zugleich die Filter; sie zählen immer den ganzen Bestand.
|
||||
$filter = [
|
||||
'aktuell' => static fn (array $i): bool => null !== $neueste && !$i['veraltet'] && 'unbekannt' !== $i['fassung'],
|
||||
'veraltet' => static fn (array $i): bool => $i['veraltet'],
|
||||
'still' => static fn (array $i): bool => $i['still'],
|
||||
'unbekannt' => static fn (array $i): bool => $i['unbekannt'],
|
||||
];
|
||||
$zahlen = ['alle' => count($alle)];
|
||||
foreach ($filter as $name => $passt) {
|
||||
$zahlen[$name] = count(array_filter($alle, $passt));
|
||||
}
|
||||
if (null === $neueste) {
|
||||
$zahlen['aktuell'] = null;
|
||||
}
|
||||
|
||||
$suche = mb_substr(trim((string) ($_GET['q'] ?? '')), 0, 100);
|
||||
$gewaehlt = is_string($_GET['filter'] ?? null) && isset($filter[$_GET['filter']]) ? $_GET['filter'] : null;
|
||||
$treffer = array_values(array_filter($alle, static function (array $i) use ($suche, $gewaehlt, $filter): bool {
|
||||
if (null !== $gewaehlt && !$filter[$gewaehlt]($i)) {
|
||||
return false;
|
||||
}
|
||||
if ('' === $suche) {
|
||||
return true;
|
||||
}
|
||||
foreach (['domain', 'domain_vorher', 'adresse', 'notiz', 'fassung', 'ip'] as $feld) {
|
||||
if (null !== $i[$feld] && false !== mb_stripos((string) $i[$feld], $suche)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}));
|
||||
|
||||
$proSeite = self::PRO_SEITE;
|
||||
$seiten = max(1, (int) ceil(count($treffer) / $proSeite));
|
||||
$seite = min($seiten, max(1, (int) ($_GET['seite'] ?? 1)));
|
||||
|
||||
$this->zeigen('uebersicht', [
|
||||
'titel' => 'Installationen',
|
||||
'neueste' => $neueste,
|
||||
'installationen' => $alle,
|
||||
'zahlen' => [
|
||||
'alle' => count($alle),
|
||||
'aktuell' => null === $neueste ? null : count(array_filter($alle, static fn (array $i): bool => !$i['veraltet'] && 'unbekannt' !== $i['fassung'])),
|
||||
'veraltet' => count(array_filter($alle, static fn (array $i): bool => $i['veraltet'])),
|
||||
'still' => count(array_filter($alle, static fn (array $i): bool => $i['still'])),
|
||||
'unbekannt' => count(array_filter($alle, static fn (array $i): bool => $i['unbekannt'])),
|
||||
],
|
||||
'installationen' => array_slice($treffer, ($seite - 1) * $proSeite, $proSeite),
|
||||
'treffer' => count($treffer),
|
||||
'suche' => $suche,
|
||||
'filter' => $gewaehlt,
|
||||
'seite' => $seite,
|
||||
'seiten' => $seiten,
|
||||
'von' => [] === $treffer ? 0 : ($seite - 1) * $proSeite + 1,
|
||||
'bis' => min(count($treffer), $seite * $proSeite),
|
||||
'zahlen' => $zahlen,
|
||||
// Verstummte bleiben außen vor: Sie holen den Auftrag womöglich nie ab. Wartende haben schon einen.
|
||||
'aktualisierbar' => array_values(array_filter($alle, static fn (array $i): bool => $i['kann_update'] && !$i['still'] && 'wartet' !== ($i['auftrag_zustand']['art'] ?? null))),
|
||||
]);
|
||||
|
||||
Reference in new issue
Block a user