diff --git a/assets/less/forum/poll.less b/assets/less/forum/poll.less index 7cbe67d4..880f85ac 100644 --- a/assets/less/forum/poll.less +++ b/assets/less/forum/poll.less @@ -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; diff --git a/public/forum/poll.php b/public/forum/poll.php index b816ebdc..a8ec1427 100644 --- a/public/forum/poll.php +++ b/public/forum/poll.php @@ -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.
"; + return; +} + if (!forum_perms_check_user( MSZ_FORUM_PERMS_GENERAL, $topicInfo['forum_id'], $currentUserId, MSZ_FORUM_PERM_SET_READ diff --git a/src/Forum/poll.php b/src/Forum/poll.php index 45b2c8d3..7202ef3b 100644 --- a/src/Forum/poll.php +++ b/src/Forum/poll.php @@ -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 "); diff --git a/templates/forum/macros.twig b/templates/forum/macros.twig index 6f695545..42ace084 100644 --- a/templates/forum/macros.twig +++ b/templates/forum/macros.twig @@ -467,24 +467,27 @@ {% 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 %}
{% if results_available %} - {{ input_checkbox_raw('', display_results, 'forum__poll__toggle', '', false, {'id':'forum-poll-toggle'}) }} + {% if options_available %} + {{ input_checkbox_raw('', display_results, 'forum__poll__toggle', '', false, {'id':'forum-poll-toggle'}) }} + {% endif %} +
{% for option in options %} {% set percent = poll.poll_votes < 1 ? 0 : (option.option_votes / poll.poll_votes) * 100 %} -
+
@@ -506,7 +509,7 @@
{% endif %} - {% if can_vote %} + {% if options_available %}
@@ -514,7 +517,7 @@
{% endif %} - {% if can_vote %} + {% if options_available %}
{{ 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 %}
- {% if poll.poll_max_votes > 1 %} + {% if can_vote and poll.poll_max_votes > 1 %}
You have {{ poll.poll_max_votes }} votes @@ -545,7 +549,9 @@ {% endif %}
- + {% if can_vote %} + + {% endif %} {% if results_available %} {% endif %} diff --git a/templates/forum/topic.twig b/templates/forum/topic.twig index 7d066cef..b23c4d62 100644 --- a/templates/forum/topic.twig +++ b/templates/forum/topic.twig @@ -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 }} diff --git a/utility.php b/utility.php index 21d4ee88..a0f6aac0 100644 --- a/utility.php +++ b/utility.php @@ -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);