From 74e70351235e5da28f2439f2334b517fb91a6c2d Mon Sep 17 00:00:00 2001 From: ghost Date: Tue, 12 Sep 2023 20:07:11 +0300 Subject: [PATCH] fix stars counter --- src/library/database.php | 8 +++++--- src/public/index.php | 2 +- src/public/magnet.php | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/library/database.php b/src/library/database.php index c34e404..d09eec1 100644 --- a/src/library/database.php +++ b/src/library/database.php @@ -1382,13 +1382,15 @@ class Database { return $query->fetch()->result; } - public function findMagnetStarsTotalByMagnetId(int $magnetId) : int { + public function findMagnetStarsTotalByMagnetId(int $magnetId, bool $value) : int { $this->_debug->query->select->total++; - $query = $this->_db->prepare('SELECT COUNT(DISTINCT `userId`) AS `result` FROM `magnetStar` WHERE `magnetId` = ?'); + $total = 0; - $query->execute([$magnetId]); + $query = $this->_db->prepare('SELECT COUNT(DISTINCT `userId`) AS `result` FROM `magnetStar` WHERE `magnetId` = ? AND `value` = ?'); + + $query->execute([$magnetId, (int) $value]); return $query->fetch()->result; } diff --git a/src/public/index.php b/src/public/index.php index 6b34508..dedde48 100644 --- a/src/public/index.php +++ b/src/public/index.php @@ -143,7 +143,7 @@ else ], 'star' => (object) [ - 'total' => $db->findMagnetStarsTotalByMagnetId($magnet->magnetId), + 'total' => $db->findMagnetStarsTotalByMagnetId($magnet->magnetId, true), 'status' => $db->findLastMagnetStarValue($magnet->magnetId, $userId), ], 'access' => (object) diff --git a/src/public/magnet.php b/src/public/magnet.php index 45e0968..723a0e3 100644 --- a/src/public/magnet.php +++ b/src/public/magnet.php @@ -131,7 +131,7 @@ else ], 'star' => (object) [ - 'total' => $db->findMagnetStarsTotalByMagnetId($magnet->magnetId), + 'total' => $db->findMagnetStarsTotalByMagnetId($magnet->magnetId, true), 'status' => $db->findLastMagnetStarValue($magnet->magnetId, $userId), ], 'access' => (object)