This commit is contained in:
themohooks 2025-02-21 23:55:20 +03:00
parent 540e643e9a
commit f4cb133e46
2 changed files with 18 additions and 9 deletions

View file

@ -105,7 +105,9 @@ $(document).ready(function()
<?php <?php
$contest = DB::query('SELECT * FROM contests WHERE status=2')[0]; $contest = DB::query('SELECT * FROM contests WHERE status=2')[0];
$photos_contest = DB::query('SELECT * FROM photos WHERE on_contest=2 AND contest_id=:id', array(':id'=>$contest['id'])); $photos_contest = DB::query('SELECT * FROM photos WHERE on_contest=2 AND contest_id=:id', array(':id'=>$contest['id']));
foreach ($photos_contest as $pc) { foreach ($photos_contest as $pc) {
$user = new User($pc['user_id']);
$class = ''; $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']) { 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'; $class = ' voted';
@ -117,7 +119,7 @@ $(document).ready(function()
<td><a href="#" pid="'.$pc['id'].'" class="contestBtn'.$class.'"></a></td> <td><a href="#" pid="'.$pc['id'].'" class="contestBtn'.$class.'"></a></td>
<td class="pb_photo" id="p2068176"><a href="/photo/'.$pc['id'].'/" target="_blank" class="prw"><img class="f" src="/api/photo/compress?url='.$pc['photourl'].'" data-src="/api/photo/compress?url='.$pc['photourl'].'" alt="630 КБ"> <td class="pb_photo" id="p2068176"><a href="/photo/'.$pc['id'].'/" target="_blank" class="prw"><img class="f" src="/api/photo/compress?url='.$pc['photourl'].'" data-src="/api/photo/compress?url='.$pc['photourl'].'" alt="630 КБ">
<div class="hpshade"> <div class="hpshade">
<div class="eye-icon">'.DB::query('SELECT COUNT(*) FROM photos_views WHERE photo_id=:id', array(':id'=>$p['id']))[0]['COUNT(*)'].'</div> <div class="eye-icon">'.DB::query('SELECT COUNT(*) FROM photos_views WHERE photo_id=:id', array(':id'=>$pc['id']))[0]['COUNT(*)'].'</div>
</div> </div>
</a></td> </a></td>
<td class="pb_descr"> <td class="pb_descr">

View file

@ -38,7 +38,14 @@ WHERE p.on_contest = 1 AND p.contest_id = :id
GROUP BY p.id GROUP BY p.id
ORDER BY rates_count DESC; ORDER BY rates_count DESC;
', array(':id'=>$contest['id'])); ', array(':id'=>$contest['id']));
var_dump($photos_contest);
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) { foreach ($photos_contest as $pc) {
$user = new User($pc['user_id']); $user = new User($pc['user_id']);
if (VoteContest::photo(Auth::userid(), $pc['id'], $contest['id']) === 1) { if (VoteContest::photo(Auth::userid(), $pc['id'], $contest['id']) === 1) {