Let participants withdraw their own word cloud terms
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3a8962976e
commit
ad5223906c
7 files changed
+154
-6
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user