Make the poll reset only delete responses
CI / Deploy / test (push) Successful in 52s
CI / Deploy / deploy (push) Skipped

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 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-08 20:34:41 +01:00
1 parent e1b327899f
commit 8644d4bc4a
7 files changed
+37 -54

No files matched your search

+3 -3
View File
@@ -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());
}
+1 -1
View File
@@ -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
-12
View File
@@ -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)
*/
+14 -20
View File
@@ -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);
});
}
}