Add hiding slides from the presentation
CI / Deploy / test (push) Successful in 57s
CI / Deploy / deploy (push) Skipped

Hidden slides stay prepared in the dashboard but are skipped when
presenting (start, next/prev, goto), can not go live via embed and are
left out of the PDF export. Hiding the live or paused slide pauses the
poll like deleting it and resumes with the next visible slide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-11 15:25:41 +01:00
1 parent e2f24877dd
commit 3c978e6f22
15 files changed
+333 -35

No files matched your search

+3 -2
View File
@@ -161,7 +161,7 @@ class AdminController extends AdminAppController
{
if ($this->poll->current_slide_id === null && !$this->poll->isPaused()) {
$first = $this->Slides->find()
->where(['poll_id' => $this->poll->id])
->where(['poll_id' => $this->poll->id, 'is_hidden' => false])
->orderBy(['position' => 'ASC', 'id' => 'ASC'])
->first();
if ($first !== null) {
@@ -203,7 +203,8 @@ class AdminController extends AdminAppController
{
$this->request->allowMethod(['post']);
$action = (string)$this->request->getData('action');
$slides = $this->Slides->listForPoll($this->poll->id);
// Hidden slides are skipped and can not go live.
$slides = $this->Slides->listForPoll($this->poll->id, true);
$ids = array_map(fn(Slide $s) => $s->id, $slides);
$index = array_search($this->poll->current_slide_id, $ids, true);
$current = $index === false ? null : $slides[$index];
+2 -2
View File
@@ -114,14 +114,14 @@ class EmbedController extends AppController
}
/**
* The embed became visible: this slide goes live. Idempotent.
* The embed became visible: this slide goes live (unless it is hidden). Idempotent.
*
* @return \Cake\Http\Response
*/
public function activate(): Response
{
$this->request->allowMethod(['post']);
if ($this->poll->is_active) {
if ($this->poll->is_active && !$this->slide->is_hidden) {
$this->poll->showEmbeddedSlide($this->slide->id);
$this->Polls->saveOrFail($this->poll);
}
+29 -9
View File
@@ -104,15 +104,7 @@ class SlidesController extends AdminAppController
$this->request->allowMethod(['post']);
$slide = $this->loadSlide($id);
// Deleting the live (or paused) slide pauses the poll; → resumes with the slide taking its place.
$ids = $this->Slides->find()
->select(['id'])
->where(['poll_id' => $this->poll->id])
->orderBy(['position' => 'ASC', 'id' => 'ASC'])
->all()
->extract('id')
->toList();
$index = (int)array_search($slide->id, $ids, true);
$this->poll->forgetSlide($slide->id, $ids[$index + 1] ?? $ids[$index - 1] ?? null);
$this->poll->forgetSlide($slide->id, $this->Slides->replacementFor($slide));
$this->Slides->getConnection()->transactional(function () use ($slide): void {
$this->Polls->saveOrFail($this->poll);
@@ -124,6 +116,34 @@ class SlidesController extends AdminAppController
return $this->redirect($this->adminUrl());
}
/**
* Hides a slide from the presentation or shows it again. Field `hidden` (1|0) is explicit
* (not a toggle), so repeating the request changes nothing. Hiding the live (or paused)
* slide pauses the poll like deleting it.
*
* @param string $id Slide id
* @return \Cake\Http\Response|null
*/
public function visibility(string $id): ?Response
{
$this->request->allowMethod(['post']);
$slide = $this->loadSlide($id);
$hidden = filter_var($this->request->getData('hidden'), FILTER_VALIDATE_BOOLEAN);
$this->Slides->getConnection()->transactional(function () use ($slide, $hidden): void {
if ($hidden) {
$this->poll->forgetSlide($slide->id, $this->Slides->replacementFor($slide));
$this->Polls->saveOrFail($this->poll);
}
$this->Slides->updateAll(['is_hidden' => $hidden], ['id' => $slide->id]);
});
$this->Flash->success($hidden
? __('Folie „{0}“ ist ausgeblendet und wird beim Präsentieren übersprungen.', $slide->question)
: __('Folie „{0}“ ist wieder eingeblendet.', $slide->question));
return $this->redirect($this->adminUrl());
}
/**
* Copies a slide (without responses) directly behind the original and opens the copy for editing.
*
+4 -3
View File
@@ -110,10 +110,11 @@ class Poll extends Entity
}
/**
* A slide is being deleted. If it was live or is the one a pause resumes, the poll pauses
* and resumes with $resumeSlideId instead (null: no slides left = not started). Idempotent.
* A slide leaves the presentation (deleted or hidden). If it was live or is the one a pause
* resumes, the poll pauses and resumes with $resumeSlideId instead (null: no slides left =
* not started). Idempotent.
*
* @param int $slideId Deleted slide
* @param int $slideId Deleted or hidden slide
* @param int|null $resumeSlideId Slide that takes its place (must belong to this poll)
* @return void
*/
+1
View File
@@ -17,6 +17,7 @@ use Cake\ORM\Entity;
* @property string $question
* @property string|null $description
* @property int $position
* @property bool $is_hidden Prepared, but skipped in the presentation (never live)
* @property array<string, mixed>|null $settings
* @property bool $is_voting_open
* @property \Cake\I18n\DateTime|null $voting_started_at Quiz: start of the voting window
+39 -6
View File
@@ -423,18 +423,51 @@ class SlidesTable extends Table
* Ordered slides of a poll including options.
*
* @param int $pollId Poll id
* @param bool $visibleOnly Only slides that are part of the presentation (not hidden)
* @return list<\App\Model\Entity\Slide>
*/
public function listForPoll(int $pollId): array
public function listForPoll(int $pollId, bool $visibleOnly = false): array
{
/** @var list<\App\Model\Entity\Slide> $slides */
$slides = $this->find()
$query = $this->find()
->where(['Slides.poll_id' => $pollId])
->contain(['SlideOptions'])
->orderBy(['Slides.position' => 'ASC', 'Slides.id' => 'ASC'])
->all()
->toList();
->orderBy(['Slides.position' => 'ASC', 'Slides.id' => 'ASC']);
if ($visibleOnly) {
$query->where(['Slides.is_hidden' => false]);
}
/** @var list<\App\Model\Entity\Slide> $slides */
$slides = $query->all()->toList();
return $slides;
}
/**
* The visible slide that takes the place of a slide leaving the presentation
* (deleted or hidden): the next visible one behind it, otherwise the one before.
*
* @param \App\Model\Entity\Slide $slide Slide leaving the presentation
* @return int|null Slide id, null if no other visible slide is left
*/
public function replacementFor(Slide $slide): ?int
{
$rows = $this->find()
->select(['id', 'is_hidden'])
->where(['poll_id' => $slide->poll_id])
->orderBy(['position' => 'ASC', 'id' => 'ASC'])
->disableHydration()
->all()
->toList();
$index = array_search($slide->id, array_column($rows, 'id'), true);
if ($index === false) {
return null;
}
$candidates = array_merge(array_slice($rows, $index + 1), array_reverse(array_slice($rows, 0, $index)));
foreach ($candidates as $row) {
if (!$row['is_hidden']) {
return (int)$row['id'];
}
}
return null;
}
}
+4 -1
View File
@@ -83,7 +83,8 @@ class PollStateService
public function forPresenter(Poll $poll): array
{
$this->Polls->pauseIfEmbedStale($poll);
$slides = $this->Slides->listForPoll($poll->id);
// The presentation consists of the visible slides only.
$slides = $this->Slides->listForPoll($poll->id, true);
$current = null;
$index = null;
foreach ($slides as $i => $slide) {
@@ -102,6 +103,7 @@ class PollStateService
], $slides),
'index' => $index,
'count' => count($slides),
'hiddenCount' => $this->Slides->find()->where(['poll_id' => $poll->id, 'is_hidden' => true])->count(),
'slide' => $current ? $this->slidePayload($current) : null,
'results' => $current ? $this->results->forSlide($current) : null,
];
@@ -123,6 +125,7 @@ class PollStateService
return [
'poll' => $this->pollPayload($poll),
'isLive' => $poll->current_slide_id === $slide->id,
'isHidden' => $slide->is_hidden,
'index' => null,
'count' => null,
'slide' => $this->slidePayload($slide),
+2 -2
View File
@@ -16,7 +16,7 @@ use Cake\ORM\Locator\LocatorAwareTrait;
* screen. With $includeInternal it also contains their answers, distribution and comments –
* that version is meant for the poll owner only.
*
* Per slide: ['slide' => Slide, 'number' => int (position in the poll, 1-based),
* Per slide: ['slide' => Slide, 'number' => int (position in the presentation, 1-based; hidden slides are left out),
* 'internal' => bool (private slide), 'withheld' => bool (private and left out),
* 'results' => ResultsService::forSlide() shape, where
* open: 'answers' contains all texts (not only the newest ones), and
@@ -49,7 +49,7 @@ class ReportService
*/
public function build(Poll $poll, bool $includeInternal): array
{
$slides = $this->Slides->listForPoll($poll->id);
$slides = $this->Slides->listForPoll($poll->id, true);
$includeInternal = $includeInternal
&& array_filter($slides, fn(Slide $slide) => $slide->isInteractive() && $slide->isPrivate()) !== [];
$sections = [];