mirror of
https://github.com/WerySkok/nativegallery.git
synced 2024-12-22 16:41:17 +03:00
fix rating
This commit is contained in:
parent
4975eca28e
commit
399939e62e
3 changed files with 17 additions and 7 deletions
|
@ -32,9 +32,9 @@ class Rate
|
||||||
foreach ($votes as $vote) {
|
foreach ($votes as $vote) {
|
||||||
$user = new User($vote['user_id']);
|
$user = new User($vote['user_id']);
|
||||||
if ($vote['type'] === 0) {
|
if ($vote['type'] === 0) {
|
||||||
$type = -1;
|
$type = 0;
|
||||||
$formattedVotesNeg[] = [$vote['user_id'], $user->i('username'), $type];
|
$formattedVotesNeg[] = [$vote['user_id'], $user->i('username'), $type];
|
||||||
} else {
|
} else if ($vote['type'] === 1) {
|
||||||
$type = 1;
|
$type = 1;
|
||||||
$formattedVotesPos[] = [$vote['user_id'], $user->i('username'), $type];
|
$formattedVotesPos[] = [$vote['user_id'], $user->i('username'), $type];
|
||||||
}
|
}
|
||||||
|
@ -44,16 +44,27 @@ class Rate
|
||||||
if (Vote::photo(Auth::userid(), $_GET['pid']) === 0) {
|
if (Vote::photo(Auth::userid(), $_GET['pid']) === 0) {
|
||||||
$negbtn = true;
|
$negbtn = true;
|
||||||
$posbtn = false;
|
$posbtn = false;
|
||||||
} else {
|
} else if (Vote::photo(Auth::userid(), $_GET['pid']) === 1) {
|
||||||
$negbtn = false;
|
$negbtn = false;
|
||||||
$posbtn = true;
|
$posbtn = true;
|
||||||
|
} else {
|
||||||
|
$negbtn = false;
|
||||||
|
$posbtn = false;
|
||||||
}
|
}
|
||||||
$result = [
|
$result = [
|
||||||
'votes' => [$formattedVotesNeg, $formattedVotesPos],
|
|
||||||
'buttons' => [$negbtn, $posbtn],
|
'buttons' => [$negbtn, $posbtn],
|
||||||
'errors' => '',
|
'errors' => '',
|
||||||
'rating' => Vote::count($_GET['pid'])
|
'rating' => Vote::count($_GET['pid'])
|
||||||
];
|
];
|
||||||
|
$votes = [];
|
||||||
|
$votes[1] = $formattedVotesPos;
|
||||||
|
$votes[0] = $formattedVotesNeg;
|
||||||
|
|
||||||
|
if (!empty($votes)) {
|
||||||
|
$result['votes'] = $votes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||||
|
|
|
@ -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));
|
$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)) {
|
if (!empty($result)) {
|
||||||
$type = $result[0]['type'];
|
$type = $result[0]['type'];
|
||||||
|
|
||||||
if ($type < 0) {
|
if ($type < 0) {
|
||||||
$type = -1;
|
$type = -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ $photouser = new \App\Models\User($photo->i('user_id'));
|
||||||
<body>
|
<body>
|
||||||
<div id="backgr"></div>
|
<div id="backgr"></div>
|
||||||
<table class="tmain">
|
<table class="tmain">
|
||||||
|
<?=Vote::photo(Auth::userid(), $id)?>
|
||||||
<?php include($_SERVER['DOCUMENT_ROOT'] . '/views/components/Navbar.php'); ?>
|
<?php include($_SERVER['DOCUMENT_ROOT'] . '/views/components/Navbar.php'); ?>
|
||||||
<tr>
|
<tr>
|
||||||
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
|
<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="star" pid="1361063"></div>
|
||||||
<div class="vote" pid="<?= $id ?>">
|
<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="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>Мне не нравится</span></a>
|
<a href="#" vote="0" class="vote_btn <?php if (Vote::photo(Auth::userid(), $id) === 0) { echo 'voted'; } ?>"><span>Мне не нравится</span></a>
|
||||||
</div>
|
</div>
|
||||||
<div id="votes" class="votes">
|
<div id="votes" class="votes">
|
||||||
<table class="vblock pro">
|
<table class="vblock pro">
|
||||||
|
|
Loading…
Reference in a new issue