diff --git a/AGENTS.md b/AGENTS.md index 4c6d062..10405c9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -58,7 +58,7 @@ src/ HomeController Startseite, Anlegen (/create), Bestätigung, Join, Recover AdminAppController Basis für /admin/{token}: löst Poll über Token-Hash auf (404 sonst), setzt Privacy-Header (no-referrer, no-store) AdminController Dashboard, Settings, Present, State-JSON, Control, QR, PDF-Export, Token rotieren, Zurücksetzen, Löschen - SlidesController Folien-CRUD, Antworten offener Fragen bzw. Skala-Auswertung (`answers`), Sortieren (Drag & Drop/Pfeiltasten via `reorder`, JSON; erfordert JS), Antworten zurücksetzen, + SlidesController Folien-CRUD, Ein-/Ausblenden (`visibility`), Duplizieren (`duplicate` → `SlidesTable::duplicate()`, Kopie direkt dahinter, öffnet das Formular der Kopie), Antworten offener Fragen bzw. Skala-Auswertung (`answers`), Sortieren (Drag & Drop/Pfeiltasten via `reorder`, JSON; erfordert JS), Antworten zurücksetzen, YouTube-Link prüfen (`youtubeCheck`, JSON) ParticipateController /p/{code}: Ansicht, State-JSON, Abstimmen, eigene Antwort/Kommentar bearbeiten; anonymes Cookie plenario_pid EmbedController /e/{key}/{id}: eine Folie zum Einbetten (z. B. Canva), activate/heartbeat/pause/control @@ -95,6 +95,7 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures `embed_key` (Einbett-Schlüssel), `embed_seen_at` (letztes Lebenszeichen der eingebetteten Live-Folie), `paused_slide_id` (Folie vor der Pause), `comment_speed` (Tempo der Skala-Kommentare in Prozent, Standard 100) - `slides`: `type` (`choice|wordcloud|open|scale|content|quiz|youtube|qa|order`), `question`, `description`, `position`, + `is_hidden` (ausgeblendet: vorbereitet, aber nicht Teil der Präsentation), `settings` (JSON, je Typ siehe `Slide::DEFAULT_SETTINGS`), `is_voting_open`, `voting_started_at` / `voting_ends_at` (nur Quiz: Start und Deadline, `null` = manuell beenden), `stage` / `focus_response_id` (nur Q&A: Phase und gerade besprochene Frage) @@ -196,6 +197,17 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures (`admin:reset`, Dashboard → „Sicherheit“). Nur Quiz (`ready`) und Q&A (`collect`) springen zurück, weil ihre Phasen ohne Antworten keinen Sinn ergeben; offen/geschlossen anderer Folien, aktuelle Folie/Pause, Einstellungen bleiben. Idempotent, in einer Transaktion. Tests: `PollResetTest.php`. +- **Duplizieren** (`slides:duplicate`, POST): kopiert Fragetext (+ „(Kopie)“), Beschreibung, Einstellungen und Optionen + inkl. `is_correct`, **nie Antworten**. Die Kopie landet direkt hinter dem Original und startet wie eine neue Folie + (`Slide::startFresh()`: Quiz `ready`, Q&A `collect`, sonst offen) – auch `add()` nutzt `startFresh()`. + Tests: `DuplicateSlideTest.php`. +- **Ausgeblendete Folien** (`is_hidden`, `slides:visibility` mit `hidden=1|0`, explizit statt Toggle → idempotent): + bleiben in der Verwaltung (gestrichelt, Badge „ausgeblendet“), gehören aber nicht zur Präsentation. Präsentation = + `SlidesTable::listForPoll($pollId, true)`: Start, →/←, `goto` (400 für ausgeblendete), Zähler im Presenter-State + (`count` ohne, `hiddenCount` = ausgeblendete), PDF-Export (Nummerierung wie in der Präsentation). Einbettung einer + ausgeblendeten Folie geht nicht live (`isHidden` im Embed-State). Eine ausgeblendete Folie darf nie live/pausiert sein: + Ausblenden der Live- oder pausierten Folie pausiert wie Löschen (`forgetSlide()` + `SlidesTable::replacementFor()` = + nächste sichtbare Folie, sonst die vorige). `is_hidden` ist nicht mass-assignable. Tests: `HiddenSlideTest.php`. - **Pause:** `current_slide_id = null` + `paused_slide_id` = Pause (Teilnehmende sehen „Kurze Pause“), ohne `paused_slide_id` = noch nicht gestartet. Immer über `Poll::showSlide()` / `showEmbeddedSlide()` / `pause()` / `forgetSlide()` setzen, nie `current_slide_id` direkt. Presenter: P bzw. der Pause-Button schaltet um (Aktionen `stop`/`resume`, beide idempotent, kein Server-Toggle), diff --git a/config/Migrations/20261111150000_AddIsHiddenToSlides.php b/config/Migrations/20261111150000_AddIsHiddenToSlides.php new file mode 100644 index 0000000..59ed676 --- /dev/null +++ b/config/Migrations/20261111150000_AddIsHiddenToSlides.php @@ -0,0 +1,37 @@ +table('slides'); + if (!$table->hasColumn('is_hidden')) { + $table->addColumn('is_hidden', 'boolean', [ + 'null' => false, + 'default' => false, + 'after' => 'position', + ])->update(); + } + } + + /** + * @return void + */ + public function down(): void + { + $table = $this->table('slides'); + if ($table->hasColumn('is_hidden')) { + $table->removeColumn('is_hidden')->update(); + } + } +} diff --git a/config/routes.php b/config/routes.php index 54b189e..f216427 100644 --- a/config/routes.php +++ b/config/routes.php @@ -83,7 +83,11 @@ return function (RouteBuilder $routes): void { ->setPatterns($token)->setPass(['id']); $admin->connect('/slides/{id}/delete', 'Slides::delete', ['_name' => 'slides:delete']) ->setPatterns($token)->setPass(['id'])->setMethods(['POST']); - $admin->connect('/slides/reorder', 'Slides::reorder', ['_name' => 'slides:reorder']) + $admin->connect('/slides/{id}/duplicate', 'Slides::duplicate', ['_name' => 'slides:duplicate']) + ->setPatterns($token)->setPass(['id'])->setMethods(['POST']); + $admin->connect('/slides/{id}/visibility', 'Slides::visibility', ['_name' => 'slides:visibility']) + ->setPatterns($token)->setPass(['id'])->setMethods(['POST']); + $admin->connect('/slides/reorder','Slides::reorder', ['_name' => 'slides:reorder']) ->setPatterns($token)->setMethods(['POST']); $admin->connect('/slides/youtube-check', 'Slides::youtubeCheck', ['_name' => 'slides:youtube-check']) ->setPatterns($token)->setMethods(['POST']); diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 883c35c..117ff67 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -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]; diff --git a/src/Controller/EmbedController.php b/src/Controller/EmbedController.php index 20262ee..46770f7 100644 --- a/src/Controller/EmbedController.php +++ b/src/Controller/EmbedController.php @@ -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); } diff --git a/src/Controller/SlidesController.php b/src/Controller/SlidesController.php index 0908100..a9fa3ae 100644 --- a/src/Controller/SlidesController.php +++ b/src/Controller/SlidesController.php @@ -43,10 +43,8 @@ class SlidesController extends AdminAppController 'validate' => false, ]); $slide->poll_id = $this->poll->id; - // A quiz is started by the presenter (that also starts its timer). - $slide->is_voting_open = $type !== Slide::TYPE_QUIZ; - // Q&A starts by collecting questions. - $slide->stage = $type === Slide::TYPE_QA ? Slide::QA_COLLECT : null; + // A quiz is started by the presenter (that also starts its timer), Q&A starts by collecting questions. + $slide->startFresh(); $optionsText = $type === Slide::TYPE_CHOICE ? "\n" : ''; $quizOptions = []; $orderOptions = []; @@ -106,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); @@ -126,6 +116,49 @@ 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. + * + * @param string $id Slide id + * @return \Cake\Http\Response|null + */ + public function duplicate(string $id): ?Response + { + $this->request->allowMethod(['post']); + $copy = $this->Slides->duplicate($this->loadSlide($id)); + $this->Flash->success(__('Folie dupliziert. Du bearbeitest jetzt die Kopie.')); + + return $this->redirect($this->adminUrl('slides:edit', ['id' => $copy->id])); + } + /** * Saves a complete new slide order (drag & drop), expects `ids[]` and answers with JSON. * diff --git a/src/Model/Entity/Poll.php b/src/Model/Entity/Poll.php index 407c111..890689e 100644 --- a/src/Model/Entity/Poll.php +++ b/src/Model/Entity/Poll.php @@ -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 */ diff --git a/src/Model/Entity/Slide.php b/src/Model/Entity/Slide.php index cd88f98..1d1e5fc 100644 --- a/src/Model/Entity/Slide.php +++ b/src/Model/Entity/Slide.php @@ -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|null $settings * @property bool $is_voting_open * @property \Cake\I18n\DateTime|null $voting_started_at Quiz: start of the voting window @@ -408,6 +409,21 @@ class Slide extends Entity return max(0, $this->voting_ends_at->getTimestamp() - ($now ?? DateTime::now())->getTimestamp()); } + /** + * Sets the state of a slide that has not been presented yet (new slide, copy): + * a quiz waits for the presenter to start it, Q&A collects questions, others are open. + * + * @return void + */ + public function startFresh(): void + { + $this->is_voting_open = !$this->isQuiz(); + $this->voting_started_at = null; + $this->voting_ends_at = null; + $this->stage = $this->isQa() ? self::QA_COLLECT : null; + $this->focus_response_id = null; + } + /** * Opens or closes voting. Opening a quiz that is not running (re)starts its * voting window and timer; opening a running quiz changes nothing. diff --git a/src/Model/Table/SlidesTable.php b/src/Model/Table/SlidesTable.php index afb3340..3a7e92c 100644 --- a/src/Model/Table/SlidesTable.php +++ b/src/Model/Table/SlidesTable.php @@ -6,6 +6,7 @@ namespace App\Model\Table; use App\Model\Entity\Slide; use App\Service\YouTubeService; use ArrayObject; +use Cake\Database\Expression\QueryExpression; use Cake\Datasource\EntityInterface; use Cake\Event\EventInterface; use Cake\ORM\RulesChecker; @@ -323,6 +324,46 @@ class SlidesTable extends Table }); } + /** + * Copies a slide incl. its settings and options (with the correct answers) and + * puts the copy directly behind the original. Responses are not copied: the copy + * starts like a new slide (quiz not started, Q&A collecting, others open). + * + * @param \App\Model\Entity\Slide $slide Original incl. slide_options + * @return \App\Model\Entity\Slide The saved copy + */ + public function duplicate(Slide $slide): Slide + { + $copy = $this->newEmptyEntity(); + $copy->poll_id = $slide->poll_id; + $copy->type = $slide->type; + $copy->question = mb_substr(__('{0} (Kopie)', $slide->question), 0, 500); + $copy->description = $slide->description; + $copy->settings = $slide->settings; + $copy->position = $slide->position + 1; + $copy->startFresh(); + + return $this->getConnection()->transactional(function () use ($slide, $copy): Slide { + $this->updateAll( + ['position' => new QueryExpression('position + 1')], + ['poll_id' => $slide->poll_id, 'position >' => $slide->position], + ); + $this->saveOrFail($copy); + foreach ($slide->slide_options ?? [] as $option) { + $newOption = $this->SlideOptions->newEntity([ + 'label' => $option->label, + 'position' => $option->position, + ]); + $newOption->set('slide_id', $copy->id); + $newOption->set('is_correct', $option->is_correct); + $this->SlideOptions->saveOrFail($newOption); + } + $this->normalizePositions($slide->poll_id); + + return $this->get($copy->id, contain: ['SlideOptions']); + }); + } + /** * Applies a complete new order (e.g. from drag & drop). * @@ -382,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; + } } diff --git a/src/Service/PollStateService.php b/src/Service/PollStateService.php index 55a7a61..55eb5a6 100644 --- a/src/Service/PollStateService.php +++ b/src/Service/PollStateService.php @@ -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), diff --git a/src/Service/ReportService.php b/src/Service/ReportService.php index 03c923b..5d8b806 100644 --- a/src/Service/ReportService.php +++ b/src/Service/ReportService.php @@ -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 = []; diff --git a/templates/Admin/index.php b/templates/Admin/index.php index e3bb1b9..8f0ab8f 100644 --- a/templates/Admin/index.php +++ b/templates/Admin/index.php @@ -15,7 +15,7 @@ $this->assign('title', $poll->title); $this->assign('noindex', '1'); $url = fn(string $name, array $params = []) => ['_name' => $name, 'token' => $adminToken] + $params; -$hasInternal = array_filter($slides, fn($slide) => $slide->isInteractive() && $slide->isPrivate()) !== []; +$hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide->isInteractive() && $slide->isPrivate()) !== []; ?>
@@ -72,7 +72,7 @@ $hasInternal = array_filter($slides, fn($slide) => $slide->isInteractive() && $s $isCurrent = $poll->current_slide_id === $slide->id; $count = $responseCounts[$slide->id] ?? 0; ?> -
  • +