From 0eb054ed295161e01440ae01bab382fd9835b0b4 Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Fri, 13 Nov 2026 10:19:17 +0100 Subject: [PATCH] Reset every slide to the state of a new slide Resetting answers now reopens closed slides (and hides the solution of ordering slides) instead of only restarting quiz and Q&A slides. Co-Authored-By: Claude Sonnet 5.5 --- AGENTS.md | 4 ++-- src/Service/ResetService.php | 20 ++++++-------------- tests/TestCase/Controller/PollResetTest.php | 7 ++++--- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 1bee80f..9528aee 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -205,8 +205,8 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures Teilnehmende nur die Lösung mit eigenen Platzierungen und `order.isCorrect`. Tests: `OrderTest.php`, `OrderSlideTest.php`. - **Zurücksetzen** (`ResetService`) löscht **nur Antworten**: Folie (`slides:reset`) bzw. alle Folien der Umfrage - (`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 und Einstellungen bleiben. Das Zurücksetzen der + (`admin:reset`, Dashboard → „Sicherheit“). Jede Folie geht danach in den Zustand einer neuen Folie (`Slide::startFresh()`: + 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). Idempotent, in einer Transaktion. Tests: `PollResetTest.php`. diff --git a/src/Service/ResetService.php b/src/Service/ResetService.php index d1f49b0..197ce76 100644 --- a/src/Service/ResetService.php +++ b/src/Service/ResetService.php @@ -11,7 +11,7 @@ use Cake\ORM\Locator\LocatorAwareTrait; /** * Deletes responses of a slide or of the whole poll. Everything else (slides, settings) stays; - * quiz and Q&A slides go back to their start, since their phases make no sense without answers, + * every slide goes back to the state of a new one (Slide::startFresh()), * and resetting the poll puts the presentation back to "not started". * Idempotent: resetting twice gives the same result. */ @@ -37,8 +37,8 @@ class ResetService } /** - * Deletes all responses of a slide. A quiz goes back to "not started" - * (so it can be played again), a Q&A slide back to collecting questions. + * Deletes all responses of a slide and puts it back to the state of a new slide: a quiz is + * "not started" (so it can be played again), a Q&A slide collects questions, all others are open. * * Questions the admin entered beforehand (Q&A) are kept unless $keepPrepared is false; * only the upvotes on them are removed. @@ -55,17 +55,9 @@ class ResetService $conditions['participant_hash !='] = VoteService::PREPARED_HASH; } $this->Responses->deleteAll($conditions); - if ($slide->isQa()) { - (new QaService())->reset($slide); - - return; - } - if ($slide->isQuiz()) { - $slide->is_voting_open = false; - $slide->voting_started_at = null; - $slide->voting_ends_at = null; - $this->Slides->saveOrFail($slide); - } + // Back to the state of a new slide: quiz ready, Q&A collecting, everything else open. + $slide->startFresh(); + $this->Slides->saveOrFail($slide); }); } diff --git a/tests/TestCase/Controller/PollResetTest.php b/tests/TestCase/Controller/PollResetTest.php index 4335982..d46c992 100644 --- a/tests/TestCase/Controller/PollResetTest.php +++ b/tests/TestCase/Controller/PollResetTest.php @@ -52,9 +52,10 @@ class PollResetTest extends TestCase $quiz->setVotingOpen(true); $quiz->is_voting_open = false; $order->is_voting_open = false; + $choice->is_voting_open = false; $qa->stage = Slide::QA_DISCUSS; $qa->is_voting_open = false; - $this->slidesTable()->saveManyOrFail([$quiz, $order, $qa]); + $this->slidesTable()->saveManyOrFail([$quiz, $order, $qa, $choice]); $poll->showSlide($qa->id); $poll->pause(); $this->pollsTable()->saveOrFail($poll); @@ -75,10 +76,10 @@ class PollResetTest extends TestCase $slides = $this->slidesTable(); $this->assertSame(Slide::QUIZ_READY, $slides->get($quiz->id)->quizPhase()); $this->assertNull($slides->get($quiz->id)->voting_started_at); - $this->assertFalse($slides->get($order->id)->is_voting_open, 'open/closed is kept'); + $this->assertTrue($slides->get($order->id)->is_voting_open, 'ordering is open again, solution hidden'); $this->assertSame(Slide::QA_COLLECT, $slides->get($qa->id)->qaStage()); $this->assertTrue($slides->get($qa->id)->is_voting_open); - $this->assertTrue($slides->get($choice->id)->is_voting_open); + $this->assertTrue($slides->get($choice->id)->is_voting_open, 'closed slides are open again'); // Idempotent: a second reset changes nothing and does not fail. $this->post("/admin/$token/reset");