Allow resetting the whole poll from the dashboard
Deletes all responses of all slides, puts every slide back to its initial state and restarts the presentation. Slides, settings, links and the join code are kept. The per-slide reset shares the logic via ResetService and now also reopens closed slides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ee593da0e6
commit
e1b327899f
8 files changed
+247
-15
No files matched your search
@@ -10,6 +10,7 @@ use App\Model\Table\SlidesTable;
|
||||
use App\Service\PollStateService;
|
||||
use App\Service\QaService;
|
||||
use App\Service\ReportService;
|
||||
use App\Service\ResetService;
|
||||
use App\Service\SlideControlService;
|
||||
use App\View\PdfView;
|
||||
use Cake\Core\Configure;
|
||||
@@ -121,6 +122,21 @@ class AdminController extends AdminAppController
|
||||
return $this->redirect($this->adminUrl() + ['#' => 'embed']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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).
|
||||
*
|
||||
* @return \Cake\Http\Response|null
|
||||
*/
|
||||
public function reset(): ?Response
|
||||
{
|
||||
$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.'));
|
||||
|
||||
return $this->redirect($this->adminUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the whole poll incl. slides and responses.
|
||||
*
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace App\Controller;
|
||||
|
||||
use App\Model\Entity\Slide;
|
||||
use App\Model\Table\SlidesTable;
|
||||
use App\Service\QaService;
|
||||
use App\Service\ResetService;
|
||||
use App\Service\ResultsService;
|
||||
use App\Service\YouTubeService;
|
||||
use Cake\Http\Exception\NotFoundException;
|
||||
@@ -138,7 +138,7 @@ class SlidesController extends AdminAppController
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all responses of a slide.
|
||||
* Deletes all responses of a slide and puts it back to its initial state.
|
||||
*
|
||||
* @param string $id Slide id
|
||||
* @return \Cake\Http\Response|null
|
||||
@@ -147,17 +147,7 @@ class SlidesController extends AdminAppController
|
||||
{
|
||||
$this->request->allowMethod(['post']);
|
||||
$slide = $this->loadSlide($id);
|
||||
$this->Slides->Responses->deleteAll(['slide_id' => $slide->id]);
|
||||
if ($slide->isQuiz()) {
|
||||
// Back to "not started" so the quiz can be played again.
|
||||
$slide->is_voting_open = false;
|
||||
$slide->voting_started_at = null;
|
||||
$slide->voting_ends_at = null;
|
||||
$this->Slides->saveOrFail($slide);
|
||||
}
|
||||
if ($slide->isQa()) {
|
||||
(new QaService())->reset($slide);
|
||||
}
|
||||
(new ResetService())->slide($slide);
|
||||
$this->Flash->success(__('Antworten der Folie „{0}“ wurden gelöscht.', $slide->question));
|
||||
|
||||
return $this->redirect($this->adminUrl());
|
||||
|
||||
@@ -99,6 +99,18 @@ 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)
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
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.
|
||||
* Idempotent: resetting twice gives the same result.
|
||||
*/
|
||||
class ResetService
|
||||
{
|
||||
use LocatorAwareTrait;
|
||||
|
||||
protected PollsTable $Polls;
|
||||
|
||||
protected SlidesTable $Slides;
|
||||
|
||||
protected ResponsesTable $Responses;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
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;
|
||||
/** @var \App\Model\Table\ResponsesTable $responses */
|
||||
$responses = $this->fetchTable('Responses');
|
||||
$this->Responses = $responses;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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).
|
||||
*
|
||||
* @param \App\Model\Entity\Slide $slide Slide
|
||||
* @return void
|
||||
*/
|
||||
public function slide(Slide $slide): void
|
||||
{
|
||||
$this->Slides->getConnection()->transactional(function () use ($slide): void {
|
||||
$this->Responses->deleteAll(['slide_id' => $slide->id]);
|
||||
if ($slide->isQa()) {
|
||||
(new QaService())->reset($slide);
|
||||
|
||||
return;
|
||||
}
|
||||
$slide->is_voting_open = !$slide->isQuiz();
|
||||
$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.
|
||||
*
|
||||
* @param \App\Model\Entity\Poll $poll Poll
|
||||
* @return void
|
||||
*/
|
||||
public function poll(Poll $poll): void
|
||||
{
|
||||
$this->Polls->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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user