Let participants edit their scale comment while voting is open

Participants can fix typos in, add or remove their own comment until the
voting closes. The rating itself stays unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-11 11:40:24 +01:00
1 parent bd488e0b81
commit d518b7a37e
6 files changed
+244 -20

No files matched your search

+36 -1
View File
@@ -86,8 +86,11 @@ class ParticipateController extends AppController
$slide = $poll->is_active ? $stateService->currentSlide($poll) : null;
$participantHash = $this->participantHash($poll);
$state = $stateService->forParticipant($poll, $participantHash, $slide);
$ownComment = $slide?->hasComments() && $state['hasResponded']
? (new VoteService())->ownComment($slide, $participantHash)
: null;
$this->set(compact('poll', 'slide', 'state', 'participantHash'));
$this->set(compact('poll', 'slide', 'state', 'participantHash', 'ownComment'));
$this->setPollInterval();
}
@@ -153,6 +156,38 @@ class ParticipateController extends AppController
return $this->redirect(['_name' => 'participate', 'code' => $poll->join_code]);
}
/**
* Replaces the own comment on a scale slide while voting is open (e.g. to fix a typo).
*
* @param string $code Join code
* @return \Cake\Http\Response|null
*/
public function comment(string $code): ?Response
{
$this->request->allowMethod(['post']);
$poll = $this->loadPoll($code);
$slide = (new PollStateService())->currentSlide($poll);
try {
if (!$this->throttle('vote', 'Plenario.throttle.votesPerMinute', 60)) {
throw new VoteException(__('Zu viele Antworten in kurzer Zeit. Bitte warte einen Moment und versuche es dann noch einmal.'));
}
if ($slide === null || $slide->id !== (int)$this->request->getData('slide_id')) {
throw new VoteException(__('Diese Frage ist nicht mehr aktiv.'));
}
$data = (array)$this->request->getData();
(new VoteService())->editComment($poll, $slide, $this->participantHash($poll), $data);
$comment = $data['comment'] ?? '';
$this->Flash->success(!is_scalar($comment) || trim((string)$comment) === ''
? __('Dein Kommentar wurde entfernt.')
: __('Dein Kommentar wurde gespeichert.'));
} catch (VoteException $e) {
$this->Flash->error($e->getMessage());
}
return $this->redirect(['_name' => 'participate', 'code' => $poll->join_code]);
}
/**
* @param string $code Join code
* @return \App\Model\Entity\Poll