From 950ac25828de0d7cff25ef3f63c9e9ca93fce471 Mon Sep 17 00:00:00 2001 From: patrickzerhusen Date: Tue, 28 Apr 2026 15:50:58 +0200 Subject: [PATCH] fixed comment count bug in moderation portal --- migrations/007_comment_moderation.sql | 2 +- public/admin.php | 210 ++++++++++++++++++++------ public/api/contributions.php | 52 ++++++- public/js/app.js | 9 +- 4 files changed, 226 insertions(+), 47 deletions(-) diff --git a/migrations/007_comment_moderation.sql b/migrations/007_comment_moderation.sql index 78356a1..97af7d4 100644 --- a/migrations/007_comment_moderation.sql +++ b/migrations/007_comment_moderation.sql @@ -10,5 +10,5 @@ ALTER TABLE comments -- Index for fast Status Filtering CREATE INDEX idx_comments_status ON comments(status); --- Sets all existing Comments to 'approved' (retroactive) +-- Approves existing Comments UPDATE comments SET status = 'approved'; \ No newline at end of file diff --git a/public/admin.php b/public/admin.php index 728d780..8c5e615 100644 --- a/public/admin.php +++ b/public/admin.php @@ -69,18 +69,28 @@ $stmt->execute([':mid' => $municipality['municipality_id']]); $news_items = $stmt->fetchAll(); -// Loads Comments with Contribution for Moderation +// Loads all Comments with Contribution Titles for Moderation $stmt = $pdo->prepare(" - SELECT contribution_id, title, category, description, author_name, - geom_type, status, likes_count, dislikes_count, comment_count, - photo_path, created_at, updated_at - FROM contributions - WHERE municipality_id = :mid - ORDER BY created_at DESC + SELECT cm.comment_id, cm.contribution_id, cm.author_name, cm.browser_id, + cm.content, cm.status, cm.created_at, + co.title AS contribution_title, co.category AS contribution_category + FROM comments cm + JOIN contributions co ON cm.contribution_id = co.contribution_id + WHERE co.municipality_id = :mid + ORDER BY cm.created_at DESC "); $stmt->execute([':mid' => $municipality['municipality_id']]); $all_comments = $stmt->fetchAll(); +// Counts Comments per Status +$comment_counts = ['pending' => 0, 'approved' => 0, 'rejected' => 0]; +foreach ($all_comments as $c) { + if (isset($comment_counts[$c['status']])) { + $comment_counts[$c['status']]++; + } +} +$comment_counts['total'] = count($all_comments); + // Shows Login Page if not authenticated if ($page === 'login' || !is_admin()) { @@ -100,7 +110,7 @@ $categories = get_categories(); // Loads all Contributions for Municipality $stmt = $pdo->prepare(" SELECT contribution_id, title, category, description, author_name, photo_path, - geom_type, status, likes_count, dislikes_count, created_at, updated_at + geom_type, status, likes_count, dislikes_count, comment_count, created_at, updated_at FROM contributions WHERE municipality_id = :mid ORDER BY created_at DESC @@ -194,27 +204,6 @@ $counts['total'] = count($all_contributions);
- -
-
-
-
Alle
-
-
-
-
Ausstehend
-
-
-
-
Akzeptiert
-
-
-
-
Abgelehnt
-
- -
-
@@ -363,14 +352,33 @@ $counts['total'] = count($all_contributions);
+ + +