Make Q&A upvote budget a share of the questions
CI / Deploy / test (push) Successful in 58s
CI / Deploy / deploy (push) Skipped

The fixed number of votes per person does not fit varying question
counts. The budget is now `upvote_share` percent of the questions
(rounded up, at least one), so it grows with the number of questions.
A migration converts existing Q&A slides (no voting stays off, others
get 25 %).

On the stage the voting step no longer lists the questions but points
participants to their devices.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-11 23:53:32 +01:00
1 parent 3762b880cb
commit 575fb8649d
14 files changed
+171 -76

No files matched your search

+9 -9
View File
@@ -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;
+42 -22
View File
@@ -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);