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

+3 -3
View File
@@ -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'],
+2 -2
View File
@@ -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)
*
+3 -2
View File
@@ -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,
+4 -4
View File
@@ -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.',