From f4cb133e467db53e223f254ed71fa5c57b566e93 Mon Sep 17 00:00:00 2001
From: themohooks <81331307+themohooks@users.noreply.github.com>
Date: Fri, 21 Feb 2025 23:55:20 +0300
Subject: [PATCH] fixes
---
views/pages/Contests/VotingIndex.php | 4 +++-
views/pages/Contests/VotingWaiting.php | 23 +++++++++++++++--------
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/views/pages/Contests/VotingIndex.php b/views/pages/Contests/VotingIndex.php
index 0cc152c..e43ae94 100644
--- a/views/pages/Contests/VotingIndex.php
+++ b/views/pages/Contests/VotingIndex.php
@@ -105,7 +105,9 @@ $(document).ready(function()
$contest['id']));
+
foreach ($photos_contest as $pc) {
+ $user = new User($pc['user_id']);
$class = '';
if ((int)DB::query('SELECT photo_id FROM contests_rates WHERE photo_id=:pid AND user_id=:uid AND contest_id=:cid', array(':uid' => Auth::userid(), ':pid' => $pc['id'], ':cid' => $contest['id']))[0]['photo_id'] === (int)$pc['id']) {
$class = ' voted';
@@ -117,7 +119,7 @@ $(document).ready(function()
|
- '.DB::query('SELECT COUNT(*) FROM photos_views WHERE photo_id=:id', array(':id'=>$p['id']))[0]['COUNT(*)'].'
+ '.DB::query('SELECT COUNT(*) FROM photos_views WHERE photo_id=:id', array(':id'=>$pc['id']))[0]['COUNT(*)'].'
|
diff --git a/views/pages/Contests/VotingWaiting.php b/views/pages/Contests/VotingWaiting.php
index 76ef056..fab917c 100644
--- a/views/pages/Contests/VotingWaiting.php
+++ b/views/pages/Contests/VotingWaiting.php
@@ -31,14 +31,21 @@ use \App\Models\{User, VoteContest, Vote};
$contest['id']));
-var_dump($photos_contest);
+ $photos_contest = DB::query('SELECT p.*, COUNT(prc.photo_id) AS rates_count
+ FROM photos p
+ LEFT JOIN photos_rates_contest prc ON p.id = prc.photo_id
+ WHERE p.on_contest = 1 AND p.contest_id = :id
+ GROUP BY p.id
+ ORDER BY rates_count DESC;
+ ', array(':id'=>$contest['id']));
+
+ foreach ($photos_contest as &$photo) {
+ $photo['votes'] = VoteContest::count($pc['id'], $contest['id']);
+ }
+
+ usort($photos_contest, function ($a, $b) {
+ return $b['votes'] <=> $a['votes'];
+ });
foreach ($photos_contest as $pc) {
$user = new User($pc['user_id']);
if (VoteContest::photo(Auth::userid(), $pc['id'], $contest['id']) === 1) {
|