Reset poll to "not started" and keep prepared Q&A questions
CI / Deploy / PHP 8.4 (push) Successful in 1m5s
CI / Deploy / PHP 8.5 (push) Successful in 1m7s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Skipped

Resetting a poll now also clears the live/paused slide so the presentation
starts over. Questions entered beforehand on Q&A slides are kept by default
(only their upvotes are removed); the dashboard offers a checkbox to delete
them too. Resetting a single slide always keeps them.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-13 09:52:26 +01:00
1 parent 19320f01c4
commit 97a60290b4
7 files changed
+119 -22

No files matched your search

+28 -11
View File
@@ -10,9 +10,9 @@ use App\Model\Table\SlidesTable;
use Cake\ORM\Locator\LocatorAwareTrait;
/**
* 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.
* 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,
* and resetting the poll puts the presentation back to "not started".
* Idempotent: resetting twice gives the same result.
*/
class ResetService
@@ -40,13 +40,21 @@ 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.
*
* Questions the admin entered beforehand (Q&A) are kept unless $keepPrepared is false;
* only the upvotes on them are removed.
*
* @param \App\Model\Entity\Slide $slide Slide
* @param bool $keepPrepared Keep prepared Q&A questions
* @return void
*/
public function slide(Slide $slide): void
public function slide(Slide $slide, bool $keepPrepared = true): void
{
$this->Slides->getConnection()->transactional(function () use ($slide): void {
$this->Responses->deleteAll(['slide_id' => $slide->id]);
$this->Slides->getConnection()->transactional(function () use ($slide, $keepPrepared): void {
$conditions = ['slide_id' => $slide->id];
if ($keepPrepared) {
$conditions['participant_hash !='] = VoteService::PREPARED_HASH;
}
$this->Responses->deleteAll($conditions);
if ($slide->isQa()) {
(new QaService())->reset($slide);
@@ -62,19 +70,28 @@ class ResetService
}
/**
* Deletes the responses of all slides of the poll (see slide()).
* The presentation stays where it is.
* Deletes the responses of all slides of the poll (see slide()) and puts the
* presentation back to "not started" (no live and no paused slide). Idempotent.
*
* @param \App\Model\Entity\Poll $poll Poll
* @param bool $keepPrepared Keep prepared Q&A questions
* @return void
*/
public function poll(Poll $poll): void
public function poll(Poll $poll, bool $keepPrepared = true): void
{
$this->Slides->getConnection()->transactional(function () use ($poll): void {
$this->Slides->getConnection()->transactional(function () use ($poll, $keepPrepared): void {
foreach ($this->Slides->find()->where(['poll_id' => $poll->id])->all() as $slide) {
/** @var \App\Model\Entity\Slide $slide */
$this->slide($slide);
$this->slide($slide, $keepPrepared);
}
if ($poll->current_slide_id === null && $poll->paused_slide_id === null) {
return;
}
$poll->notStarted();
/** @var \App\Model\Table\PollsTable $polls */
$polls = $this->fetchTable('Polls');
$polls->saveOrFail($poll);
});
}
}