Allow upvoting own Q&A questions as an opt-in setting #25
No files matched your search
@@ -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`,
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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()]) ?> · <?= __n('max. {0} Upvote pro Person', 'max. {0} Upvotes pro Person', (int)$slide->setting('max_upvotes'), (int)$slide->setting('max_upvotes')) ?></span>
|
||||
][$slide->qaStage()]) ?> · <?= __n('max. {0} Upvote pro Person', 'max. {0} Upvotes pro Person', (int)$slide->setting('max_upvotes'), (int)$slide->setting('max_upvotes')) ?><?= $slide->setting('allow_self_upvote') ? ' · ' . __('auch für eigene Fragen') : '' ?></span>
|
||||
<?php elseif ($slide->isOrder() && !$slide->is_voting_open) : ?>
|
||||
<span class="muted">· <?= __('Abstimmung geschlossen, aufgelöst') ?></span>
|
||||
<?php elseif (!$slide->is_voting_open) : ?><span class="muted">· <?= __('Abstimmung geschlossen') ?></span><?php endif; ?>
|
||||
|
||||
@@ -291,6 +291,13 @@ $optionsError = $slide->getError('options_text');
|
||||
'aria-describedby' => 'qa-upvotes-hint',
|
||||
]) ?>
|
||||
<p class="hint" id="qa-upvotes-hint"><?= __('So viele Stimmen hat jede Person beim Abstimmen. Sie lassen sich frei auf Fragen anderer verteilen – mehrere auf eine Frage geben ihr mehr Gewicht.') ?></p>
|
||||
<?= $this->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',
|
||||
]) ?>
|
||||
<p class="hint" id="qa-self-upvote-hint"><?= __('Sinnvoll, wenn ihr Themen priorisiert („Was besprechen wir heute?“). Bei normalen Fragerunden lieber aus: Sonst landen oft die Fragen derjenigen vorn, die alle Stimmen sich selbst geben.') ?></p>
|
||||
<p class="hint"><?= __('Ablauf in der Präsentation: 1. Fragen sammeln, 2. abstimmen, 3. besprechen – die Frage mit den meisten Upvotes zuerst. Du schaltest die Schritte selbst weiter.') ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
]);
|
||||
})));
|
||||
|
||||
Reference in new issue
Block a user