3 Commits

Author SHA1 Message Date
luptmoor
0f15e92d65 comment counter now refreshed for each deletion or addition of comment 2026-04-28 10:21:27 +02:00
luptmoor
942affd5e5 fix typo contribution_id 2026-04-28 10:08:49 +02:00
luptmoor
02ba53724e prepared comment counting 2026-04-28 10:04:51 +02:00
3 changed files with 25 additions and 0 deletions

View File

@@ -31,5 +31,6 @@ CREATE INDEX idx_comments_browser ON comments(browser_id);
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------
ALTER TABLE contributions ALTER TABLE contributions
ADD COLUMN photo_path VARCHAR(255) DEFAULT NULL; ADD COLUMN photo_path VARCHAR(255) DEFAULT NULL;
ADD COLUMN comment_count INTEGER NOT NULL DEFAULT 0;
COMMENT ON COLUMN contributions.photo_path IS 'Relative Path to uploaded Photo. NULL = no Photo.'; COMMENT ON COLUMN contributions.photo_path IS 'Relative Path to uploaded Photo. NULL = no Photo.';

View File

@@ -629,6 +629,14 @@ function handle_create_comment($input) {
':content' => $input['content'] ':content' => $input['content']
]); ]);
$stmt2 = $pdo->prepare("
UPDATE contributions
SET comment_count = comment_count + 1
WHERE contribution_id = :cid;
");
$stmt2->execute([':cid' => $input['contribution_id']]);
json_response([ json_response([
'message' => 'Comment created successfully.', 'message' => 'Comment created successfully.',
'comment_id' => (int) $pdo->lastInsertId() 'comment_id' => (int) $pdo->lastInsertId()
@@ -656,6 +664,14 @@ function handle_delete_comment($input) {
$stmt = $pdo->prepare("DELETE FROM comments WHERE comment_id = :id"); $stmt = $pdo->prepare("DELETE FROM comments WHERE comment_id = :id");
$stmt->execute([':id' => $input['comment_id']]); $stmt->execute([':id' => $input['comment_id']]);
$stmt2 = $pdo->prepare("
UPDATE contributions
SET comment_count = comment_count - 1
WHERE contribution_id = :cid;
");
$stmt2->execute([':cid' => $input['contribution_id']]);
json_response(['message' => 'Comment deleted successfully.']); json_response(['message' => 'Comment deleted successfully.']);
} catch (PDOException $e) { } catch (PDOException $e) {

View File

@@ -1105,6 +1105,14 @@ function loadComments(contributionId) {
}); });
listContainer.innerHTML = html; listContainer.innerHTML = html;
const count = response.comments.length;
const header = document.querySelector('#comments-toggle-' + contributionId)?.closest('.popup-comments-header');
if (header) {
header.innerHTML = '<i class="fa-solid fa-comments"></i> Kommentare (' + count + ')' +
' <i class="fa-solid fa-chevron-down popup-comments-toggle" id="comments-toggle-' + contributionId + '"></i>';
}
}); });
} }