From ecba4a77a76aa8dafec78b0336bf0d382be66394 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Tue, 22 Apr 2025 14:37:55 +0500 Subject: feat: show favorite reaction + count them as contributions --- public/users.php | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) (limited to 'public/users.php') diff --git a/public/users.php b/public/users.php index fdcbacf..06aa459 100644 --- a/public/users.php +++ b/public/users.php @@ -189,13 +189,25 @@ $actions = []; // calculating contributions $stmt = $db->prepare("SELECT COUNT(*) FROM emotes WHERE uploaded_by = ?"); $stmt->execute([$user->id()]); -$contributions = $stmt->fetch()[0]; +$contributions = intval($stmt->fetch()[0]); + +$stmt = $db->prepare("SELECT COUNT(*) FROM ratings WHERE user_id = ?"); +$stmt->execute([$user->id()]); + +$contributions += intval($stmt->fetch()[0]); // getting status $status = 1; // getting favorite reaction -$fav_reaction = 1; +$fav_reaction = null; + +$stmt = $db->prepare("SELECT rate, COUNT(*) AS c FROM ratings WHERE user_id = ? GROUP BY rate ORDER BY c DESC LIMIT 1"); +$stmt->execute([$user->id()]); + +if ($row = $stmt->fetch()) { + $fav_reaction = $row; +} // getting favorite emote $fav_emote = 1; @@ -285,21 +297,21 @@ if ($is_json) { ?> - Contributed emotes + Contributions - - Favorite reaction - - '; - } else { - echo 'Coal '; - } - ?> - - + + + Favorite reaction + + '; + ?> + + prepare("SELECT code, ext FROM emotes WHERE id = ?"); $stmt->execute([$fav_emote]); @@ -370,7 +382,7 @@ if ($is_json) { '; + echo ''; echo '' . $emote_row['; echo '

' . $emote_row["code"] . '

'; echo '
'; @@ -395,7 +407,7 @@ if ($is_json) {
'; + echo ''; echo '' . $emote_row['; echo '

' . $emote_row["code"] . '

'; echo '
'; -- cgit v1.2.3