Allow Q&A rounds without upvotes and limit upvotes per question
CI / Deploy / test (push) Successful in 57s
CI / Deploy / deploy (push) Skipped

- 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 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-09 08:36:02 +01:00
1 parent 3e44ded107
commit bc86ec2db6
16 files changed
+235 -38

No files matched your search

+3 -1
View File
@@ -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<int>, upvoted: array<int, int>,
* @return array{stage: string, maxUpvotes: int, maxPerQuestion: int, votesLeft: int, allowSelfUpvote: bool, mine: list<int>, upvoted: array<int, int>,
* questions: list<array{id: int, text: string, votes?: int}>, 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'],
+10 -8
View File
@@ -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;
}
+5 -1
View File
@@ -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,
+1 -1
View File
@@ -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);
+16 -2
View File
@@ -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.',