diff --git a/AGENTS.md b/AGENTS.md index 65c6162..04900b9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -136,7 +136,9 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures `VoteService::MAX_QA_QUESTIONS` pro Person, gleiche Frage nur einmal pro Folie), Teilnehmende sehen alle bisherigen Fragen (gegen Dubletten, eigene markiert), aber noch keine Upvotes. `vote`: Upvotes auf fremde Fragen, Budget = Setting `max_upvotes` pro Person, frei verteilbar (auch mehrere auf eine Frage, - je Upvote eine Zeile), `vote=remove` nimmt eine Stimme der Frage zurück; im State `qa.upvoted` = {Frage-id: eigene Stimmen}; + je Upvote eine Zeile), `vote=remove` nimmt eine Stimme der Frage zurück; im State `qa.upvoted` = {Frage-id: eigene Stimmen}. + Setting `allow_self_upvote` (Standard aus, für Themen-Priorisierung) erlaubt Stimmen auf eigene Fragen aus demselben Budget + (State `qa.allowSelfUpvote`); bewusst aus, weil anonym sonst Selbstvermarktung die Rangfolge bestimmt; Teilnehmende sehen alle Fragen in Eingangsreihenfolge **ohne** Zählung. `discuss`: Abstimmung zu, Fragen nach Upvotes sortiert (Gleichstand: älteste zuerst), `focus_response_id` = aktuelle Frage. In `discuss` blättern next/prev (→/←, Klicker) zuerst durch die Fragen, erst danach durch die Folien. Fokuswechsel per `updateAll` ohne `modified`, diff --git a/src/Model/Entity/Slide.php b/src/Model/Entity/Slide.php index 2112a19..fae229f 100644 --- a/src/Model/Entity/Slide.php +++ b/src/Model/Entity/Slide.php @@ -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 => [], ]; diff --git a/src/Model/Table/SlidesTable.php b/src/Model/Table/SlidesTable.php index 2fa07a6..6d223d3 100644 --- a/src/Model/Table/SlidesTable.php +++ b/src/Model/Table/SlidesTable.php @@ -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); diff --git a/src/Service/PollStateService.php b/src/Service/PollStateService.php index 8c81dde..3400372 100644 --- a/src/Service/PollStateService.php +++ b/src/Service/PollStateService.php @@ -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, upvoted: array, + * @return array{stage: string, maxUpvotes: int, votesLeft: int, allowSelfUpvote: bool, mine: list, upvoted: array, * questions: list, 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), diff --git a/src/Service/QaService.php b/src/Service/QaService.php index 8a2bd85..378f46c 100644 --- a/src/Service/QaService.php +++ b/src/Service/QaService.php @@ -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) * diff --git a/src/Service/VoteService.php b/src/Service/VoteService.php index 4656b9e..fe5577a 100644 --- a/src/Service/VoteService.php +++ b/src/Service/VoteService.php @@ -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). diff --git a/templates/Admin/index.php b/templates/Admin/index.php index 37ae761..6283fa1 100644 --- a/templates/Admin/index.php +++ b/templates/Admin/index.php @@ -96,7 +96,7 @@ $hasInternal = array_filter($slides, fn($slide) => $slide->isInteractive() && $s 'collect' => __('Fragen sammeln'), 'vote' => __('Abstimmung läuft'), 'discuss' => __('Fragen werden besprochen'), - ][$slide->qaStage()]) ?> · setting('max_upvotes'), (int)$slide->setting('max_upvotes')) ?> + ][$slide->qaStage()]) ?> · setting('max_upvotes'), (int)$slide->setting('max_upvotes')) ?>setting('allow_self_upvote') ? ' · ' . __('auch für eigene Fragen') : '' ?> isOrder() && !$slide->is_voting_open) : ?> · is_voting_open) : ?>· diff --git a/templates/Slides/form.php b/templates/Slides/form.php index 267f04c..b454565 100644 --- a/templates/Slides/form.php +++ b/templates/Slides/form.php @@ -291,6 +291,13 @@ $optionsError = $slide->getError('options_text'); 'aria-describedby' => 'qa-upvotes-hint', ]) ?>

+ Form->control('settings.allow_self_upvote', [ + 'type' => 'checkbox', + 'label' => __('Stimmen für eigene Fragen erlauben'), + 'checked' => (bool)$settings['allow_self_upvote'], + 'aria-describedby' => 'qa-self-upvote-hint', + ]) ?> +

diff --git a/tests/TestCase/Service/QaTest.php b/tests/TestCase/Service/QaTest.php index d08270e..ec0e527 100644 --- a/tests/TestCase/Service/QaTest.php +++ b/tests/TestCase/Service/QaTest.php @@ -151,9 +151,38 @@ class QaTest extends TestCase $this->assertArrayNotHasKey('votes', $state['qa']['questions'][0]); $this->assertSame([$b => 2, $a => 1], $state['qa']['upvoted']); $this->assertSame(0, $state['qa']['votesLeft']); + $this->assertFalse($state['qa']['allowSelfUpvote']); $this->assertTrue($state['hasResponded']); } + public function testSelfUpvoteOnlyWithSetting(): void + { + [, $slide] = $this->createQa(); + $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')); + + [$poll] = $this->createPoll(); + $slide = $this->createSlide($poll, Slide::TYPE_QA, ['settings' => ['max_upvotes' => 3, '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'); + $slide = $this->stage($slide, Slide::QA_VOTE); + + // Own questions take votes from the same budget, stacked and withdrawn like any other. + $this->vote($poll, $slide, 'p1', $a); + $this->vote($poll, $slide, 'p1', $a); + $this->vote($poll, $slide, 'p1', $b); + $this->assertVoteFails('Du hast alle 3 Stimmen vergeben. Nimm eine zurück, um eine andere Frage zu unterstützen.', fn() => $this->vote($poll, $slide, 'p1', $a)); + $this->vote($poll, $slide, 'p1', $a, 'remove'); + + $state = (new PollStateService())->forParticipant($poll, 'p1')['qa']; + $this->assertTrue($state['allowSelfUpvote']); + $this->assertSame([$a => 1, $b => 1], $state['upvoted']); + $this->assertSame(1, $state['votesLeft']); + } + public function testDiscussStepsThroughQuestionsByRank(): void { [$poll, $slide] = $this->createQa(3); diff --git a/webroot/js/plenario.js b/webroot/js/plenario.js index 8626d07..c044408 100644 --- a/webroot/js/plenario.js +++ b/webroot/js/plenario.js @@ -1398,12 +1398,15 @@ qaList.appendChild(el('p', { class: 'results-empty', text: 'Es wurden keine Fragen eingereicht.' })); return; } + if (qa.mine.length && !qa.allowSelfUpvote) { + qaList.appendChild(el('p', { class: 'hint', text: 'Deine eigenen Fragen kannst du nicht unterstützen – verteile deine Stimmen auf die Fragen der anderen.' })); + } qaList.appendChild(el('ul', { class: 'qa-list' }, qa.questions.map(function (question) { var mine = qa.mine.indexOf(question.id) >= 0; // Own upvotes on this question – several are allowed to push important questions. var given = (qa.upvoted || {})[question.id] || 0; var action; - if (mine) { + if (mine && !qa.allowSelfUpvote) { action = el('span', { class: 'qa-own', text: 'deine Frage' }); } else { var button = function (vote, symbol, label, disabled) { @@ -1430,7 +1433,7 @@ ]); } return el('li', { class: 'qa-item' + (mine ? ' is-mine' : '') + (given > 0 ? ' is-upvoted' : '') }, [ - el('span', { class: 'qa-item__text', text: question.text }), + el('span', { class: 'qa-item__text', text: question.text + (mine && qa.allowSelfUpvote ? ' (deine Frage)' : '') }), action ]); })));