Fixed the way polls are displayed in certain situations.

This commit is contained in:
flash 2019-05-05 17:46:57 +02:00
parent f5d693f24b
commit d33f7614d0
6 changed files with 34 additions and 12 deletions

View file

@ -70,6 +70,10 @@
opacity: .2;
}
&--voted &__background {
opacity: .4;
}
&__container {
display: flex;
justify-content: center;
@ -80,6 +84,10 @@
padding: 5px;
}
&--voted &__text {
font-weight: 700;
}
&__votes {
flex: 0 0 auto;
padding: 5px;

View file

@ -48,6 +48,11 @@ if (empty($poll)) {
$topicInfo = forum_poll_get_topic($poll['poll_id']);
if (!is_null($topicInfo['topic_locked'])) {
echo "The topic associated with this poll has been locked.<br>";
return;
}
if (!forum_perms_check_user(
MSZ_FORUM_PERMS_GENERAL, $topicInfo['forum_id'],
$currentUserId, MSZ_FORUM_PERM_SET_READ

View file

@ -202,7 +202,7 @@ function forum_poll_get_topic(int $poll): array
}
$getTopic = db_prepare("
SELECT `forum_id`, `topic_id`
SELECT `forum_id`, `topic_id`, `topic_locked`
FROM `msz_forum_topics`
WHERE `poll_id` = :poll
");

View file

@ -467,24 +467,27 @@
</div>
{% endmacro %}
{% macro forum_poll(poll, options, user_answers, topic_id) %}
{% macro forum_poll(poll, options, user_answers, topic_id, can_vote, preview_results) %}
{% from '_layout/input.twig' import input_csrf, input_hidden, input_checkbox, input_checkbox_raw %}
{% set user_answers = user_answers is empty or user_answers is not iterable ? [] : user_answers %}
{% set user_answered = user_answers|length > 0 %}
{% set results_available = user_answered or poll.poll_expired or poll.poll_preview_results %}
{% set can_vote = not poll.poll_expired and (poll.poll_change_vote or not user_answered) %}
{% set results_available = preview_results or user_answered or poll.poll_expired or poll.poll_preview_results %}
{% set options_available = not poll.poll_expired and (poll.poll_change_vote or not user_answered) %}
{% set display_results = user_answered or poll.poll_expired %}
{% if options is iterable and options|length > 0 %}
<div class="forum__poll">
{% if results_available %}
{% if options_available %}
{{ input_checkbox_raw('', display_results, 'forum__poll__toggle', '', false, {'id':'forum-poll-toggle'}) }}
{% endif %}
<div class="container forum__poll__container forum__poll__container--results">
<div class="forum__poll__results">
{% for option in options %}
{% set percent = poll.poll_votes < 1 ? 0 : (option.option_votes / poll.poll_votes) * 100 %}
<div class="forum__poll__result">
<div class="forum__poll__result{% if option.option_id in user_answers %} forum__poll__result--voted{% endif %}">
<div class="forum__poll__result__background" style="width: {{ percent }}%">
</div>
<div class="forum__poll__result__container">
@ -506,7 +509,7 @@
</div>
{% endif %}
{% if can_vote %}
{% if options_available %}
<div class="forum__poll__buttons">
<label class="input__button forum__poll__button" for="forum-poll-toggle">Vote</label>
</div>
@ -514,7 +517,7 @@
</div>
{% endif %}
{% if can_vote %}
{% if options_available %}
<form method="post" action="{{ url('forum-poll-vote') }}" class="container forum__poll__container forum__poll__container--poll js-forum-poll"
data-poll-id="{{ poll.poll_id }}" data-poll-max-votes="{{ poll.poll_max_votes }}">
{{ input_csrf('forum_poll') }}
@ -525,12 +528,13 @@
{{ input_checkbox(
'poll[answers][]',
option.option_text, option.option_id in user_answers, 'forum__poll__option',
option.option_id, poll.poll_max_votes <= 1
option.option_id, poll.poll_max_votes <= 1,
null, not can_vote
) }}
{% endfor %}
</div>
{% if poll.poll_max_votes > 1 %}
{% if can_vote and poll.poll_max_votes > 1 %}
<div class="forum__poll__remaining js-forum-poll-remaining">
You have <span class="forum__poll__remaining__num">
<span class="js-forum-poll-remaining-count">{{ poll.poll_max_votes }}</span> vote<span class="js-forum-poll-remaining-plural">s</span>
@ -545,7 +549,9 @@
{% endif %}
<div class="forum__poll__buttons">
{% if can_vote %}
<button class="input__button forum__poll__button">Vote</button>
{% endif %}
{% if results_available %}
<label class="input__button forum__poll__button" for="forum-poll-toggle">Results</label>
{% endif %}

View file

@ -56,7 +56,7 @@
{% block content %}
{{ forum_header(topic_info.topic_title, topic_breadcrumbs, false, canonical_url, topic_actions) }}
{{ topic_notice }}
{{ forum_poll(topic_info, topic_poll_options, topic_poll_user_answers, topic_info.topic_id) }}
{{ forum_poll(topic_info, topic_poll_options, topic_poll_user_answers, topic_info.topic_id, current_user.user_id|default(0) > 0, topic_info.author_user_id == current_user.user_id|default(0)) }}
{{ topic_tools }}
{{ forum_post_listing(topic_posts, current_user.user_id|default(0), topic_perms) }}
{{ topic_tools }}

View file

@ -64,6 +64,9 @@ function pdo_prepare_array(array $keys, bool $useKeys = false, string $format =
return implode(', ', $parts);
}
// render_error, render_info and render_info_or_json should be redone a bit better
// following a uniform format so there can be a global handler for em
function render_error(int $code, string $template = 'errors.%d'): string
{
return render_info(null, $code, $template);