fix rating

This commit is contained in:
themohooks 2024-07-06 08:58:54 +03:00
parent 4975eca28e
commit 399939e62e
3 changed files with 17 additions and 7 deletions

View file

@ -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);

View file

@ -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;
}

View file

@ -21,7 +21,7 @@ $photouser = new \App\Models\User($photo->i('user_id'));
<body>
<div id="backgr"></div>
<table class="tmain">
<?=Vote::photo(Auth::userid(), $id)?>
<?php include($_SERVER['DOCUMENT_ROOT'] . '/views/components/Navbar.php'); ?>
<tr>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
@ -133,7 +133,7 @@ $photouser = new \App\Models\User($photo->i('user_id'));
<div class="star" pid="1361063"></div>
<div class="vote" pid="<?= $id ?>">
<a href="#" vote="1" class="vote_btn <?php if (Vote::photo(Auth::userid(), $id) === 1) { echo 'voted'; } ?>"><span>Интересная фотография!</span></a>
<a href="#" vote="0" class="vote_btn <?php if (Vote::photo(Auth::userid(), $id) === -1) { echo 'voted'; } ?>"><span>Мне не&nbsp;нравится</span></a>
<a href="#" vote="0" class="vote_btn <?php if (Vote::photo(Auth::userid(), $id) === 0) { echo 'voted'; } ?>"><span>Мне не&nbsp;нравится</span></a>
</div>
<div id="votes" class="votes">
<table class="vblock pro">