Allow upvoting own Q&A questions as an opt-in setting
The new Q&A setting allow_self_upvote (off by default) lets participants spend their upvote budget on their own questions, e.g. for prioritizing topics. Without it, participants now see a short hint why their own questions cannot be upvoted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ec0b13cae8
commit
affc9a5ece
10 files changed
+59
-12
No files matched your search
@@ -104,8 +104,9 @@ 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],
|
||||
// upvotes per participant in the voting stage (1..QA_MAX_UPVOTES)
|
||||
self::TYPE_QA => ['max_upvotes' => 3],
|
||||
// upvotes per participant in the voting stage (1..QA_MAX_UPVOTES);
|
||||
// allow_self_upvote: upvotes on own questions (for prioritizing topics, off by default)
|
||||
self::TYPE_QA => ['max_upvotes' => 3, 'allow_self_upvote' => false],
|
||||
// The correct order is the order of the slide_options (position), revealed when voting closes.
|
||||
self::TYPE_ORDER => [],
|
||||
];
|
||||
|
||||
@@ -173,6 +173,7 @@ class SlidesTable extends Table
|
||||
case Slide::TYPE_QA:
|
||||
$max = (int)($input['max_upvotes'] ?? $settings['max_upvotes']);
|
||||
$settings['max_upvotes'] = max(1, min(Slide::QA_MAX_UPVOTES, $max));
|
||||
$settings['allow_self_upvote'] = filter_var($input['allow_self_upvote'] ?? false, FILTER_VALIDATE_BOOLEAN);
|
||||
break;
|
||||
case Slide::TYPE_YOUTUBE:
|
||||
$url = mb_substr(trim((string)($input['url'] ?? '')), 0, 500);
|
||||
|
||||
@@ -284,11 +284,12 @@ class PollStateService
|
||||
* - collect: all questions so far in submission order (helps to avoid duplicates), `mine` marks own ones
|
||||
* - vote: all questions in submission order, without counts (no bandwagon effect)
|
||||
* - discuss: all questions ranked with upvotes, `focusId` = question being discussed
|
||||
* `upvoted` = own upvotes per question id (several per question are allowed).
|
||||
* `upvoted` = own upvotes per question id (several per question are allowed),
|
||||
* `allowSelfUpvote` = own questions may be upvoted too (setting `allow_self_upvote`).
|
||||
*
|
||||
* @param \App\Model\Entity\Slide $slide Q&A slide
|
||||
* @param string $participantHash Participant hash
|
||||
* @return array{stage: string, maxUpvotes: int, votesLeft: int, mine: list<int>, upvoted: array<int, int>,
|
||||
* @return array{stage: string, maxUpvotes: 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
|
||||
@@ -311,6 +312,7 @@ class PollStateService
|
||||
'stage' => $stage,
|
||||
'maxUpvotes' => $max,
|
||||
'votesLeft' => max(0, $max - count($own['upvotes'])),
|
||||
'allowSelfUpvote' => (bool)$slide->setting('allow_self_upvote'),
|
||||
'mine' => $own['questions'],
|
||||
'upvoted' => array_count_values($own['upvotes']),
|
||||
'questions' => array_values($questions),
|
||||
|
||||
@@ -14,7 +14,8 @@ use InvalidArgumentException;
|
||||
*
|
||||
* Stages (Slide::qaStage()):
|
||||
* - collect: participants submit questions (voting open)
|
||||
* - vote: participants upvote questions of others, at most `max_upvotes` each (voting open)
|
||||
* - vote: participants upvote questions of others (own ones with `allow_self_upvote`),
|
||||
* at most `max_upvotes` each (voting open)
|
||||
* - discuss: voting closed; the presenter steps through the questions, most upvoted
|
||||
* first (`slides.focus_response_id` = question on screen)
|
||||
*
|
||||
|
||||
@@ -26,8 +26,9 @@ use Cake\Utility\Security;
|
||||
* - Q&A (see QaService for the stages): `question` (text) only while collecting,
|
||||
* 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, at most `max_upvotes` in total, freely distributed (several
|
||||
* on one question are allowed); `remove` withdraws one own upvote of the question.
|
||||
* 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);
|
||||
* `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()).
|
||||
*/
|
||||
@@ -270,7 +271,7 @@ class VoteService
|
||||
if ($vote !== 'up') {
|
||||
throw new VoteException(__('Ungültige Stimme.'));
|
||||
}
|
||||
if (in_array($id, $own['questions'], true)) {
|
||||
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).
|
||||
|
||||
Reference in new issue
Block a user