diff --git a/TODO.md b/TODO.md index 7034423..a78e203 100644 --- a/TODO.md +++ b/TODO.md @@ -555,7 +555,7 @@ Goal: rename the tables and column to the canonical M2M pattern (`tags`, `thesis manually prepare `SELECT … FROM thesis_files WHERE thesis_id = ?` instead of calling `$db->getThesisFiles($thesisId)` which already exists. Replace with the DB method. -- [ ] **`admin/index.php` stats computed via PHP `array_filter` on full result set** — "total", +- [x] **`admin/index.php` stats computed via PHP `array_filter` on full result set** — "total", "publiés", "en attente" counts are derived by filtering the already-fetched `$theses` array in PHP. When a filter is active the stats reflect only filtered rows, which is misleading. Add `Database::getThesesStats(): array` returning three counts from SQL diff --git a/public/admin/index.php b/public/admin/index.php index e99cad0..6dc0806 100644 --- a/public/admin/index.php +++ b/public/admin/index.php @@ -22,6 +22,7 @@ try { if ($orientationFilter) $filters['orientation'] = $orientationFilter; $theses = $db->getThesesList($filters); + $stats = $db->getThesesStats(); $years = $db->getAllYears(); $orientations = $db->getAllOrientations(); } catch (Exception $e) { @@ -95,18 +96,18 @@ document.addEventListener('DOMContentLoaded', () => { - +
-
+
TFE total
-
$t['is_published'])) ?>
+
Publiés
-
!$t['is_published'])) ?>
+
En attente
diff --git a/src/Database.php b/src/Database.php index b44461f..2b6e734 100644 --- a/src/Database.php +++ b/src/Database.php @@ -540,6 +540,30 @@ class Database { return $stmt->fetchAll(PDO::FETCH_COLUMN); } + /** + * Return whole-database thesis counts, independent of any active filter. + * + * Always reflects the full theses table so the stats bar in admin/index.php + * shows accurate numbers even when a search or year filter is active. + * + * @return array{total: int, published: int, pending: int} + */ + public function getThesesStats(): array { + $stmt = $this->pdo->query( + "SELECT + COUNT(*) AS total, + SUM(CASE WHEN is_published = 1 THEN 1 ELSE 0 END) AS published, + SUM(CASE WHEN is_published = 0 THEN 1 ELSE 0 END) AS pending + FROM theses" + ); + $row = $stmt->fetch(); + return [ + 'total' => (int) $row['total'], + 'published' => (int) $row['published'], + 'pending' => (int) $row['pending'], + ]; + } + // ======================================================================== // CRUD METHODS (from formulaire) // ======================================================================== diff --git a/src/cache/rate_limit/ad921d60486366258809553a3db49a4a.json b/src/cache/rate_limit/ad921d60486366258809553a3db49a4a.json index a2b2955..f3b3c3f 100644 --- a/src/cache/rate_limit/ad921d60486366258809553a3db49a4a.json +++ b/src/cache/rate_limit/ad921d60486366258809553a3db49a4a.json @@ -1 +1 @@ -[1774615474] \ No newline at end of file +[1774694544] \ No newline at end of file diff --git a/storage/test.db b/storage/test.db index bf85056..7e572e0 100644 Binary files a/storage/test.db and b/storage/test.db differ