Hide vote button in poll if user already voted (#1235)

* Hide vote button in poll if user already voted

* Update viewtopic.php

* Update CHANGELOG.md
This commit is contained in:
Roman Kelesidis 2023-12-21 00:15:06 +07:00 committed by GitHub
commit 428984524e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 6 deletions

View file

@ -26,6 +26,7 @@
- Introduce limit setting for max number of files to be processed in separate index file-listing [\#1223](https://github.com/torrentpier/torrentpier/pull/1223) ([kovalensky](https://github.com/kovalensky))
- Fixed set auth cookie issue [\#1227](https://github.com/torrentpier/torrentpier/pull/1227) ([belomaxorka](https://github.com/belomaxorka))
- Fixed broken captcha check on login.php [\#1233](https://github.com/torrentpier/torrentpier/pull/1233) ([belomaxorka](https://github.com/belomaxorka))
- Hide vote button in poll if user already voted [\#1235](https://github.com/torrentpier/torrentpier/pull/1235) ([belomaxorka](https://github.com/belomaxorka))
- New Crowdin updates [\#1203](https://github.com/torrentpier/torrentpier/pull/1203), [\#1222](https://github.com/torrentpier/torrentpier/pull/1222) ([Exileum](https://github.com/Exileum))
## [v2.4.0-rc2](https://github.com/torrentpier/torrentpier/tree/v2.4.0-rc2) (2023-12-12)

View file

@ -68,7 +68,7 @@ switch ($mode) {
}
// Checking that poll has not been finished
if (!\TorrentPier\Legacy\Poll::poll_is_active($t_data)) {
if (!\TorrentPier\Legacy\Poll::pollIsActive($t_data)) {
bb_die($lang['NEW_POLL_ENDED']);
}
@ -76,7 +76,7 @@ switch ($mode) {
bb_die($lang['NO_VOTE_OPTION']);
}
if (DB()->fetch_row("SELECT 1 FROM " . BB_POLL_USERS . " WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']} LIMIT 1")) {
if (\TorrentPier\Legacy\Poll::userIsAlreadyVoted($topic_id, (int)$userdata['user_id'])) {
bb_die($lang['ALREADY_VOTED']);
}

View file

@ -142,13 +142,25 @@ class Poll
return is_array($topic_id) ? $items : $items[$topic_id];
}
/**
* Checks whether the user has voted in a poll
*
* @param int $topic_id
* @param int $user_id
* @return bool
*/
public static function userIsAlreadyVoted(int $topic_id, int $user_id): bool
{
return (bool)DB()->fetch_row("SELECT user_id FROM " . BB_POLL_USERS . " WHERE topic_id = $topic_id AND user_id = $user_id LIMIT 1");
}
/**
* Check whether poll is active
*
* @param array $t_data
* @return bool
*/
public static function poll_is_active(array $t_data): bool
public static function pollIsActive(array $t_data): bool
{
global $bb_cfg;
return ($t_data['topic_vote'] == 1 && $t_data['topic_time'] > TIMENOW - $bb_cfg['poll_max_days'] * 86400);

View file

@ -126,10 +126,10 @@ function html2text (str)
<table id="poll-results-block" class="borderless bCenter"></table>
<table id="poll-votes-block" class="borderless bCenter"></table>
<!-- IF SHOW_VOTE_BTN -->
<!-- IF not POLL_ALREADY_VOTED && SHOW_VOTE_BTN -->
<div id="vote-btn-a" class="mrg_8 tCenter">[ <a href="#" onclick="build_votes(); return false;" class="gen"><b>{L_SUBMIT_VOTE}</b></a> ]</div>
<div id="vote-btn-input" class="mrg_6 tCenter" style="display: none;"><input type="button" onclick="submit_vote(); return false;" value="{L_SUBMIT_VOTE}" class="bold" /></div>
<!-- ELSE -->
<!-- ELSEIF not SHOW_VOTE_BTN -->
<div class="mrg_8 tCenter">[ <b>{L_NEW_POLL_END}</b> ]</div>
<!-- ENDIF -->

View file

@ -552,7 +552,8 @@ if ($topic_has_poll) {
$template->assign_vars(['TOPIC_HAS_POLL' => false]);
} else {
$template->assign_vars([
'SHOW_VOTE_BTN' => \TorrentPier\Legacy\Poll::poll_is_active($t_data),
'SHOW_VOTE_BTN' => \TorrentPier\Legacy\Poll::pollIsActive($t_data),
'POLL_ALREADY_VOTED' => \TorrentPier\Legacy\Poll::userIsAlreadyVoted($topic_id, (int)$userdata['user_id']),
'POLL_VOTES_JS' => $poll_votes_js
]);
}