From 8644d4bc4a9690f2be762d4acc9cd50788e5d4f8 Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Sun, 8 Nov 2026 20:34:41 +0100 Subject: [PATCH] Make the poll reset only delete responses The presentation (current slide, pause) and the open/closed state of slides are kept. Only quiz and Q&A slides go back to their start, as the per-slide reset already did before. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 11 +++---- src/Controller/AdminController.php | 6 ++-- src/Controller/SlidesController.php | 2 +- src/Model/Entity/Poll.php | 12 -------- src/Service/ResetService.php | 34 +++++++++------------ templates/Admin/index.php | 8 ++--- tests/TestCase/Controller/PollResetTest.php | 18 ++++++----- 7 files changed, 37 insertions(+), 54 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index ee17bbe..574c571 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -69,7 +69,7 @@ src/ YouTubeService YouTube-Links/Timecodes parsen, Watch-/Embed-URLs, Prüfung per oEmbed (Http\Client) QaService Q&A: Phasen wechseln, Fragen nach Upvotes ranken, Fokus beim Besprechen SlideControlService Folien-Aktionen open/close/toggle/stage/question (Presenter und Einbettung gemeinsam) - ResetService Antworten löschen + Ausgangszustand: einzelne Folie (`slide`) bzw. ganze Umfrage (`poll`) + ResetService Antworten löschen: einzelne Folie (`slide`) bzw. alle Folien der Umfrage (`poll`) ReportService Daten für den PDF-Export: Ergebnisse aller interaktiven Folien, mit/ohne interne Inhalte View/PdfView.php Rendert Template als HTML (Layout `pdf`) und wandelt es mit Dompdf in ein PDF templates/ Deutsche UI, Layouts: default, present (Vollbild, dunkel), error, email @@ -162,13 +162,12 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures danach sieht der Presenter die Lösung inkl. „X von N komplett richtig“ und je Eintrag, wie oft er an der richtigen Stelle lag; Teilnehmende nur die Lösung mit eigenen Platzierungen und `order.isCorrect`. Tests: `OrderTest.php`, `OrderSlideTest.php`. -- **Zurücksetzen** (`ResetService`): Folie (`slides:reset`) = alle Antworten löschen und Zustand wie neu angelegt - (Quiz `ready`, Q&A `collect`, alle anderen Typen wieder offen, Reihenfolge also nicht mehr aufgelöst). Umfrage - (`admin:reset`, Dashboard → „Sicherheit“) = das für alle Folien plus Präsentation auf „noch nicht gestartet“ - (`Poll::restart()`); Folien, Einstellungen, Links und Code bleiben. +- **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, aktuelle Folie/Pause, Einstellungen bleiben. Idempotent, in einer Transaktion. Tests: `PollResetTest.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()` / `restart()` setzen, + `paused_slide_id` = noch nicht gestartet. Immer über `Poll::showSlide()` / `showEmbeddedSlide()` / `pause()` setzen, nie `current_slide_id` direkt. Presenter: P pausiert, ←/→ setzt bei der pausierten Folie fort. - **Einbettung** (`/e/{key}/{id}`, `EmbedController`): eigener `embed_key` statt Admin-Token (darf nur diese Folie zeigen, live schalten, pausieren und `SlideControlService`-Aktionen), wird beim ersten Dashboard-Aufruf erzeugt diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index f86d6da..1dbb057 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -123,8 +123,8 @@ class AdminController extends AdminAppController } /** - * Deletes all responses of all slides and starts the presentation over, - * slides, settings and links are kept (e.g. to run the poll with another group). + * Deletes all responses of all slides; slides, settings and the presentation are kept + * (e.g. to run the poll with another group). * * @return \Cake\Http\Response|null */ @@ -132,7 +132,7 @@ class AdminController extends AdminAppController { $this->request->allowMethod(['post']); (new ResetService())->poll($this->poll); - $this->Flash->success(__('Die Umfrage wurde zurückgesetzt: Alle Antworten sind gelöscht, die Präsentation beginnt wieder bei der ersten Folie.')); + $this->Flash->success(__('Alle Antworten wurden gelöscht.')); return $this->redirect($this->adminUrl()); } diff --git a/src/Controller/SlidesController.php b/src/Controller/SlidesController.php index 636d52b..dc51a66 100644 --- a/src/Controller/SlidesController.php +++ b/src/Controller/SlidesController.php @@ -138,7 +138,7 @@ class SlidesController extends AdminAppController } /** - * Deletes all responses of a slide and puts it back to its initial state. + * Deletes all responses of a slide. * * @param string $id Slide id * @return \Cake\Http\Response|null diff --git a/src/Model/Entity/Poll.php b/src/Model/Entity/Poll.php index 8114a06..675e61d 100644 --- a/src/Model/Entity/Poll.php +++ b/src/Model/Entity/Poll.php @@ -99,18 +99,6 @@ class Poll extends Entity $this->embed_seen_at = null; } - /** - * Back to "not started": no slide live, nothing to resume. Idempotent. - * - * @return void - */ - public function restart(): void - { - $this->current_slide_id = null; - $this->paused_slide_id = null; - $this->embed_seen_at = null; - } - /** * @return bool Paused after a slide had been live (not: not started yet) */ diff --git a/src/Service/ResetService.php b/src/Service/ResetService.php index 06fcc9e..eea3602 100644 --- a/src/Service/ResetService.php +++ b/src/Service/ResetService.php @@ -5,22 +5,20 @@ namespace App\Service; use App\Model\Entity\Poll; use App\Model\Entity\Slide; -use App\Model\Table\PollsTable; use App\Model\Table\ResponsesTable; use App\Model\Table\SlidesTable; use Cake\ORM\Locator\LocatorAwareTrait; /** - * Deletes responses and puts slides (and the whole poll) back to their initial state, - * so a poll can be run again. Slides, options, settings, links and the join code are kept. + * Deletes responses of a slide or of the whole poll. Everything else (slides, settings, + * the presentation's current slide) stays; only quiz and Q&A slides go back to their + * start, since their phases make no sense without answers. * Idempotent: resetting twice gives the same result. */ class ResetService { use LocatorAwareTrait; - protected PollsTable $Polls; - protected SlidesTable $Slides; protected ResponsesTable $Responses; @@ -30,9 +28,6 @@ class ResetService */ public function __construct() { - /** @var \App\Model\Table\PollsTable $polls */ - $polls = $this->fetchTable('Polls'); - $this->Polls = $polls; /** @var \App\Model\Table\SlidesTable $slides */ $slides = $this->fetchTable('Slides'); $this->Slides = $slides; @@ -42,9 +37,8 @@ class ResetService } /** - * Deletes all responses of a slide and restores the state of a new slide: - * quiz not started, Q&A collecting, everything else open for voting - * (so orderings are no longer revealed). + * 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. * * @param \App\Model\Entity\Slide $slide Slide * @return void @@ -58,29 +52,29 @@ class ResetService return; } - $slide->is_voting_open = !$slide->isQuiz(); - $slide->voting_started_at = null; - $slide->voting_ends_at = null; - $this->Slides->saveOrFail($slide); + if ($slide->isQuiz()) { + $slide->is_voting_open = false; + $slide->voting_started_at = null; + $slide->voting_ends_at = null; + $this->Slides->saveOrFail($slide); + } }); } /** - * Resets every slide of the poll and the presentation itself (not started, - * no pause, no live embed), so participants see the waiting page. + * Deletes the responses of all slides of the poll (see slide()). + * The presentation stays where it is. * * @param \App\Model\Entity\Poll $poll Poll * @return void */ public function poll(Poll $poll): void { - $this->Polls->getConnection()->transactional(function () use ($poll): void { + $this->Slides->getConnection()->transactional(function () use ($poll): void { foreach ($this->Slides->find()->where(['poll_id' => $poll->id])->all() as $slide) { /** @var \App\Model\Entity\Slide $slide */ $this->slide($slide); } - $poll->restart(); - $this->Polls->saveOrFail($poll); }); } } diff --git a/templates/Admin/index.php b/templates/Admin/index.php index b520c3e..d06239f 100644 --- a/templates/Admin/index.php +++ b/templates/Admin/index.php @@ -237,12 +237,12 @@ $hasInternal = array_filter($slides, fn($slide) => $slide->isInteractive() && $s ]) ?>

-

- current_slide_id !== null || $poll->isPaused()) : ?> +

+

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

- Form->postLink(__('Umfrage zurücksetzen'), $url('admin:reset'), [ + Form->postLink(__('Alle Antworten löschen'), $url('admin:reset'), [ 'class' => 'button button--small button--danger', - 'confirm' => __('Alle Antworten aller Folien unwiderruflich löschen und die Umfrage auf Anfang setzen?'), + 'confirm' => __('Alle Antworten aller Folien unwiderruflich löschen?'), ]) ?>

diff --git a/tests/TestCase/Controller/PollResetTest.php b/tests/TestCase/Controller/PollResetTest.php index ba354a1..4cc9405 100644 --- a/tests/TestCase/Controller/PollResetTest.php +++ b/tests/TestCase/Controller/PollResetTest.php @@ -29,7 +29,7 @@ class PollResetTest extends TestCase $this->enableCsrfToken(); } - public function testResetDeletesAllResponsesAndStartsOver(): void + public function testResetOnlyDeletesResponses(): void { [$poll, $token] = $this->createPoll(); [$other] = $this->createPoll('Andere'); @@ -60,22 +60,21 @@ class PollResetTest extends TestCase $this->post("/admin/$token/reset"); $this->assertRedirect(['_name' => 'admin', 'token' => $token]); - $this->assertFlashMessage('Die Umfrage wurde zurückgesetzt: Alle Antworten sind gelöscht, die Präsentation beginnt wieder bei der ersten Folie.'); + $this->assertFlashMessage('Alle Antworten wurden gelöscht.'); $responses = TableRegistry::getTableLocator()->get('Responses'); $this->assertSame(0, $responses->find()->where(['slide_id IN' => [$choice->id, $quiz->id, $order->id, $qa->id]])->count()); $this->assertSame(1, $responses->find()->where(['slide_id' => $foreign->id])->count(), 'other polls stay untouched'); + // The presentation stays where it is (paused on the choice slide). $poll = $this->pollsTable()->get($poll->id); $this->assertNull($poll->current_slide_id); - $this->assertNull($poll->paused_slide_id); - $this->assertSame($foreign->id, $this->pollsTable()->get($other->id)->current_slide_id); + $this->assertSame($choice->id, $poll->paused_slide_id); $slides = $this->slidesTable(); $this->assertSame(Slide::QUIZ_READY, $slides->get($quiz->id)->quizPhase()); $this->assertNull($slides->get($quiz->id)->voting_started_at); - $this->assertTrue($slides->get($order->id)->is_voting_open); - $this->assertFalse($slides->get($order->id)->isOrderRevealed()); + $this->assertFalse($slides->get($order->id)->is_voting_open, 'open/closed is kept'); $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); @@ -83,7 +82,7 @@ class PollResetTest extends TestCase // Idempotent: a second reset changes nothing and does not fail. $this->post("/admin/$token/reset"); $this->assertRedirect(['_name' => 'admin', 'token' => $token]); - $this->assertNull($this->pollsTable()->get($poll->id)->current_slide_id); + $this->assertSame($choice->id, $this->pollsTable()->get($poll->id)->paused_slide_id); } public function testResetRequiresPost(): void @@ -101,7 +100,10 @@ class PollResetTest extends TestCase $this->assertResponseNotContains("/admin/$token/reset\""); $this->assertResponseContains('Noch nichts zurückzusetzen'); - $this->goLive($poll, $slide); + $poll = $this->goLive($poll, $slide); + (new VoteService())->submit($poll, $slide, VoteService::participantHash(str_repeat('a', 32), $poll->id), [ + 'option_id' => $slide->slide_options[0]->id, + ]); $this->get("/admin/$token"); $this->assertResponseContains("/admin/$token/reset\""); }