Let participants withdraw their own word cloud terms
CI / Deploy / test (push) Successful in 59s
CI / Deploy / deploy (push) Skipped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-11 12:07:44 +01:00
1 parent 3a8962976e
commit ad5223906c
7 files changed
+154 -6

No files matched your search

+10 -2
View File
@@ -321,8 +321,8 @@ class PollStateService
*
* @param \App\Model\Entity\Slide $slide Word cloud slide
* @param string $participantHash Participant hash
* @return array{mine: list<string>, down: list<string>, allowUpvotes: bool, allowDownvotes: bool}
* `mine` (named/upvoted) and `down` are lower case word keys
* @return array{mine: list<string>, down: list<string>, own: list<array{text: string, down: bool}>, allowUpvotes: bool, allowDownvotes: bool}
* `mine` (named/upvoted) and `down` are lower case word keys, `own` the same entries as typed
*/
public function wordState(Slide $slide, string $participantHash): array
{
@@ -330,10 +330,18 @@ class PollStateService
$mine = array_values(array_unique(array_map(VoteService::wordKey(...), $votes['up'])));
$down = array_values(array_unique(array_map(VoteService::wordKey(...), $votes['down'])));
$allowUpvotes = (bool)$slide->setting('allow_upvotes');
// Own entries as typed (first spelling per key), oldest first, so they can be withdrawn.
$own = [];
foreach (['up' => false, 'down' => true] as $kind => $isDown) {
foreach ($votes[$kind] as $text) {
$own[VoteService::wordKey($text)] ??= ['text' => $text, 'down' => $isDown];
}
}
return [
'mine' => $mine,
'down' => $down,
'own' => array_values($own),
'allowUpvotes' => $allowUpvotes,
'allowDownvotes' => $allowUpvotes && (bool)$slide->setting('allow_downvotes'),
];
+36
View File
@@ -22,6 +22,7 @@ use Cake\Utility\Security;
* 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).
* `vote=remove` withdraws the participant's own entry for a word (see removeWord()).
* At most MAX_WORDS_PER_REQUEST terms per request and MAX_WORDS per participant and slide.
* - checks and insert run in one transaction with the slide row locked (see lockSlide()),
* so concurrent or repeated requests cannot store an answer twice.
@@ -529,6 +530,11 @@ class VoteService
if (($data['vote'] ?? null) === 'down') {
return $this->downvoteRows($slide, self::stringField($data, 'word'), $existing, $downvoted);
}
if (($data['vote'] ?? null) === 'remove') {
$this->removeWord($slide, $participantHash, self::stringField($data, 'word'));
return [];
}
$input = array_filter(
array_merge((array)($data['words'] ?? []), (array)($data['word'] ?? [])),
@@ -574,6 +580,36 @@ class VoteService
return array_map(fn(string $word) => ['text_value' => $word], $words);
}
/**
* Word cloud: withdraws the participant's own entry for a term – named/upvoted or downvoted –
* e.g. to fix a typo by entering it again. Only the participant's own rows are touched; the term
* stays in the cloud as long as others named it.
*
* @param \App\Model\Entity\Slide $slide Slide
* @param string $participantHash Participant hash
* @param string $word Word to withdraw
* @return void
* @throws \App\Service\VoteException
*/
protected function removeWord(Slide $slide, string $participantHash, string $word): void
{
$key = self::wordKey($word);
$ids = [];
$own = $this->Responses->find()
->select(['id', 'text_value'])
->where(['slide_id' => $slide->id, 'participant_hash' => $participantHash, 'text_value IS NOT' => null])
->disableHydration();
foreach ($own as $row) {
if (self::wordKey((string)$row['text_value']) === $key) {
$ids[] = $row['id'];
}
}
if ($key === '' || $ids === []) {
throw new VoteException(__('Diesen Begriff hast du nicht genannt.'));
}
$this->Responses->deleteAll(['id IN' => $ids]);
}
/**
* @param \App\Model\Entity\Slide $slide Slide
* @param string $word Word to downvote