contests to photos

This commit is contained in:
themohooks 2025-02-15 04:54:34 +03:00
parent 13f06db887
commit be85a9531a
4 changed files with 107 additions and 6 deletions

View file

@ -38,6 +38,7 @@ class Routes
Router::get('/article/$id', 'MainController@gallery');
Router::get('/voting', 'ContestsController@index');
Router::get('/voting/results', 'ContestsController@results');
Router::get('/voting/waiting', 'ContestsController@waiting');
Router::get('/comments', 'MainController@comments');
if (Auth::userid() > 0) {
$user = new \App\Models\User(Auth::userid());
@ -52,6 +53,7 @@ class Routes
Router::get('/search', 'SearchController@i');
Router::get('/fav', 'MainController@fav');
Router::get('/voting/sendpretend', 'ContestsController@sendpretend');
Router::get('/vehicle/edit', 'VehicleController@iedit');
Router::get('/vehicle/dbedit', 'VehicleController@dbedit');
@ -77,6 +79,8 @@ class Routes
Router::any('/api/admin/getvehicleinputs/$id', 'ApiController@admingetvehicleinputs');
Router::any('/api/admin/geodb/create', 'ApiController@admingeodbcreate');
Router::any('/api/admin/geodb/load', 'ApiController@admingeodbload');
Router::any('/api/admin/contests/createtheme', 'ApiController@admincontestscreatetheme');
Router::any('/api/admin/contests/create', 'ApiController@admincontestscreate');
}
Router::get('/logout', 'MainController@logout');
Router::get('/404', 'ExceptionRegister@notfound');

View file

@ -7,7 +7,23 @@ class Vote
{
public static function photo($user_id, $pid)
{
$result = DB::query('SELECT type FROM photos_rates WHERE user_id=:uid AND photo_id=:pid', array(':uid' => $user_id, ':pid' => $pid));
$result = DB::query('SELECT type FROM photos_rates WHERE user_id=:uid AND photo_id=:pid AND contest=0', array(':uid' => $user_id, ':pid' => $pid));
if (!empty($result)) {
$type = $result[0]['type'];
if ($type < 0) {
$type = -1;
}
return $type;
} else {
return -1;
}
}
public static function photoContest($user_id, $pid)
{
$result = DB::query('SELECT type FROM photos_rates WHERE user_id=:uid AND photo_id=:pid AND contest=1', array(':uid' => $user_id, ':pid' => $pid));
if (!empty($result)) {
$type = $result[0]['type'];
if ($type < 0) {

View file

@ -122,6 +122,78 @@ LIMIT 10;');
}
?>
</div>
<style>
#contestNotify {
background-size: 550px 211.2px;
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 550 211.2" width="550" height="211.2" style="opacity: 0.3; filter: grayscale(0);"><text x="0em" y="1em" font-size="88" transform="rotate(17 55 52.8)">🎁</text><text x="1.25em" y="2em" font-size="88" transform="rotate(17 165 140.8)">🎈</text><text x="2.5em" y="1em" font-size="88" transform="rotate(17 275 52.8)">🎀</text><text x="3.75em" y="2em" font-size="88" transform="rotate(17 385 140.8)">🎊</text><text x="5em" y="1em" font-size="88" transform="rotate(17 495 52.8)">🎉</text></svg>');
}
</style>
<?php
if (DB::query('SELECT status FROM contests WHERE status=2')[0]['status'] === 2) {
$contest = DB::query('SELECT * FROM contests WHERE status=2')[0];
$theme = DB::query('SELECT * FROM contests_themes WHERE id=:id', array(':id'=>$contest['themeid']))[0];
echo ' <div id="contestNotify" style="float:left; border:solid 1px #171022; padding:6px 10px 7px; margin-bottom:13px; background-color:#E5D6FF"><h4>Фотоконкурс!</h4>
Закончится через: <b id="countdown"></b><br>
Тематика: <b>'.$theme['title'].'</b><br>
<b style="color: #412378;">Голосуйте за лучшие фотографии, которые должны стать победителями сегодняшнего конкурса!</b><br><br>
<a href="/voting" style="background-color: #37009D; color: #fff;" type="button">Голосовать!</a>';
} else if (DB::query('SELECT status FROM contests WHERE status=1')[0]['status'] === 1) {
$contest = DB::query('SELECT * FROM contests WHERE status=1')[0];
$theme = DB::query('SELECT * FROM contests_themes WHERE id=:id', array(':id'=>$contest['themeid']))[0];
echo ' <div id="contestNotify" style="float:left; border:solid 1px #171022; padding:6px 10px 7px; margin-bottom:13px; background-color:#E5D6FF"><h4>Фотоконкурс!</h4>
Начнётся через: <b id="countdown"></b><br>
Тематика: <b>'.$theme.'</b><br>
<b style="color: #412378;">Лучшие фотографии по мнению сообщества '.NGALLERY['root']['title'].' будут отмечены</b><br><br>
<a href="/voting/sendpretend" style="background-color: #37009D; color: #fff;" type="button">Участвовать!</a>';
}
?>
</div>
<script>
function startCountdown(unixTimestamp) {
function padZero(num) {
return num < 10 ? '0' + num : num;
}
function getWord(num, words) {
if (num % 10 === 1 && num % 100 !== 11) return words[0];
if (num % 10 >= 2 && num % 10 <= 4 && (num % 100 < 10 || num % 100 >= 20)) return words[1];
return words[2];
}
function updateTimer() {
const now = Math.floor(Date.now() / 1000);
const diff = unixTimestamp - now;
if (diff <= 0) {
clearInterval(interval);
document.getElementById('countdown').textContent = "00 дней 00 часов 00 минут 00 секунд";
return;
}
const days = Math.floor(diff / 86400);
const hours = Math.floor((diff % 86400) / 3600);
const minutes = Math.floor((diff % 3600) / 60);
const seconds = diff % 60;
document.getElementById('countdown').textContent =
`${padZero(days)} ${getWord(days, ['день', 'дня', 'дней'])} ` +
`${padZero(hours)} ${getWord(hours, ['час', 'часа', 'часов'])} ` +
`${padZero(minutes)} ${getWord(minutes, ['минута', 'минуты', 'минут'])} ` +
`${padZero(seconds)} ${getWord(seconds, ['секунда', 'секунды', 'секунд'])}`;
}
updateTimer(); // сразу обновляем отображение
const interval = setInterval(updateTimer, 1000);
}
startCountdown(1740607200);
</script>
</div>

View file

@ -258,15 +258,24 @@ if ($photo->i('id') !== null) {
<a href="#" vote="0" class="vote_btn <?php if (Vote::photo(Auth::userid(), $id) === 0) {
echo 'voted';
} ?>"><span>Мне не&nbsp;нравится</span></a>
<?php
if ($photo->content('video') === null && $photo->i('user_id') != Auth::userid()) { ?>
<a class="konk_btn <?php if (Vote::photoContest(Auth::userid(), $id) === 1) {
echo 'voted';
} ?>" vote="1" href="#"><span>Красиво, на&nbsp;конкурс!</span></a>
<a href="#" vote="0" class="konk_btn <?php if (Vote::photoContest(Auth::userid(), $id) === 0) {
echo 'voted';
} ?>"><span>Неконкурсное фото</span></a>
<?php } else if ($photo->i('user_id') === Auth::userid()) { ?>
<!--a class="konk_btn" vote="1" href="#"><span>Красиво, на&nbsp;конкурс!</span></!--a>
<a-- href="#" vote="0" class="konk_btn"><span>Неконкурсное фото</span></a-->
<a href="#" vote="1" class="konk_btn"><span>Выставить на&nbsp;конкурс</span></a><a href="#" vote="0" class="konk_btn"><span>Не участвовать в&nbsp;конкурсе</span></a></div>
<?php } ?>
</div>
<?php } ?>
<div id="votes" class="votes">
<table class="vblock pro">
<?php
$votespos = DB::query('SELECT * FROM photos_rates WHERE photo_id=:pid AND type=1 ORDER BY id DESC', array(':pid' => $id));
$votespos = DB::query('SELECT * FROM photos_rates WHERE photo_id=:pid AND type=1 AND contest=0 ORDER BY id DESC', array(':pid' => $id));
foreach ($votespos as $ps) {
$uservote = new User($ps['user_id']);
echo ' <tr>
@ -279,7 +288,7 @@ if ($photo->i('id') !== null) {
</table>
<table class="vblock coN">
<?php
$votespos = DB::query('SELECT * FROM photos_rates WHERE photo_id=:pid AND type=0 ORDER BY id DESC', array(':pid' => $id));
$votespos = DB::query('SELECT * FROM photos_rates WHERE photo_id=:pid AND type=0 AND contest=0 ORDER BY id DESC', array(':pid' => $id));
foreach ($votespos as $ps) {
$uservote = new User($ps['user_id']);
echo ' <tr>