From 9c6a19f0de1f1137cfaaa5599f8dcee2ecf8b2ce Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Fri, 13 Nov 2026 10:26:44 +0100 Subject: [PATCH] Offer reset when slides were touched, not only when answers exist The dashboard and per-slide reset buttons only checked for responses, so a started quiz without votes, a closed slide or a running presentation could not be reset. Check Slide::isFresh() and Poll::isStarted() as well. Co-Authored-By: Claude Sonnet 5.5 --- AGENTS.md | 2 ++ src/Controller/AdminController.php | 7 ++++- src/Model/Entity/Poll.php | 8 +++++ src/Model/Entity/Slide.php | 15 +++++++++ templates/Admin/index.php | 24 ++++++++------ tests/TestCase/Controller/PollResetTest.php | 35 +++++++++++++++++++++ 6 files changed, 81 insertions(+), 10 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 9528aee..4ed77ca 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -209,6 +209,8 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures Quiz `ready`, Q&A `collect`, alle anderen offen – bei Reihenfolge bleibt die Lösung so verdeckt); Einstellungen bleiben. Das Zurücksetzen der Umfrage setzt außerdem die Präsentation auf „nicht gestartet“ (`Poll::notStarted()`: weder live noch pausiert). Vorab eingetragene Q&A-Fragen bleiben standardmäßig erhalten (nur ihre Upvotes gehen weg): Folien-Reset behält sie immer, der Umfrage-Reset hat die Checkbox `keep_prepared` (nur sichtbar, wenn es welche gibt). + Die Reset-Buttons (Dashboard, ↺ je Folie) erscheinen nicht nur bei Antworten, sondern auch, wenn eine Folie vom Ausgangszustand abweicht + (`Slide::isFresh()`: Quiz gestartet, Folie geschlossen, Q&A-Phase) oder die Präsentation läuft/pausiert (`Poll::isStarted()`). 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 diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index af8b8c3..cea9232 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -61,7 +61,12 @@ class AdminController extends AdminAppController $hasPrepared = $this->Responses->hasPrepared($this->poll->id); - $this->set(compact('slides', 'responseCounts', 'hasPrepared', 'typeLabels', 'typeDescriptions', 'joinUrl', 'embedKey')); + // Answers are not the only thing a reset undoes: a started quiz, closed slides or a running presentation too. + $canReset = $responseCounts !== [] + || $this->poll->isStarted() + || array_filter($slides, fn(Slide $slide) => !$slide->isFresh()) !== []; + + $this->set(compact('slides', 'responseCounts', 'canReset', 'hasPrepared', 'typeLabels', 'typeDescriptions', 'joinUrl', 'embedKey')); } /** diff --git a/src/Model/Entity/Poll.php b/src/Model/Entity/Poll.php index 1e34ac6..6790b0e 100644 --- a/src/Model/Entity/Poll.php +++ b/src/Model/Entity/Poll.php @@ -140,6 +140,14 @@ class Poll extends Entity $this->embed_seen_at = null; } + /** + * @return bool Live or paused, i.e. not in the state notStarted() sets + */ + public function isStarted(): bool + { + return $this->current_slide_id !== null || $this->paused_slide_id !== null; + } + /** * @return bool Paused after a slide had been live (not: not started yet) */ diff --git a/src/Model/Entity/Slide.php b/src/Model/Entity/Slide.php index 19f85a3..a3a11ef 100644 --- a/src/Model/Entity/Slide.php +++ b/src/Model/Entity/Slide.php @@ -450,6 +450,21 @@ class Slide extends Entity $this->focus_response_id = null; } + /** + * Whether the slide is in the state startFresh() sets (nothing started, closed or discussed yet). + * A reset has nothing to do for such a slide unless it has answers. + * + * @return bool + */ + public function isFresh(): bool + { + return $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/templates/Admin/index.php b/templates/Admin/index.php index f79b7f9..75bd82c 100644 --- a/templates/Admin/index.php +++ b/templates/Admin/index.php @@ -174,12 +174,14 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide- 'data-confirm' => $isCurrent ? __('Diese Folie ist gerade live. Ausblenden und die Umfrage pausieren?') : null, ]) ?> - 0) : ?> + 0 || !$slide->isFresh()) : ?> Form->postButton('↺', $url('slides:reset', ['id' => $slide->id]), [ 'class' => 'button button--small button--icon', - 'title' => __('Zurücksetzen: alle Antworten dieser Folie löschen'), - 'aria-label' => __('Antworten der Folie „{0}“ zurücksetzen', $slide->question), - 'data-confirm' => __('Alle {0} Antworten dieser Folie löschen?', $count), + 'title' => __('Zurücksetzen: Antworten löschen und Folie wie neu starten'), + 'aria-label' => __('Folie „{0}“ zurücksetzen', $slide->question), + 'data-confirm' => $count > 0 + ? __('Alle {0} Antworten dieser Folie löschen und die Folie zurücksetzen?', $count) + : __('Folie zurücksetzen?'), ]) ?> Form->postButton('🗑', $url('slides:delete', ['id' => $slide->id]), [ @@ -291,8 +293,10 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide-

- -

Html->link(__('Ergebnisse vorher als PDF sichern'), '#export') ?>

+ + +

Html->link(__('Ergebnisse vorher als PDF sichern'), '#export') ?>

+ Form->create(null, ['url' => $url('admin:reset')]) ?> Form->control('keep_prepared', [ @@ -301,13 +305,15 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide- 'label' => __('Vorab eingetragene Fragen (Fragen & Antworten) behalten'), ]) ?> - Form->button(__('Alle Antworten löschen'), [ + Form->button($responseCounts !== [] ? __('Alle Antworten löschen') : __('Umfrage zurücksetzen'), [ 'class' => 'button button--small button--danger', - 'data-confirm' => __('Alle Antworten aller Folien unwiderruflich löschen?'), + 'data-confirm' => $responseCounts !== [] + ? __('Alle Antworten aller Folien unwiderruflich löschen?') + : __('Alle Folien zurücksetzen und die Präsentation auf „nicht gestartet“ stellen?'), ]) ?> Form->end() ?> -

+

diff --git a/tests/TestCase/Controller/PollResetTest.php b/tests/TestCase/Controller/PollResetTest.php index d46c992..c711c7f 100644 --- a/tests/TestCase/Controller/PollResetTest.php +++ b/tests/TestCase/Controller/PollResetTest.php @@ -149,4 +149,39 @@ class PollResetTest extends TestCase $this->get("/admin/$token"); $this->assertResponseContains("/admin/$token/reset\""); } + + public function testDashboardOffersResetWithoutAnswersWhenSlidesWereTouched(): void + { + [$poll, $token] = $this->createPoll(); + $quiz = $this->createSlide($poll, Slide::TYPE_QUIZ); + $quiz->startFresh(); + $this->slidesTable()->saveOrFail($quiz); + $choice = $this->createSlide($poll, Slide::TYPE_CHOICE); + $this->get("/admin/$token"); + $this->assertResponseContains('Noch nichts zurückzusetzen'); + + // Quiz started, nobody answered yet. + $quiz->setVotingOpen(true); + $this->slidesTable()->saveOrFail($quiz); + $this->get("/admin/$token"); + $this->assertResponseContains("/admin/$token/reset\""); + $this->assertResponseContains("/admin/$token/slides/{$quiz->id}/reset"); + $this->assertResponseNotContains("/admin/$token/slides/{$choice->id}/reset"); + + // Closed slide. + $quiz->startFresh(); + $this->slidesTable()->saveOrFail($quiz); + $choice->is_voting_open = false; + $this->slidesTable()->saveOrFail($choice); + $this->get("/admin/$token"); + $this->assertResponseContains("/admin/$token/reset\""); + $this->assertResponseContains("/admin/$token/slides/{$choice->id}/reset"); + + // Presentation running. + $choice->startFresh(); + $this->slidesTable()->saveOrFail($choice); + $this->goLive($poll, $choice); + $this->get("/admin/$token"); + $this->assertResponseContains("/admin/$token/reset\""); + } }