diff --git a/AGENTS.md b/AGENTS.md index bd5f501..7ea68bc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -158,15 +158,17 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures der Presenter schaltet manuell weiter (V bzw. Stepper, auch zurück). `collect`: Fragen einreichen (max. `VoteService::MAX_QA_QUESTIONS` pro Person, gleiche Frage nur einmal pro Folie), Teilnehmende sehen alle bisherigen Fragen (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, + `vote`: Upvotes auf fremde Fragen, Budget pro Person = Anteil der Fragen (Setting `upvote_share` in Prozent, `Slide::QA_UPVOTE_SHARES`, aufgerundet, mindestens 1: + `Slide::qaBudget(Anzahl Fragen)`; im State/JSON `maxUpvotes`), wächst also mit der Fragenzahl, 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` + Setting `max_upvotes_per_question` begrenzt die eigenen Stimmen je Frage (0 = nur durch das Budget begrenzt, + effektiv `Slide::qaUpvotesPerQuestion($budget)`, State `maxPerQuestion`). `upvote_share = 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; auch die Bühne (Presenter/Embed, PDF) bekommt in `vote` + Teilnehmende sehen alle Fragen in Eingangsreihenfolge **ohne** Zählung; die Bühne (Presenter/Embed) zeigt in `vote` keine Fragen, + sondern nur den Hinweis „Schau auf dein Gerät und stimme ab“ mit Fragenzahl, Budget und vergebener Gesamtsumme (`Results.qa`); auch sonst gibt es dort keine Zählungen je Frage und keine Rangfolge (`ResultsService::qa()`, nur die Summe `upvotes`), damit niemand beeinflusst wird. `discuss`: Abstimmung zu, Fragen nach Upvotes sortiert (Gleichstand: älteste zuerst), `focus_response_id` = aktuelle Frage. In `discuss` blättern next/prev (→/←, Klicker) zuerst durch die Fragen, erst danach durch die Folien. Fokuswechsel per `updateAll` ohne `modified`, diff --git a/config/Migrations/20261111160000_ConvertQaUpvotesToShare.php b/config/Migrations/20261111160000_ConvertQaUpvotesToShare.php new file mode 100644 index 0000000..507f21b --- /dev/null +++ b/config/Migrations/20261111160000_ConvertQaUpvotesToShare.php @@ -0,0 +1,38 @@ +fetchAll("SELECT id, settings FROM slides WHERE type = 'qa'"); + foreach ($rows as $row) { + $settings = json_decode((string)$row['settings'], true); + if (!is_array($settings) || !array_key_exists('max_upvotes', $settings)) { + continue; + } + $settings['upvote_share'] = (int)$settings['max_upvotes'] === 0 ? 0 : 25; + unset($settings['max_upvotes']); + $this->getAdapter()->execute( + 'UPDATE slides SET settings = ? WHERE id = ?', + [json_encode($settings, JSON_UNESCAPED_UNICODE), $row['id']], + ); + } + } + + /** + * @return void + */ + public function down(): void + { + } +} diff --git a/src/Model/Entity/Slide.php b/src/Model/Entity/Slide.php index 1d1e5fc..1bf2276 100644 --- a/src/Model/Entity/Slide.php +++ b/src/Model/Entity/Slide.php @@ -84,10 +84,17 @@ class Slide extends Entity public const QA_STAGES = [self::QA_COLLECT, self::QA_VOTE, self::QA_DISCUSS]; /** - * Highest selectable number of upvotes per participant on a Q&A slide. + * Highest selectable number of upvotes one participant may give a single question. */ public const QA_MAX_UPVOTES = 10; + /** + * Selectable shares (percent of the questions) that make up each participant's upvote budget. + * + * @var list + */ + public const QA_UPVOTE_SHARES = [10, 20, 25, 33, 50]; + /** * Default settings per type. Unknown keys are dropped on save. * @@ -117,10 +124,11 @@ 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], - // 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); + // upvote_share: percent of the questions each participant may upvote in the voting stage, so the + // budget grows with the number of questions (qaBudget(); 0 = no voting stage, else QA_UPVOTE_SHARES); + // max_upvotes_per_question: own upvotes per question (0 = no limit besides the budget); // allow_self_upvote: upvotes on own questions (for prioritizing topics, off by default) - self::TYPE_QA => ['max_upvotes' => 3, 'max_upvotes_per_question' => 0, 'allow_self_upvote' => false], + self::TYPE_QA => ['upvote_share' => 25, '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 => [], ]; @@ -331,13 +339,13 @@ class Slide extends Entity } /** - * Whether a Q&A slide has a voting stage (setting `max_upvotes` > 0). + * Whether a Q&A slide has a voting stage (setting `upvote_share` > 0). * * @return bool */ public function hasQaUpvotes(): bool { - return (int)$this->setting('max_upvotes') > 0; + return (int)$this->setting('upvote_share') > 0; } /** @@ -351,16 +359,32 @@ class Slide extends Entity } /** - * Upvotes one participant may give a single Q&A question (never more than `max_upvotes`). + * Upvotes each participant gets in the voting stage: `upvote_share` percent of the questions, + * rounded up and at least one (0 without questions or without a voting stage). * + * @param int $questionCount Number of questions on the slide * @return int */ - public function qaUpvotesPerQuestion(): int + public function qaBudget(int $questionCount): int + { + if ($questionCount <= 0 || !$this->hasQaUpvotes()) { + return 0; + } + + return max(1, (int)ceil($questionCount * (int)$this->setting('upvote_share') / 100)); + } + + /** + * Upvotes one participant may give a single Q&A question (never more than the budget). + * + * @param int $budget Upvotes per participant, see qaBudget() + * @return int + */ + public function qaUpvotesPerQuestion(int $budget): int { - $max = (int)$this->setting('max_upvotes'); $perQuestion = (int)$this->setting('max_upvotes_per_question'); - return $perQuestion > 0 ? min($perQuestion, $max) : $max; + return $perQuestion > 0 ? min($perQuestion, $budget) : $budget; } /** diff --git a/src/Model/Table/SlidesTable.php b/src/Model/Table/SlidesTable.php index 3a7e92c..6dde09e 100644 --- a/src/Model/Table/SlidesTable.php +++ b/src/Model/Table/SlidesTable.php @@ -173,9 +173,11 @@ class SlidesTable extends Table } break; case Slide::TYPE_QA: - $max = (int)($input['max_upvotes'] ?? $settings['max_upvotes']); + $share = (int)($input['upvote_share'] ?? $settings['upvote_share']); // 0 = no upvotes (no voting stage) - $settings['max_upvotes'] = max(0, min(Slide::QA_MAX_UPVOTES, $max)); + $settings['upvote_share'] = $share === 0 || in_array($share, Slide::QA_UPVOTE_SHARES, true) + ? $share + : Slide::DEFAULT_SETTINGS[Slide::TYPE_QA]['upvote_share']; $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)); diff --git a/src/Service/PollStateService.php b/src/Service/PollStateService.php index 55eb5a6..1669191 100644 --- a/src/Service/PollStateService.php +++ b/src/Service/PollStateService.php @@ -283,7 +283,7 @@ 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. + * `maxUpvotes` = upvote budget of the participant (share of the questions), 0: no voting stage; `maxPerQuestion` = own upvotes allowed per question. * * @param \App\Model\Entity\Slide $slide Q&A slide * @param string $participantHash Participant hash @@ -294,8 +294,8 @@ class PollStateService { $stage = $slide->qaStage(); $own = $this->Responses->qaVotesOf($slide->id, $participantHash); - $max = (int)$slide->setting('max_upvotes'); $questions = (new QaService())->rankedQuestions($slide); + $max = $slide->qaBudget(count($questions)); if ($stage === Slide::QA_DISCUSS) { $focusId = in_array($slide->focus_response_id, array_column($questions, 'id'), true) ? $slide->focus_response_id @@ -309,7 +309,7 @@ class PollStateService return [ 'stage' => $stage, 'maxUpvotes' => $max, - 'maxPerQuestion' => $slide->qaUpvotesPerQuestion(), + 'maxPerQuestion' => $slide->qaUpvotesPerQuestion($max), '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 188d98a..bc401f4 100644 --- a/src/Service/QaService.php +++ b/src/Service/QaService.php @@ -15,8 +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 and `max_upvotes_per_question` per question (voting open). - * Skipped with `max_upvotes` = 0 (Slide::qaStages()). + * a budget of `upvote_share` percent of the questions each and `max_upvotes_per_question` per question (voting open). + * Skipped with `upvote_share` = 0 (Slide::qaStages()). * - discuss: voting closed; the presenter steps through the questions, most upvoted * first (`slides.focus_response_id` = question on screen) * diff --git a/src/Service/ResultsService.php b/src/Service/ResultsService.php index f383458..b25cba2 100644 --- a/src/Service/ResultsService.php +++ b/src/Service/ResultsService.php @@ -217,6 +217,7 @@ class ResultsService { $questions = (new QaService())->rankedQuestions($slide); $upvotes = array_sum(array_column($questions, 'votes')); + $budget = $slide->qaBudget(count($questions)); if ($slide->qaStage() === Slide::QA_VOTE) { // A live ranking on the stage would sway the vote: submission order, no counts until voting ends. usort($questions, fn($a, $b) => $a['id'] <=> $b['id']); @@ -232,8 +233,8 @@ class ResultsService return [ 'stage' => $slide->qaStage(), 'stages' => $slide->qaStages(), - 'maxUpvotes' => (int)$slide->setting('max_upvotes'), - 'maxPerQuestion' => $slide->qaUpvotesPerQuestion(), + 'maxUpvotes' => $budget, + 'maxPerQuestion' => $slide->qaUpvotesPerQuestion($budget), 'upvotes' => $upvotes, 'questions' => $questions, 'focusId' => $focusIndex === null ? null : $slide->focus_response_id, diff --git a/src/Service/VoteService.php b/src/Service/VoteService.php index 6076b78..0b0f71b 100644 --- a/src/Service/VoteService.php +++ b/src/Service/VoteService.php @@ -32,8 +32,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, - * at most `max_upvotes_per_question` if set; `max_upvotes` = 0 means no voting stage); + * a budget of `upvote_share` percent of the questions in total, freely distributed (several on one question are allowed, + * at most `max_upvotes_per_question` if set; `upvote_share` = 0 means no voting stage); * `remove` withdraws one own upvote of the question. `vote=edit|delete` + `question_id` * changes or deletes an own question, only while collecting (see editQuestion()). * - ordering: `order` = all option ids, each exactly once, in the participant's order. @@ -404,8 +404,8 @@ class VoteService } // 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(); + $max = $slide->qaBudget($this->Responses->questionsOf($slide->id)->count()); + $perQuestion = $slide->qaUpvotesPerQuestion($max); if ($perQuestion < $max && count(array_keys($own['upvotes'], $id, true)) >= $perQuestion) { throw new VoteException(__n( 'Du kannst jeder Frage nur eine Stimme geben.', diff --git a/templates/Admin/index.php b/templates/Admin/index.php index 1dccab9..85f3739 100644 --- a/templates/Admin/index.php +++ b/templates/Admin/index.php @@ -99,9 +99,8 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide- 'vote' => __('Abstimmung läuft'), 'discuss' => __('Fragen werden besprochen'), ][$slide->qaStage()]) ?> · hasQaUpvotes()) : ?>setting('max_upvotes'); - $perQuestion = $slide->qaUpvotesPerQuestion(); ?> - setting('allow_self_upvote') ? ' · ' . __('auch für eigene Fragen') : '' ?> + $perQuestion = (int)$slide->setting('max_upvotes_per_question'); ?> + setting('upvote_share')) ?> 0 ? ' · ' . __n('{0} pro Frage', '{0} pro Frage', $perQuestion, $perQuestion) : '' ?>setting('allow_self_upvote') ? ' · ' . __('auch für eigene Fragen') : '' ?> isOrder() && !$slide->is_voting_open) : ?> · diff --git a/templates/Slides/form.php b/templates/Slides/form.php index 3924b2b..8c43533 100644 --- a/templates/Slides/form.php +++ b/templates/Slides/form.php @@ -301,14 +301,20 @@ $optionsError = $slide->getError('options_text'); $upvoteOptions[$n] = __n('{0} Stimme', '{0} Stimmen', $n, $n); } ?> - Form->control('settings.max_upvotes', [ + + Form->control('settings.upvote_share', [ 'type' => 'select', - 'options' => [0 => __('keine – ohne Abstimmung')] + $upvoteOptions, - 'label' => __('Upvotes (Stimmen) pro Person'), - 'value' => $settings['max_upvotes'], + 'options' => [0 => __('keine – ohne Abstimmung')] + $shareOptions, + 'label' => __('Stimmen pro Person'), + 'value' => $settings['upvote_share'], 'aria-describedby' => 'qa-upvotes-hint', ]) ?> -

+

Form->control('settings.max_upvotes_per_question', [ 'type' => 'select', 'options' => [0 => __('unbegrenzt (bis alle Stimmen vergeben sind)')] + $upvoteOptions, diff --git a/tests/TestCase/Controller/QaSlideTest.php b/tests/TestCase/Controller/QaSlideTest.php index 73f9b21..df9e72d 100644 --- a/tests/TestCase/Controller/QaSlideTest.php +++ b/tests/TestCase/Controller/QaSlideTest.php @@ -61,29 +61,29 @@ class QaSlideTest extends TestCase [$poll, $token] = $this->createPoll(); $this->get("/admin/$token/slides/add?type=qa"); $this->assertResponseOk(); - $this->assertResponseContains('Upvotes (Stimmen) pro Person'); + $this->assertResponseContains('Stimmen pro Person'); $this->assertResponseNotContains('Abstimmung geöffnet'); $this->post("/admin/$token/slides/add?type=qa", [ 'type' => 'qa', 'question' => 'Eure Fragen an den Vorstand', - 'settings' => ['max_upvotes' => '5'], + 'settings' => ['upvote_share' => '25'], ]); $this->assertRedirect(); $slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail(); - $this->assertSame([Slide::TYPE_QA, 5, Slide::QA_COLLECT, true], [ - $slide->type, $slide->setting('max_upvotes'), $slide->stage, $slide->is_voting_open, + $this->assertSame([Slide::TYPE_QA, 25, Slide::QA_COLLECT, true], [ + $slide->type, $slide->setting('upvote_share'), $slide->stage, $slide->is_voting_open, ]); $this->get("/admin/$token"); $this->assertResponseContains('Fragen sammeln'); - $this->assertResponseContains('max. 5 Upvotes pro Person'); + $this->assertResponseContains('Stimmen für 25 % der Fragen pro Person'); } public function testSwitchingOffUpvotesSkipsTheVotingStage(): void { [$poll, $token] = $this->createPoll(); - $slide = $this->createSlide($poll, Slide::TYPE_QA, ['settings' => ['max_upvotes' => 2]]); + $slide = $this->createSlide($poll, Slide::TYPE_QA, ['settings' => ['upvote_share' => 50]]); $this->goLive($poll, $slide); (new QaService())->setStage($slide, Slide::QA_VOTE); @@ -94,11 +94,11 @@ class QaSlideTest extends TestCase // 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'], + 'settings' => ['upvote_share' => '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->assertSame([0, Slide::QA_DISCUSS, false], [$slide->setting('upvote_share'), $slide->qaStage(), $slide->is_voting_open]); $this->get("/admin/$token"); $this->assertResponseContains('ohne Upvotes'); @@ -115,7 +115,7 @@ class QaSlideTest extends TestCase public function testFullRoundTrip(): void { [$poll, $token] = $this->createPoll(); - $slide = $this->createSlide($poll, Slide::TYPE_QA, ['settings' => ['max_upvotes' => 1]]); + $slide = $this->createSlide($poll, Slide::TYPE_QA, ['settings' => ['upvote_share' => 50]]); $next = $this->createSlide($poll, Slide::TYPE_CONTENT); $this->goLive($poll, $slide); $code = $poll->join_code; diff --git a/tests/TestCase/Service/QaTest.php b/tests/TestCase/Service/QaTest.php index e805027..1a654f2 100644 --- a/tests/TestCase/Service/QaTest.php +++ b/tests/TestCase/Service/QaTest.php @@ -29,10 +29,10 @@ class QaTest extends TestCase /** * @return array{0: \App\Model\Entity\Poll, 1: \App\Model\Entity\Slide} */ - protected function createQa(int $maxUpvotes = 2): array + protected function createQa(int $share = 50): array { [$poll] = $this->createPoll(); - $slide = $this->createSlide($poll, Slide::TYPE_QA, ['settings' => ['max_upvotes' => $maxUpvotes]]); + $slide = $this->createSlide($poll, Slide::TYPE_QA, ['settings' => ['upvote_share' => $share]]); return [$this->goLive($poll, $slide), $slide]; } @@ -70,25 +70,35 @@ class QaTest extends TestCase } } - public function testSanitizesMaxUpvotes(): void + public function testSanitizesUpvoteShare(): void { [, $slide] = $this->createQa(); - $this->assertSame(2, $slide->setting('max_upvotes')); + $this->assertSame(50, $slide->setting('upvote_share')); $this->assertSame(Slide::QA_COLLECT, $slide->qaStage()); $table = $this->slidesTable(); - $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')); + $share = fn(string $value) => $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['upvote_share' => $value]])->setting('upvote_share'); + $this->assertSame(0, $share('0')); + $this->assertSame(33, $share('33')); + $this->assertSame(25, $share('-3'), 'invalid values fall back to the default'); + $this->assertSame(25, $share('99')); + } + public function testBudgetGrowsWithTheNumberOfQuestions(): void + { + [, $slide] = $this->createQa(25); + $this->assertSame([0, 1, 1, 1, 2, 3, 25], array_map($slide->qaBudget(...), [0, 1, 4, 3, 5, 12, 100])); + [, $off] = $this->createQa(0); + $this->assertSame(0, $off->qaBudget(10)); + + $table = $this->slidesTable(); $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']]); + $patched = $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['upvote_share' => '25', 'max_upvotes_per_question' => '2']]); + $this->assertSame([2, 2, 1], [$patched->setting('max_upvotes_per_question'), $patched->qaUpvotesPerQuestion(5), $patched->qaUpvotesPerQuestion(1)]); + $patched = $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['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'); + $this->assertSame([10, 3], [$patched->setting('max_upvotes_per_question'), $patched->qaUpvotesPerQuestion(3)]); + $this->assertSame(4, $slide->qaUpvotesPerQuestion(4), '0 = no limit per question'); } public function testWithoutUpvotesThereIsNoVotingStage(): void @@ -122,10 +132,14 @@ class QaTest extends TestCase public function testUpvotesPerQuestionAreLimited(): void { [$poll] = $this->createPoll(); - $slide = $this->createSlide($poll, Slide::TYPE_QA, ['settings' => ['max_upvotes' => 3, 'max_upvotes_per_question' => 1]]); + $slide = $this->createSlide($poll, Slide::TYPE_QA, ['settings' => ['upvote_share' => 50, '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'); + // Six questions at 50 % make a budget of three votes. + foreach (['C', 'D', 'E', 'F'] as $letter) { + $this->ask($poll, $slide, 'p1', 'Frage ' . $letter); + } $slide = $this->stage($slide, Slide::QA_VOTE); $this->vote($poll, $slide, 'p2', $a); @@ -138,7 +152,7 @@ class QaTest extends TestCase $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()->patchEntity($slide, ['type' => 'qa', 'settings' => ['upvote_share' => 50, 'max_upvotes_per_question' => 2]]); $this->slidesTable()->saveOrFail($slide); $this->vote($poll, $slide, 'p2', $a); $this->vote($poll, $slide, 'p3', $b); @@ -180,10 +194,12 @@ class QaTest extends TestCase public function testUpvotesAreABudgetThatCanBeStackedAndWithdrawn(): void { - [$poll, $slide] = $this->createQa(3); + [$poll, $slide] = $this->createQa(50); $a = $this->ask($poll, $slide, 'p1', 'Frage A'); $b = $this->ask($poll, $slide, 'p2', 'Frage B'); $c = $this->ask($poll, $slide, 'p2', 'Frage C'); + // Six questions at 50 % make a budget of three votes. + $rest = array_map(fn(string $x) => $this->ask($poll, $slide, 'p9', 'Frage ' . $x), ['D', 'E', 'F']); $slide = $this->stage($slide, Slide::QA_VOTE); $this->assertTrue($slide->isVotingOpen()); @@ -205,11 +221,11 @@ class QaTest extends TestCase // While voting is open, the stage only gets the total: no ranking, no counts per question. $results = (new ResultsService())->forSlide($slide); - $this->assertSame([$a, $b, $c], array_column($results['questions'], 'id')); + $this->assertSame([$a, $b, $c, ...$rest], array_column($results['questions'], 'id')); $this->assertArrayNotHasKey('votes', $results['questions'][0]); $this->assertSame(4, $results['upvotes']); $ranked = (new QaService())->rankedQuestions($slide); - $this->assertSame([[$b, 3], [$a, 1], [$c, 0]], array_map(fn($q) => [$q['id'], $q['votes']], $ranked)); + $this->assertSame([[$b, 3], [$a, 1], [$c, 0], [$rest[0], 0], [$rest[1], 0], [$rest[2], 0]], array_map(fn($q) => [$q['id'], $q['votes']], $ranked)); $this->vote($poll, $slide, 'p3', $b, 'remove'); $this->assertSame(2, (new QaService())->rankedQuestions($slide)[0]['votes'], 'remove withdraws only one upvote'); @@ -217,7 +233,7 @@ class QaTest extends TestCase // Voting view of participants: all questions, submission order, no counts. $state = (new PollStateService())->forParticipant($poll, 'p3'); - $this->assertSame([$a, $b, $c], array_column($state['qa']['questions'], 'id')); + $this->assertSame([$a, $b, $c, ...$rest], array_column($state['qa']['questions'], 'id')); $this->assertArrayNotHasKey('votes', $state['qa']['questions'][0]); $this->assertSame([$b => 2, $a => 1], $state['qa']['upvoted']); $this->assertSame(0, $state['qa']['votesLeft']); @@ -231,13 +247,17 @@ class QaTest extends TestCase $this->assertFalse($slide->setting('allow_self_upvote')); $table = $this->slidesTable(); $this->assertTrue($table->patchEntity($slide, ['type' => 'qa', 'settings' => ['allow_self_upvote' => '1']])->setting('allow_self_upvote')); - $this->assertFalse($table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '2']])->setting('allow_self_upvote')); + $this->assertFalse($table->patchEntity($slide, ['type' => 'qa', 'settings' => ['upvote_share' => '20']])->setting('allow_self_upvote')); [$poll] = $this->createPoll(); - $slide = $this->createSlide($poll, Slide::TYPE_QA, ['settings' => ['max_upvotes' => 3, 'allow_self_upvote' => true]]); + $slide = $this->createSlide($poll, Slide::TYPE_QA, ['settings' => ['upvote_share' => 25, 'allow_self_upvote' => true]]); $poll = $this->goLive($poll, $slide); $a = $this->ask($poll, $slide, 'p1', 'Thema A'); $b = $this->ask($poll, $slide, 'p2', 'Thema B'); + // Twelve questions at 25 % make a budget of three votes. + for ($i = 1; $i <= 10; $i++) { + $this->ask($poll, $slide, 'p3', 'Thema ' . $i); + } $slide = $this->stage($slide, Slide::QA_VOTE); // Own questions take votes from the same budget, stacked and withdrawn like any other. @@ -255,7 +275,7 @@ class QaTest extends TestCase public function testDiscussStepsThroughQuestionsByRank(): void { - [$poll, $slide] = $this->createQa(3); + [$poll, $slide] = $this->createQa(50); $a = $this->ask($poll, $slide, 'p1', 'Frage A'); $b = $this->ask($poll, $slide, 'p1', 'Frage B'); $slide = $this->stage($slide, Slide::QA_VOTE); diff --git a/webroot/css/plenario.css b/webroot/css/plenario.css index 9236a6b..a5eac07 100644 --- a/webroot/css/plenario.css +++ b/webroot/css/plenario.css @@ -573,6 +573,9 @@ textarea { resize: vertical; } .qa-focus__nav:empty { display: none; } .qa-list--compact .qa-item { padding: 8px 12px; } .qa-summary { color: var(--muted); margin: 0 0 1em; } +.qa-vote-hint { text-align: center; padding: 8vh 16px 4vh; } +.qa-vote-hint__title { margin: 0 0 .3em; font-size: clamp(2rem, 6vw, 3.5rem); font-weight: 800; color: var(--qa); } +.qa-vote-hint__text { margin: 0 auto 1.2em; max-width: 30em; font-size: clamp(1.1rem, 2.6vw, 1.6rem); } .qa-steps { list-style: none; padding: 0; margin: 0 0 1em; display: flex; flex-wrap: wrap; gap: 6px; counter-reset: none; } .qa-steps__step { display: inline-block; padding: 4px 12px; border-radius: 99px; border: 1px solid var(--border); background: transparent; color: var(--muted); font: inherit; font-size: .85em; } button.qa-steps__step { cursor: pointer; } diff --git a/webroot/js/plenario.js b/webroot/js/plenario.js index 9a2ba92..2fb00cf 100644 --- a/webroot/js/plenario.js +++ b/webroot/js/plenario.js @@ -1026,16 +1026,16 @@ return el('li', { class: 'answer', text: question.text }); }))); } 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' })); - // No counts or ranking while voting is open (the server sends none), so the stage does not sway the vote. - children.push(el('ul', { class: 'qa-list' }, questions.map(function (question) { - return el('li', { class: 'qa-item' }, [ - el('span', { class: 'qa-item__text', text: question.text }) - ]); - }))); + // The questions are voted on at the participants' devices: the stage only points there + // (no list, counts or ranking, so it can not sway the vote). + children.push(el('div', { class: 'qa-vote-hint' }, [ + el('p', { class: 'qa-vote-hint__title', text: 'Jetzt abstimmen!' }), + el('p', { class: 'qa-vote-hint__text', text: 'Schau auf dein Gerät und gib deine Stimmen den Fragen, die dir wichtig sind.' }), + el('p', { class: 'qa-summary', text: questions.length + (questions.length === 1 ? ' Frage' : ' Fragen') + + ' · jede Person hat ' + results.maxUpvotes + (results.maxUpvotes === 1 ? ' Stimme' : ' Stimmen') + + (results.maxPerQuestion < results.maxUpvotes ? ' (höchstens ' + results.maxPerQuestion + ' pro Frage)' : '') + + ' · bisher ' + results.upvotes + ' vergeben' }) + ])); } else if (questions.length === 0) { children.push(el('p', { class: 'qa-summary', text: 'Es wurden keine Fragen eingereicht.' })); } else {