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

+34 -10
View File
@@ -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<int>
*/
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;
}
/**