From bc86ec2db68a48c74d2b8a5f1f8aeed8aa69bf49 Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Mon, 9 Nov 2026 08:36:02 +0100 Subject: [PATCH] Allow Q&A rounds without upvotes and limit upvotes per question - max_upvotes = 0 disables upvoting: the voting stage is skipped (collect -> discuss), questions are discussed in submission order - new setting max_upvotes_per_question caps a participant's upvotes on a single question (0 = no limit besides max_upvotes) Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 4 ++ src/Controller/SlidesController.php | 5 ++ src/Model/Entity/Slide.php | 38 ++++++++++++- src/Model/Table/SlidesTable.php | 6 +- src/Service/PollStateService.php | 4 +- src/Service/QaService.php | 18 +++--- src/Service/ResultsService.php | 6 +- src/Service/SlideControlService.php | 2 +- src/Service/VoteService.php | 18 +++++- templates/Admin/export.php | 5 +- templates/Admin/index.php | 6 +- templates/Participate/view.php | 27 ++++++--- templates/Slides/form.php | 14 ++++- tests/TestCase/Controller/QaSlideTest.php | 33 +++++++++++ tests/TestCase/Service/QaTest.php | 68 ++++++++++++++++++++++- webroot/js/plenario.js | 19 +++++-- 16 files changed, 235 insertions(+), 38 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 2f032e8..d5f5b63 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -156,6 +156,10 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures (gegen Dubletten, eigene markiert), aber noch keine Upvotes. `vote`: Upvotes auf fremde Fragen, Budget = Setting `max_upvotes` pro Person, frei verteilbar (auch mehrere auf eine Frage, je Upvote eine Zeile), `vote=remove` nimmt eine Stimme der Frage zurück; im State `qa.upvoted` = {Frage-id: eigene Stimmen}. + Setting `max_upvotes_per_question` begrenzt die eigenen Stimmen je Frage (0 = nur durch `max_upvotes` begrenzt, + effektiv `Slide::qaUpvotesPerQuestion()`, State `maxPerQuestion`). `max_upvotes = 0` = ohne Upvotes: es gibt keine Phase `vote` + (`Slide::qaStages()` = collect → discuss, im Presenter-JSON `results.stages`), besprochen wird in Eingangsreihenfolge; + wird es während `vote` auf 0 gesetzt, springt `SlidesController::saveSlide()` nach `discuss`. Setting `allow_self_upvote` (Standard aus, für Themen-Priorisierung) erlaubt Stimmen auf eigene Fragen aus demselben Budget (State `qa.allowSelfUpvote`); bewusst aus, weil anonym sonst Selbstvermarktung die Rangfolge bestimmt; Teilnehmende sehen alle Fragen in Eingangsreihenfolge **ohne** Zählung. `discuss`: Abstimmung zu, Fragen nach Upvotes diff --git a/src/Controller/SlidesController.php b/src/Controller/SlidesController.php index 8393477..0908100 100644 --- a/src/Controller/SlidesController.php +++ b/src/Controller/SlidesController.php @@ -5,6 +5,7 @@ namespace App\Controller; use App\Model\Entity\Slide; use App\Model\Table\SlidesTable; +use App\Service\QaService; use App\Service\ResetService; use App\Service\ResultsService; use App\Service\YouTubeService; @@ -300,6 +301,10 @@ class SlidesController extends AdminAppController if ($slide->type === Slide::TYPE_CHOICE || $slide->isQuiz() || $slide->isOrder()) { $this->Slides->syncOptions($slide, $labels, $correct); } + if ($slide->isQa() && $slide->qaStage() === Slide::QA_VOTE && !$slide->hasQaUpvotes()) { + // Upvotes were switched off while voting: continue with the discussion. + (new QaService())->setStage($slide, Slide::QA_DISCUSS); + } if ($youtube['warning'] !== null) { $this->Flash->warning($youtube['warning']); } diff --git a/src/Model/Entity/Slide.php b/src/Model/Entity/Slide.php index 57b8820..b625d80 100644 --- a/src/Model/Entity/Slide.php +++ b/src/Model/Entity/Slide.php @@ -104,9 +104,10 @@ class Slide extends Entity self::TYPE_QUIZ => ['time_limit' => 30], // url as entered, video_id parsed from it, start in seconds self::TYPE_YOUTUBE => ['url' => '', 'video_id' => '', 'start' => 0, 'autoplay' => false], - // upvotes per participant in the voting stage (1..QA_MAX_UPVOTES); + // max_upvotes: upvotes per participant in the voting stage (0..QA_MAX_UPVOTES, 0 = no voting stage); + // max_upvotes_per_question: own upvotes per question (0 = no limit besides max_upvotes); // allow_self_upvote: upvotes on own questions (for prioritizing topics, off by default) - self::TYPE_QA => ['max_upvotes' => 3, 'allow_self_upvote' => false], + self::TYPE_QA => ['max_upvotes' => 3, 'max_upvotes_per_question' => 0, 'allow_self_upvote' => false], // The correct order is the order of the slide_options (position), revealed when voting closes. self::TYPE_ORDER => [], ]; @@ -316,6 +317,39 @@ class Slide extends Entity return in_array($this->stage, self::QA_STAGES, true) ? (string)$this->stage : self::QA_COLLECT; } + /** + * Whether a Q&A slide has a voting stage (setting `max_upvotes` > 0). + * + * @return bool + */ + public function hasQaUpvotes(): bool + { + return (int)$this->setting('max_upvotes') > 0; + } + + /** + * Stages of a Q&A slide in order: without upvotes the voting stage is skipped. + * + * @return list + */ + public function qaStages(): array + { + return $this->hasQaUpvotes() ? self::QA_STAGES : [self::QA_COLLECT, self::QA_DISCUSS]; + } + + /** + * Upvotes one participant may give a single Q&A question (never more than `max_upvotes`). + * + * @return int + */ + public function qaUpvotesPerQuestion(): int + { + $max = (int)$this->setting('max_upvotes'); + $perQuestion = (int)$this->setting('max_upvotes_per_question'); + + return $perQuestion > 0 ? min($perQuestion, $max) : $max; + } + /** * Whether a participant may answer the slide several times (word cloud: one * row per word, Q&A: questions and upvotes). diff --git a/src/Model/Table/SlidesTable.php b/src/Model/Table/SlidesTable.php index 6d223d3..b7990fc 100644 --- a/src/Model/Table/SlidesTable.php +++ b/src/Model/Table/SlidesTable.php @@ -172,7 +172,11 @@ class SlidesTable extends Table break; case Slide::TYPE_QA: $max = (int)($input['max_upvotes'] ?? $settings['max_upvotes']); - $settings['max_upvotes'] = max(1, min(Slide::QA_MAX_UPVOTES, $max)); + // 0 = no upvotes (no voting stage) + $settings['max_upvotes'] = max(0, min(Slide::QA_MAX_UPVOTES, $max)); + $perQuestion = (int)($input['max_upvotes_per_question'] ?? $settings['max_upvotes_per_question']); + // 0 = no limit per question + $settings['max_upvotes_per_question'] = max(0, min(Slide::QA_MAX_UPVOTES, $perQuestion)); $settings['allow_self_upvote'] = filter_var($input['allow_self_upvote'] ?? false, FILTER_VALIDATE_BOOLEAN); break; case Slide::TYPE_YOUTUBE: diff --git a/src/Service/PollStateService.php b/src/Service/PollStateService.php index aba4d18..94ccea9 100644 --- a/src/Service/PollStateService.php +++ b/src/Service/PollStateService.php @@ -280,10 +280,11 @@ class PollStateService * - discuss: all questions ranked with upvotes, `focusId` = question being discussed * `upvoted` = own upvotes per question id (several per question are allowed), * `allowSelfUpvote` = own questions may be upvoted too (setting `allow_self_upvote`). + * `maxUpvotes` = 0: no voting stage; `maxPerQuestion` = own upvotes allowed per question. * * @param \App\Model\Entity\Slide $slide Q&A slide * @param string $participantHash Participant hash - * @return array{stage: string, maxUpvotes: int, votesLeft: int, allowSelfUpvote: bool, mine: list, upvoted: array, + * @return array{stage: string, maxUpvotes: int, maxPerQuestion: int, votesLeft: int, allowSelfUpvote: bool, mine: list, upvoted: array, * questions: list, focusId: int|null} */ public function qaState(Slide $slide, string $participantHash): array @@ -305,6 +306,7 @@ class PollStateService return [ 'stage' => $stage, 'maxUpvotes' => $max, + 'maxPerQuestion' => $slide->qaUpvotesPerQuestion(), 'votesLeft' => max(0, $max - count($own['upvotes'])), 'allowSelfUpvote' => (bool)$slide->setting('allow_self_upvote'), 'mine' => $own['questions'], diff --git a/src/Service/QaService.php b/src/Service/QaService.php index 378f46c..188d98a 100644 --- a/src/Service/QaService.php +++ b/src/Service/QaService.php @@ -15,7 +15,8 @@ use InvalidArgumentException; * Stages (Slide::qaStage()): * - collect: participants submit questions (voting open) * - vote: participants upvote questions of others (own ones with `allow_self_upvote`), - * at most `max_upvotes` each (voting open) + * at most `max_upvotes` each and `max_upvotes_per_question` per question (voting open). + * Skipped with `max_upvotes` = 0 (Slide::qaStages()). * - discuss: voting closed; the presenter steps through the questions, most upvoted * first (`slides.focus_response_id` = question on screen) * @@ -70,15 +71,15 @@ class QaService /** * Switches the stage. Collecting and voting open the slide for input, * discussing closes it and puts the top question on screen. Setting the - * current stage again changes nothing. + * current stage again changes nothing. Without upvotes there is no voting stage. * * @param \App\Model\Entity\Slide $slide Q&A slide - * @param string $stage One of Slide::QA_STAGES + * @param string $stage One of Slide::qaStages() * @return \App\Model\Entity\Slide */ public function setStage(Slide $slide, string $stage): Slide { - if (!$slide->isQa() || !in_array($stage, Slide::QA_STAGES, true)) { + if (!$slide->isQa() || !in_array($stage, $slide->qaStages(), true)) { throw new InvalidArgumentException('Unknown Q&A stage ' . $stage); } if ($slide->qaStage() === $stage && $slide->stage !== null) { @@ -95,18 +96,19 @@ class QaService } /** - * Moves to the following stage (collect → vote → discuss). + * Moves to the following stage (collect → vote → discuss, without upvotes collect → discuss). * * @param \App\Model\Entity\Slide $slide Q&A slide * @return bool False when already discussing */ public function advance(Slide $slide): bool { - $index = (int)array_search($slide->qaStage(), Slide::QA_STAGES, true); - if (!isset(Slide::QA_STAGES[$index + 1])) { + $stages = $slide->qaStages(); + $index = (int)array_search($slide->qaStage(), $stages, true); + if (!isset($stages[$index + 1])) { return false; } - $this->setStage($slide, Slide::QA_STAGES[$index + 1]); + $this->setStage($slide, $stages[$index + 1]); return true; } diff --git a/src/Service/ResultsService.php b/src/Service/ResultsService.php index 28026a2..ac66a36 100644 --- a/src/Service/ResultsService.php +++ b/src/Service/ResultsService.php @@ -36,7 +36,9 @@ use Cake\ORM\Locator\LocatorAwareTrait; * order with 'position' (1-based), 'placed' (participants who put the item at its position), * 'percent', plus 'correctCount' (participants with the completely correct order). * Neither the correct order nor counts are part of the result before it is revealed. - * - qa: 'stage' (collect|vote|discuss), 'maxUpvotes', 'upvotes' (total), + * - qa: 'stage' (collect|vote|discuss), 'stages' (available stages in order, no 'vote' without upvotes), + * 'maxUpvotes' (per participant, 0 = no upvotes), 'maxPerQuestion' (per participant and question), + * 'upvotes' (total), * 'questions' => [['id', 'text', 'votes']] most upvoted first (ties: oldest first), * 'focusId' (question being discussed|null), 'focusIndex' (0-based position in questions|null). * Presenter only – participants get their own view, see PollStateService::qaState(). @@ -221,7 +223,9 @@ class ResultsService return [ 'stage' => $slide->qaStage(), + 'stages' => $slide->qaStages(), 'maxUpvotes' => (int)$slide->setting('max_upvotes'), + 'maxPerQuestion' => $slide->qaUpvotesPerQuestion(), 'upvotes' => array_sum(array_column($questions, 'votes')), 'questions' => $questions, 'focusId' => $focusIndex === null ? null : $slide->focus_response_id, diff --git a/src/Service/SlideControlService.php b/src/Service/SlideControlService.php index 5123858..e0c5478 100644 --- a/src/Service/SlideControlService.php +++ b/src/Service/SlideControlService.php @@ -54,7 +54,7 @@ class SlideControlService break; } $stage = (string)($data['stage'] ?? ''); - if (!in_array($stage, Slide::QA_STAGES, true)) { + if (!in_array($stage, $slide->qaStages(), true)) { throw new BadRequestException('Unknown stage'); } $qa->setStage($slide, $stage); diff --git a/src/Service/VoteService.php b/src/Service/VoteService.php index 6b5836a..0e56276 100644 --- a/src/Service/VoteService.php +++ b/src/Service/VoteService.php @@ -31,7 +31,8 @@ use Cake\Utility\Security; * at most MAX_QA_QUESTIONS per participant, the same question (case-insensitive) * only once per slide. `vote=up|remove` + `question_id` only while voting: upvote * questions of others (own ones too with setting `allow_self_upvote`), at most - * `max_upvotes` in total, freely distributed (several on one question are allowed); + * `max_upvotes` in total, freely distributed (several on one question are allowed, + * at most `max_upvotes_per_question` if set; `max_upvotes` = 0 means no voting stage); * `remove` withdraws one own upvote of the question. * - ordering: `order` = all option ids, each exactly once, in the participant's order. * Stored as one row with the ids comma separated in `text_value` (see parseOrder()). @@ -297,6 +298,9 @@ class VoteService return [['text_value' => $text]]; } + if (!$slide->hasQaUpvotes()) { + throw new VoteException(__('Bei dieser Fragerunde wird nicht abgestimmt.')); + } if ($stage !== Slide::QA_VOTE) { throw new VoteException(__('Die Abstimmung über die Fragen hat noch nicht begonnen.')); } @@ -324,8 +328,18 @@ class VoteService if (!$slide->setting('allow_self_upvote') && in_array($id, $own['questions'], true)) { throw new VoteException(__('Deine eigene Frage kannst du nicht unterstützen.')); } - // Several upvotes on the same question are allowed (push important questions). + // Several upvotes on the same question are allowed (push important questions), + // up to the limit per question. $max = (int)$slide->setting('max_upvotes'); + $perQuestion = $slide->qaUpvotesPerQuestion(); + if ($perQuestion < $max && count(array_keys($own['upvotes'], $id, true)) >= $perQuestion) { + throw new VoteException(__n( + 'Du kannst jeder Frage nur eine Stimme geben.', + 'Du kannst jeder Frage höchstens {0} Stimmen geben.', + $perQuestion, + $perQuestion, + )); + } if (count($own['upvotes']) >= $max) { throw new VoteException(__n( 'Du hast deine Stimme schon vergeben. Nimm sie zurück, um eine andere Frage zu unterstützen.', diff --git a/templates/Admin/export.php b/templates/Admin/export.php index 4894446..fc03efc 100644 --- a/templates/Admin/export.php +++ b/templates/Admin/export.php @@ -211,14 +211,15 @@ $bar = function (float $percent, bool $ok = false): string {

+ 0; ?> - + $question) : ?> - + diff --git a/templates/Admin/index.php b/templates/Admin/index.php index d06239f..b5781ac 100644 --- a/templates/Admin/index.php +++ b/templates/Admin/index.php @@ -96,7 +96,11 @@ $hasInternal = array_filter($slides, fn($slide) => $slide->isInteractive() && $s 'collect' => __('Fragen sammeln'), 'vote' => __('Abstimmung läuft'), 'discuss' => __('Fragen werden besprochen'), - ][$slide->qaStage()]) ?> · setting('max_upvotes'), (int)$slide->setting('max_upvotes')) ?>setting('allow_self_upvote') ? ' · ' . __('auch für eigene Fragen') : '' ?> + ][$slide->qaStage()]) ?> · hasQaUpvotes()) : ?>setting('max_upvotes'); + $perQuestion = $slide->qaUpvotesPerQuestion(); ?> + setting('allow_self_upvote') ? ' · ' . __('auch für eigene Fragen') : '' ?> + isOrder() && !$slide->is_voting_open) : ?> · is_voting_open) : ?>· diff --git a/templates/Participate/view.php b/templates/Participate/view.php index 096bc75..69466a1 100644 --- a/templates/Participate/view.php +++ b/templates/Participate/view.php @@ -173,19 +173,28 @@ $countdown = function (?int $remaining): string { -

+

0 + ? __('Anonym. Du kannst mehrere Fragen stellen. Schau unten, ob deine Frage schon gestellt wurde – dann unterstützt du sie einfach beim Abstimmen, das nach der Sammelphase beginnt.') + : __('Anonym. Du kannst mehrere Fragen stellen. Schau unten, ob deine Frage schon gestellt wurde.') ?>

Form->button(__('Frage einreichen'), ['class' => 'button button--primary button--block']) ?> Form->end() ?> Form->hidden('slide_id', ['value' => $slide->id]) ?> -

+

+ + + + + + + + + + 0) : ?> + + + +

diff --git a/templates/Slides/form.php b/templates/Slides/form.php index b454565..650ec7d 100644 --- a/templates/Slides/form.php +++ b/templates/Slides/form.php @@ -285,12 +285,20 @@ $optionsError = $slide->getError('options_text'); ?> Form->control('settings.max_upvotes', [ 'type' => 'select', - 'options' => $upvoteOptions, + 'options' => [0 => __('keine – ohne Abstimmung')] + $upvoteOptions, 'label' => __('Upvotes (Stimmen) pro Person'), 'value' => $settings['max_upvotes'], 'aria-describedby' => 'qa-upvotes-hint', ]) ?> -

+

+ Form->control('settings.max_upvotes_per_question', [ + 'type' => 'select', + 'options' => [0 => __('unbegrenzt (bis alle Stimmen vergeben sind)')] + $upvoteOptions, + 'label' => __('Höchstens pro Frage'), + 'value' => $settings['max_upvotes_per_question'], + 'aria-describedby' => 'qa-per-question-hint', + ]) ?> +

Form->control('settings.allow_self_upvote', [ 'type' => 'checkbox', 'label' => __('Stimmen für eigene Fragen erlauben'), @@ -298,7 +306,7 @@ $optionsError = $slide->getError('options_text'); 'aria-describedby' => 'qa-self-upvote-hint', ]) ?>

-

+

isInteractive() && !$slide->isQuiz() && !$slide->isQa()) : ?> diff --git a/tests/TestCase/Controller/QaSlideTest.php b/tests/TestCase/Controller/QaSlideTest.php index f2956a1..73f9b21 100644 --- a/tests/TestCase/Controller/QaSlideTest.php +++ b/tests/TestCase/Controller/QaSlideTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Test\TestCase\Controller; use App\Model\Entity\Slide; +use App\Service\QaService; use App\Service\VoteService; use App\Test\TestCase\PlenarioTestTrait; use Cake\TestSuite\IntegrationTestTrait; @@ -79,6 +80,38 @@ class QaSlideTest extends TestCase $this->assertResponseContains('max. 5 Upvotes pro Person'); } + public function testSwitchingOffUpvotesSkipsTheVotingStage(): void + { + [$poll, $token] = $this->createPoll(); + $slide = $this->createSlide($poll, Slide::TYPE_QA, ['settings' => ['max_upvotes' => 2]]); + $this->goLive($poll, $slide); + (new QaService())->setStage($slide, Slide::QA_VOTE); + + $this->get("/admin/$token/slides/{$slide->id}/edit"); + $this->assertResponseContains('keine – ohne Abstimmung'); + $this->assertResponseContains('Höchstens pro Frage'); + + // Switched off while voting: the round continues with the discussion. + $this->post("/admin/$token/slides/{$slide->id}/edit", [ + 'question' => $slide->question, + 'settings' => ['max_upvotes' => '0', 'max_upvotes_per_question' => '0'], + ]); + $this->assertRedirect(); + $slide = $this->slidesTable()->get($slide->id); + $this->assertSame([0, Slide::QA_DISCUSS, false], [$slide->setting('max_upvotes'), $slide->qaStage(), $slide->is_voting_open]); + + $this->get("/admin/$token"); + $this->assertResponseContains('ohne Upvotes'); + + // Back to collecting, V goes straight to discussing; "vote" is rejected. + $state = $this->control($token, ['action' => 'stage', 'stage' => 'collect']); + $this->assertSame(['collect', 'discuss'], $state['results']['stages']); + $state = $this->control($token, ['action' => 'toggle']); + $this->assertSame('discuss', $state['results']['stage']); + $this->post("/admin/$token/control", ['action' => 'stage', 'stage' => 'vote']); + $this->assertResponseCode(400); + } + public function testFullRoundTrip(): void { [$poll, $token] = $this->createPoll(); diff --git a/tests/TestCase/Service/QaTest.php b/tests/TestCase/Service/QaTest.php index ec0e527..409735c 100644 --- a/tests/TestCase/Service/QaTest.php +++ b/tests/TestCase/Service/QaTest.php @@ -12,6 +12,7 @@ use App\Service\VoteException; use App\Service\VoteService; use App\Test\TestCase\PlenarioTestTrait; use Cake\TestSuite\TestCase; +use InvalidArgumentException; /** * Q&A slides: collect questions, upvote, discuss one by one. @@ -76,8 +77,73 @@ class QaTest extends TestCase $this->assertSame(Slide::QA_COLLECT, $slide->qaStage()); $table = $this->slidesTable(); - $this->assertSame(1, $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '0']])->setting('max_upvotes')); + $this->assertSame(0, $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '0']])->setting('max_upvotes')); + $this->assertSame(0, $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '-3']])->setting('max_upvotes')); $this->assertSame(10, $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '99']])->setting('max_upvotes')); + + $this->assertSame(0, $slide->setting('max_upvotes_per_question')); + $patched = $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '5', 'max_upvotes_per_question' => '2']]); + $this->assertSame([2, 2], [$patched->setting('max_upvotes_per_question'), $patched->qaUpvotesPerQuestion()]); + $patched = $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '3', 'max_upvotes_per_question' => '99']]); + // Never more per question than in total. + $this->assertSame([10, 3], [$patched->setting('max_upvotes_per_question'), $patched->qaUpvotesPerQuestion()]); + $patched = $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '4', 'max_upvotes_per_question' => '0']]); + $this->assertSame(4, $patched->qaUpvotesPerQuestion(), '0 = no limit per question'); + } + + public function testWithoutUpvotesThereIsNoVotingStage(): void + { + [$poll, $slide] = $this->createQa(0); + $this->assertFalse($slide->hasQaUpvotes()); + $this->assertSame([Slide::QA_COLLECT, Slide::QA_DISCUSS], $slide->qaStages()); + $first = $this->ask($poll, $slide, 'p1', 'Frage A'); + $this->ask($poll, $slide, 'p2', 'Frage B'); + $this->assertVoteFails('Bei dieser Fragerunde wird nicht abgestimmt.', fn() => $this->vote($poll, $slide, 'p2', $first)); + + $qa = new QaService(); + try { + $qa->setStage($slide, Slide::QA_VOTE); + $this->fail('No voting stage expected'); + } catch (InvalidArgumentException) { + } + + // collect → discuss, in submission order. + $this->assertTrue($qa->advance($slide)); + $slide = $this->slidesTable()->get($slide->id); + $this->assertSame([Slide::QA_DISCUSS, $first, false], [$slide->qaStage(), $slide->focus_response_id, $slide->is_voting_open]); + $this->assertFalse($qa->advance($slide)); + + $results = (new ResultsService())->forSlide($slide); + $this->assertSame([['collect', 'discuss'], 0], [$results['stages'], $results['maxUpvotes']]); + $this->assertSame(['Frage A', 'Frage B'], array_column($results['questions'], 'text')); + $this->assertSame(0, (new PollStateService())->forParticipant($poll, 'p1')['qa']['maxUpvotes']); + } + + public function testUpvotesPerQuestionAreLimited(): void + { + [$poll] = $this->createPoll(); + $slide = $this->createSlide($poll, Slide::TYPE_QA, ['settings' => ['max_upvotes' => 3, 'max_upvotes_per_question' => 1]]); + $poll = $this->goLive($poll, $slide); + $a = $this->ask($poll, $slide, 'p1', 'Frage A'); + $b = $this->ask($poll, $slide, 'p1', 'Frage B'); + $slide = $this->stage($slide, Slide::QA_VOTE); + + $this->vote($poll, $slide, 'p2', $a); + $this->assertVoteFails('Du kannst jeder Frage nur eine Stimme geben.', fn() => $this->vote($poll, $slide, 'p2', $a)); + $this->vote($poll, $slide, 'p2', $b); + // Withdrawing frees the question again. + $this->vote($poll, $slide, 'p2', $a, 'remove'); + $this->vote($poll, $slide, 'p2', $a); + + $state = (new PollStateService())->forParticipant($poll, 'p2')['qa']; + $this->assertEquals([1, 1, [$a => 1, $b => 1]], [$state['maxPerQuestion'], $state['votesLeft'], $state['upvoted']]); + + $this->slidesTable()->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => 3, 'max_upvotes_per_question' => 2]]); + $this->slidesTable()->saveOrFail($slide); + $this->vote($poll, $slide, 'p2', $a); + $this->vote($poll, $slide, 'p3', $b); + $this->vote($poll, $slide, 'p3', $b); + $this->assertVoteFails('Du kannst jeder Frage höchstens 2 Stimmen geben.', fn() => $this->vote($poll, $slide, 'p3', $b)); } public function testCollectQuestionsSeveralPerParticipantWithoutDuplicates(): void diff --git a/webroot/js/plenario.js b/webroot/js/plenario.js index 92afd52..b649977 100644 --- a/webroot/js/plenario.js +++ b/webroot/js/plenario.js @@ -743,9 +743,13 @@ var onQuestion = options && options.onQuestion; var questions = results.questions; var maxVotes = Math.max.apply(null, questions.map(function (q) { return q.votes; }).concat([1])); - var children = [Qa.steps(results.stage, onStage)]; + var children = [Qa.steps(results.stage, onStage, results.stages)]; + var withVotes = results.maxUpvotes > 0; function votes(question) { + if (!withVotes) { + return null; + } return el('span', { class: 'qa-votes', 'aria-label': question.votes + (question.votes === 1 ? ' Stimme' : ' Stimmen'), @@ -763,6 +767,7 @@ } else if (results.stage === 'vote') { children.push(el('p', { class: 'qa-summary', text: 'Abstimmen: jede Person hat ' + results.maxUpvotes + (results.maxUpvotes === 1 ? ' Stimme' : ' Stimmen') + + (results.maxPerQuestion < results.maxUpvotes ? ' (höchstens ' + results.maxPerQuestion + ' pro Frage)' : '') + ' · bisher ' + results.upvotes + ' vergeben' })); children.push(el('ol', { class: 'qa-list' }, questions.map(function (question) { return el('li', { class: 'qa-item' }, [ @@ -819,9 +824,9 @@ var Qa = { labels: { collect: 'Fragen sammeln', vote: 'Abstimmen', discuss: 'Besprechen' }, - /** Stepper of the three stages; clickable for the presenter (onStage). */ - steps: function (stage, onStage) { - return el('ol', { class: 'qa-steps', 'aria-label': 'Ablauf' }, ['collect', 'vote', 'discuss'].map(function (key, i) { + /** Stepper of the stages (without upvotes there is no voting stage); clickable for the presenter (onStage). */ + steps: function (stage, onStage, stages) { + return el('ol', { class: 'qa-steps', 'aria-label': 'Ablauf' }, (stages || ['collect', 'vote', 'discuss']).map(function (key, i) { var current = key === stage; var label = (i + 1) + ' ' + Qa.labels[key]; var item = onStage @@ -1430,7 +1435,7 @@ 'aria-label': given === 0 ? 'keine Stimme von dir' : given + (given === 1 ? ' Stimme' : ' Stimmen') + ' von dir', text: '▲ ' + given }), - button('up', '+', 'Stimme geben', qa.votesLeft === 0) + button('up', '+', 'Stimme geben', qa.votesLeft === 0 || given >= qa.maxPerQuestion) ]); } return el('li', { class: 'qa-item' + (mine ? ' is-mine' : '') + (given > 0 ? ' is-upvoted' : '') }, [ @@ -1463,7 +1468,9 @@ } return el('li', attrs, [ el('span', { class: 'qa-item__text', text: (i < index ? '✓ ' : '') + question.text + (mine ? ' (deine Frage)' : '') }), - el('span', { class: 'qa-votes', 'aria-label': question.votes + (question.votes === 1 ? ' Stimme' : ' Stimmen'), text: '▲ ' + question.votes }) + qa.maxUpvotes > 0 + ? el('span', { class: 'qa-votes', 'aria-label': question.votes + (question.votes === 1 ? ' Stimme' : ' Stimmen'), text: '▲ ' + question.votes }) + : null ]); }))); }
#
#
.