Hide Q&A upvote counts until voting ends #53

Merged
gnilebein merged 1 commits from fix/qa-own-question-mobile into main 2026-11-11 15:06:51 +01:00
5 changed files with 21 additions and 11 deletions
Showing only changes of commit 759e15390e - Show all commits

No files matched your search

+2 -1
View File
@@ -165,7 +165,8 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures
wird es während `vote` auf 0 gesetzt, springt `SlidesController::saveSlide()` nach `discuss`.
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
Teilnehmende sehen alle Fragen in Eingangsreihenfolge **ohne** Zählung; auch die Bühne (Presenter/Embed, PDF) bekommt in `vote`
keine Zählungen je Frage und keine Rangfolge (`ResultsService::qa()`, nur die Summe `upvotes`), damit niemand beeinflusst wird. `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`,
damit Teilnehmerseiten nicht neu laden. Teilnehmende bekommen nie `results`, sondern `qa` aus `PollStateService::qaState()`.
+9 -2
View File
@@ -40,7 +40,8 @@ use Cake\ORM\Locator\LocatorAwareTrait;
* - 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),
* 'questions' => [['id', 'text', 'votes']] most upvoted first (ties: oldest first);
* during 'vote' only [['id', 'text']] in submission order (no counts while voting is open),
* 'focusId' (question being discussed|null), 'focusIndex' (0-based position in questions|null).
* Presenter only – participants get their own view, see PollStateService::qaState().
*/
@@ -215,6 +216,12 @@ class ResultsService
protected function qa(Slide $slide): array
{
$questions = (new QaService())->rankedQuestions($slide);
$upvotes = array_sum(array_column($questions, 'votes'));
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']);
$questions = array_map(fn($q) => ['id' => $q['id'], 'text' => $q['text']], $questions);
}
$focusIndex = null;
foreach ($questions as $index => $question) {
if ($question['id'] === $slide->focus_response_id) {
@@ -227,7 +234,7 @@ class ResultsService
'stages' => $slide->qaStages(),
'maxUpvotes' => (int)$slide->setting('max_upvotes'),
'maxPerQuestion' => $slide->qaUpvotesPerQuestion(),
'upvotes' => array_sum(array_column($questions, 'votes')),
'upvotes' => $upvotes,
'questions' => $questions,
'focusId' => $focusIndex === null ? null : $slide->focus_response_id,
'focusIndex' => $focusIndex,
+1 -1
View File
@@ -213,7 +213,7 @@ $bar = function (float $percent, bool $ok = false): string {
<?php if ($r['questions'] === []) : ?>
<p class="empty"><?= __('Keine Fragen eingereicht.') ?></p>
<?php else : ?>
<?php $withUpvotes = $r['maxUpvotes'] > 0; ?>
<?php $withUpvotes = $r['maxUpvotes'] > 0 && $r['stage'] !== 'vote'; ?>
<table>
<thead><tr><th class="num">#</th><th><?= __('Frage') ?></th><?php if ($withUpvotes) : ?><th class="num"><?= __('Upvotes') ?></th><?php endif; ?></tr></thead>
<tbody>
+6 -2
View File
@@ -203,12 +203,16 @@ class QaTest extends TestCase
$this->assertVoteFails('Du hast diese Frage nicht unterstützt.', fn() => $this->vote($poll, $slide, 'p3', $c, 'remove'));
$this->vote($poll, $slide, 'p3', $a);
// While voting is open, the stage only gets the total: no ranking, no counts per question.
$results = (new ResultsService())->forSlide($slide);
$this->assertSame([[$b, 3], [$a, 1], [$c, 0]], array_map(fn($q) => [$q['id'], $q['votes']], $results['questions']));
$this->assertSame([$a, $b, $c], array_column($results['questions'], 'id'));
$this->assertArrayNotHasKey('votes', $results['questions'][0]);
$this->assertSame(4, $results['upvotes']);
$ranked = (new QaService())->rankedQuestions($slide);
$this->assertSame([[$b, 3], [$a, 1], [$c, 0]], array_map(fn($q) => [$q['id'], $q['votes']], $ranked));
$this->vote($poll, $slide, 'p3', $b, 'remove');
$this->assertSame(2, (new ResultsService())->forSlide($slide)['questions'][0]['votes'], 'remove withdraws only one upvote');
$this->assertSame(2, (new QaService())->rankedQuestions($slide)[0]['votes'], 'remove withdraws only one upvote');
$this->vote($poll, $slide, 'p3', $b);
// Voting view of participants: all questions, submission order, no counts.
+3 -5
View File
@@ -1000,7 +1000,6 @@
var onStage = options && options.onStage;
var onQuestion = options && options.onQuestion;
var questions = results.questions;
var maxVotes = Math.max.apply(null, questions.map(function (q) { return q.votes; }).concat([1]));
var children = [Qa.steps(results.stage, onStage, results.stages)];
var withVotes = results.maxUpvotes > 0;
@@ -1027,11 +1026,10 @@
+ results.maxUpvotes + (results.maxUpvotes === 1 ? ' Stimme' : ' Stimmen')
+ (results.maxPerQuestion < results.maxUpvotes ? ' (höchstens ' + results.maxPerQuestion + ' pro Frage)' : '')
+ ' · bisher ' + results.upvotes + ' vergeben' }));
children.push(el('ol', { class: 'qa-list' }, questions.map(function (question) {
// No counts or ranking while voting is open (the server sends none), so the stage does not sway the vote.
children.push(el('ul', { class: 'qa-list' }, questions.map(function (question) {
return el('li', { class: 'qa-item' }, [
el('span', { class: 'qa-item__text', text: question.text }),
votes(question),
el('span', { class: 'qa-item__bar', style: 'width:' + (question.votes / maxVotes * 100) + '%' })
el('span', { class: 'qa-item__text', text: question.text })
]);
})));
} else if (questions.length === 0) {