From 399939e62ea72b1ac4dc656c9c8fbc62899ac6c0 Mon Sep 17 00:00:00 2001 From: themohooks <81331307+themohooks@users.noreply.github.com> Date: Sat, 6 Jul 2024 08:58:54 +0300 Subject: [PATCH] fix rating --- app/Controllers/Api/Images/Rate.php | 19 +++++++++++++++---- app/Models/Vote.php | 1 - views/pages/Photo.php | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/Controllers/Api/Images/Rate.php b/app/Controllers/Api/Images/Rate.php index cce28c5..377fbd8 100644 --- a/app/Controllers/Api/Images/Rate.php +++ b/app/Controllers/Api/Images/Rate.php @@ -32,9 +32,9 @@ class Rate foreach ($votes as $vote) { $user = new User($vote['user_id']); if ($vote['type'] === 0) { - $type = -1; + $type = 0; $formattedVotesNeg[] = [$vote['user_id'], $user->i('username'), $type]; - } else { + } else if ($vote['type'] === 1) { $type = 1; $formattedVotesPos[] = [$vote['user_id'], $user->i('username'), $type]; } @@ -44,16 +44,27 @@ class Rate if (Vote::photo(Auth::userid(), $_GET['pid']) === 0) { $negbtn = true; $posbtn = false; - } else { + } else if (Vote::photo(Auth::userid(), $_GET['pid']) === 1) { $negbtn = false; $posbtn = true; + } else { + $negbtn = false; + $posbtn = false; } $result = [ - 'votes' => [$formattedVotesNeg, $formattedVotesPos], 'buttons' => [$negbtn, $posbtn], 'errors' => '', 'rating' => Vote::count($_GET['pid']) ]; + $votes = []; + $votes[1] = $formattedVotesPos; + $votes[0] = $formattedVotesNeg; + + if (!empty($votes)) { + $result['votes'] = $votes; + } + + header('Content-Type: application/json'); echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); diff --git a/app/Models/Vote.php b/app/Models/Vote.php index e2a14dc..f132a7a 100644 --- a/app/Models/Vote.php +++ b/app/Models/Vote.php @@ -10,7 +10,6 @@ class Vote $result = DB::query('SELECT type FROM photos_rates WHERE user_id=:uid AND photo_id=:pid', array(':uid' => $user_id, ':pid' => $pid)); if (!empty($result)) { $type = $result[0]['type']; - if ($type < 0) { $type = -1; } diff --git a/views/pages/Photo.php b/views/pages/Photo.php index cec12d0..2f9e755 100644 --- a/views/pages/Photo.php +++ b/views/pages/Photo.php @@ -21,7 +21,7 @@ $photouser = new \App\Models\User($photo->i('user_id'));