Share repeated controller and service code
CI / Deploy / test (push) Successful in 53s
CI / Deploy / deploy (push) Skipped

- AppController: joinUrl(), adminUrlFor(), setPollInterval() and protect()
  instead of copies in Admin-, Home-, Participate- and EmbedController.
- PollMailer::sendSafely() replaces two try/catch blocks around mail sending.
- Slide::optionIds() replaces five identical array_map() calls.
- PollStateService: one pollPayload() for presenter and embed; the vote
  action passes the already loaded slide instead of loading it again.
- ResultsService::forSlide() takes the answer/comment limit and the rating
  flag, so ReportService no longer queries answers, comments and the scale
  distribution twice and the export loads the slides only once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-08 22:50:56 +01:00
1 parent ad537b9b34
commit 3e44ded107
14 files changed
+189 -137

No files matched your search

+28 -17
View File
@@ -94,13 +94,7 @@ class PollStateService
}
return [
'poll' => [
'title' => $poll->title,
'joinCode' => $poll->join_code,
'joinCodeFormatted' => $poll->formattedJoinCode(),
'isActive' => $poll->is_active,
'isPaused' => $poll->isPaused(),
],
'poll' => $this->pollPayload($poll),
'slides' => array_map(fn(Slide $s) => [
'id' => $s->id,
'type' => $s->type,
@@ -127,13 +121,7 @@ class PollStateService
$slide = $this->Slides->closeIfExpired($slide);
return [
'poll' => [
'title' => $poll->title,
'joinCode' => $poll->join_code,
'joinCodeFormatted' => $poll->formattedJoinCode(),
'isActive' => $poll->is_active,
'isPaused' => $poll->isPaused(),
],
'poll' => $this->pollPayload($poll),
'isLive' => $poll->current_slide_id === $slide->id,
'index' => null,
'count' => null,
@@ -145,11 +133,17 @@ class PollStateService
/**
* @param \App\Model\Entity\Poll $poll Poll
* @param string $participantHash Participant hash
* @param \App\Model\Entity\Slide|false|null $current Current slide if already loaded via currentSlide()
* in this request (null = none is live), false = load it
* @return array<string, mixed>
*/
public function forParticipant(Poll $poll, string $participantHash): array
public function forParticipant(Poll $poll, string $participantHash, Slide|false|null $current = false): array
{
$slide = $poll->is_active ? $this->currentSlide($poll) : null;
$slide = match (true) {
!$poll->is_active => null,
$current === false => $this->currentSlide($poll),
default => $current,
};
$words = $slide?->type === Slide::TYPE_WORDCLOUD ? $this->wordState($slide, $participantHash) : null;
$quiz = $slide?->isQuiz() ? $this->quizState($slide, $participantHash) : null;
$qa = $slide?->isQa() ? $this->qaState($slide, $participantHash) : null;
@@ -233,7 +227,7 @@ class PollStateService
->first();
$answer = $response === null ? null : VoteService::parseOrder($response->text_value);
}
$correct = array_map(fn($option) => $option->id, array_values($slide->slide_options ?? []));
$correct = $slide->optionIds();
return [
'revealed' => $revealed,
@@ -343,6 +337,23 @@ class PollStateService
];
}
/**
* Poll part of the presenter and embed state.
*
* @param \App\Model\Entity\Poll $poll Poll
* @return array{title: string, joinCode: string, joinCodeFormatted: string, isActive: bool, isPaused: bool}
*/
protected function pollPayload(Poll $poll): array
{
return [
'title' => $poll->title,
'joinCode' => $poll->join_code,
'joinCodeFormatted' => $poll->formattedJoinCode(),
'isActive' => $poll->is_active,
'isPaused' => $poll->isPaused(),
];
}
/**
* @param \App\Model\Entity\Slide $slide Slide
* @return array<string, mixed>