Remove per-participant word limit from word clouds
Participants can now always submit any number of words. Drops the max_words setting, its form field, the limit checks in VoteService and the remaining/limitReached state; existing max_words values in stored settings are ignored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6cc813f87b
commit
bd17a97487
10 files changed
+26
-87
No files matched your search
@@ -127,7 +127,7 @@ class PollStateService
|
||||
$slide?->id ?? 0,
|
||||
(int)($slide?->is_voting_open ?? 0),
|
||||
// Word clouds are answered word by word without reload.
|
||||
$words !== null ? (int)$words['limitReached'] : (int)$hasResponded,
|
||||
$words !== null ? 0 : (int)$hasResponded,
|
||||
$slide?->modified?->toUnixString() ?? 0,
|
||||
]),
|
||||
'slide' => $showResults ? $this->slidePayload($slide) : null,
|
||||
@@ -141,25 +141,19 @@ class PollStateService
|
||||
*
|
||||
* @param \App\Model\Entity\Slide $slide Word cloud slide
|
||||
* @param string $participantHash Participant hash
|
||||
* @return array{mine: list<string>, down: list<string>, max: int, remaining: int|null,
|
||||
* limitReached: bool, allowUpvotes: bool, allowDownvotes: bool}
|
||||
* `mine` (named/upvoted) and `down` are lower case word keys, `remaining` is null when unlimited
|
||||
* @return array{mine: list<string>, down: list<string>, allowUpvotes: bool, allowDownvotes: bool}
|
||||
* `mine` (named/upvoted) and `down` are lower case word keys
|
||||
*/
|
||||
public function wordState(Slide $slide, string $participantHash): array
|
||||
{
|
||||
$votes = $this->Responses->wordVotesOf($slide->id, $participantHash);
|
||||
$mine = array_values(array_unique(array_map(VoteService::wordKey(...), $votes['up'])));
|
||||
$down = array_values(array_unique(array_map(VoteService::wordKey(...), $votes['down'])));
|
||||
$max = (int)$slide->setting('max_words');
|
||||
$remaining = $max > 0 ? max(0, $max - count($mine)) : null;
|
||||
$allowUpvotes = (bool)$slide->setting('allow_upvotes');
|
||||
|
||||
return [
|
||||
'mine' => $mine,
|
||||
'down' => $down,
|
||||
'max' => $max,
|
||||
'remaining' => $remaining,
|
||||
'limitReached' => $remaining === 0,
|
||||
'allowUpvotes' => $allowUpvotes,
|
||||
'allowDownvotes' => $allowUpvotes && (bool)$slide->setting('allow_downvotes'),
|
||||
];
|
||||
|
||||
@@ -17,11 +17,10 @@ use Cake\Utility\Security;
|
||||
* - voting on the slide must be open
|
||||
* - every participant can answer a slide exactly once, except word clouds:
|
||||
* there words are submitted one by one (each word once per participant,
|
||||
* at most `max_words` words, 0 = unlimited). Submitting a word that already
|
||||
* any number of words). Submitting a word that already
|
||||
* exists in the cloud is an upvote – both are stored as the same row.
|
||||
* `vote=down` stores a downvote (numeric_value = DOWNVOTE) for an existing
|
||||
* word of someone else. Each participant rates a word only once (up or down);
|
||||
* downvotes do not count towards `max_words`.
|
||||
* word of someone else. Each participant rates a word only once (up or down).
|
||||
*/
|
||||
class VoteService
|
||||
{
|
||||
@@ -153,7 +152,7 @@ class VoteService
|
||||
|
||||
/**
|
||||
* Accepts `word` (string) or `words` (list). Words the participant already
|
||||
* submitted are skipped, the rest is cut to the remaining limit.
|
||||
* submitted are skipped.
|
||||
*
|
||||
* @param \App\Model\Entity\Slide $slide Slide
|
||||
* @param string $participantHash Participant hash
|
||||
@@ -193,19 +192,6 @@ class VoteService
|
||||
$words[] = $word;
|
||||
}
|
||||
|
||||
$max = (int)$slide->setting('max_words');
|
||||
if ($max > 0) {
|
||||
$remaining = max(0, $max - count($existing));
|
||||
if ($remaining === 0) {
|
||||
throw new VoteException(__n(
|
||||
'Du hast deinen Begriff bereits abgegeben.',
|
||||
'Du hast bereits alle {0} Begriffe abgegeben.',
|
||||
$max,
|
||||
$max,
|
||||
));
|
||||
}
|
||||
$words = array_slice($words, 0, $remaining);
|
||||
}
|
||||
if ($words === []) {
|
||||
throw new VoteException(match (true) {
|
||||
$duplicate => __('Diesen Begriff hast du schon genannt.'),
|
||||
|
||||
Reference in new issue
Block a user