Benjamin Harris 2 miesięcy temu
rodzic
commit
c1a4b0602f
1 zmienionych plików z 36 dodań i 1 usunięć
  1. 36 1
      web/index.php

+ 36 - 1
web/index.php

@@ -252,6 +252,15 @@ $sql .= " ORDER BY {$order}";
 $st = $pdo->prepare($sql);
 $st->execute($params);
 $rows = $st->fetchAll();
+
+// Build type breakdown from results (no extra query)
+$typeCount = [];
+foreach ($rows as $r) {
+    $t = trim((string)($r['application_type'] ?? ''));
+    if ($t !== '') $typeCount[$t] = ($typeCount[$t] ?? 0) + 1;
+}
+arsort($typeCount);
+$classifiedCount = array_sum($typeCount);
 ?>
 <!doctype html>
 <html lang="en">
@@ -322,7 +331,33 @@ $rows = $st->fetchAll();
                     <button type="submit" class="btn btn-primary">Apply</button>
                 </div>
             </form>
-            <div class="muted mt-2"><?= count($rows) ?> item(s)</div>
+            <div class="muted mt-2"><?= count($rows) ?> item(s)<?php if ($classifiedCount > 0): ?>, <?= $classifiedCount ?> classified<?php endif; ?></div>
+            <?php if (!empty($typeCount)): ?>
+            <div class="mt-2 d-flex flex-wrap gap-1 align-items-center">
+                <?php
+                // Build URL preserving current filters but swapping app_type
+                $baseParams = array_filter([
+                    'q'             => $q,
+                    'council_key'   => $councilKeySel,
+                    'sort'          => $sort !== 'close' ? $sort : null,
+                    'dir'           => $dir !== 'DESC' ? strtolower($dir) : null,
+                    'include_closed'=> $includeClosed ? '1' : null,
+                ]);
+                ?>
+                <?php if ($appTypeSel !== ''): ?>
+                <a class="btn btn-sm btn-outline-secondary" href="?<?= h(http_build_query($baseParams)) ?>">All types</a>
+                <?php endif; ?>
+                <?php foreach ($typeCount as $type => $n):
+                    $linkParams = $baseParams + ['app_type' => $type];
+                    $active = ($appTypeSel === $type);
+                ?>
+                <a class="btn btn-sm <?= $active ? 'btn-primary' : 'btn-outline-primary' ?>"
+                   href="?<?= h(http_build_query($linkParams)) ?>">
+                   <?= h($type) ?> <span class="badge <?= $active ? 'text-bg-light' : 'text-bg-primary' ?>"><?= $n ?></span>
+                </a>
+                <?php endforeach; ?>
+            </div>
+            <?php endif; ?>
         </header>
 
         <div class="container">