Reset poll to "not started" and keep prepared Q&A questions
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:
1 parent
19320f01c4
commit
97a60290b4
7 files changed
+119
-22
No files matched your search
@@ -59,7 +59,9 @@ class AdminController extends AdminAppController
|
||||
// Created on first visit, so every slide has its embed URL ready to copy.
|
||||
$embedKey = $this->Polls->ensureEmbedKey($this->poll);
|
||||
|
||||
$this->set(compact('slides', 'responseCounts', 'typeLabels', 'typeDescriptions', 'joinUrl', 'embedKey'));
|
||||
$hasPrepared = $this->Responses->hasPrepared($this->poll->id);
|
||||
|
||||
$this->set(compact('slides', 'responseCounts', 'hasPrepared', 'typeLabels', 'typeDescriptions', 'joinUrl', 'embedKey'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,15 +119,17 @@ class AdminController extends AdminAppController
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all responses of all slides; slides, settings and the presentation are kept
|
||||
* (e.g. to run the poll with another group).
|
||||
* Deletes all responses of all slides and puts the presentation back to "not started"; slides and settings
|
||||
* are kept (e.g. to run the poll with another group). Prepared Q&A questions stay unless
|
||||
* `keep_prepared` is sent as 0.
|
||||
*
|
||||
* @return \Cake\Http\Response|null
|
||||
*/
|
||||
public function reset(): ?Response
|
||||
{
|
||||
$this->request->allowMethod(['post']);
|
||||
(new ResetService())->poll($this->poll);
|
||||
$keepPrepared = $this->request->getData('keep_prepared', '1') !== '0';
|
||||
(new ResetService())->poll($this->poll, $keepPrepared);
|
||||
$this->Flash->success(__('Alle Antworten wurden gelöscht.'));
|
||||
|
||||
return $this->redirect($this->adminUrl());
|
||||
|
||||
@@ -109,6 +109,18 @@ class Poll extends Entity
|
||||
$this->embed_seen_at = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Back to "not started": neither live nor paused. Idempotent.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function notStarted(): void
|
||||
{
|
||||
$this->current_slide_id = null;
|
||||
$this->paused_slide_id = null;
|
||||
$this->embed_seen_at = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A slide leaves the presentation (deleted or hidden). If it was live or is the one a pause
|
||||
* resumes, the poll pauses and resumes with $resumeSlideId instead (null: no slides left =
|
||||
|
||||
@@ -172,6 +172,18 @@ class ResponsesTable extends Table
|
||||
return (int)($row['n'] ?? 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $pollId Poll id
|
||||
* @return bool Whether the poll has Q&A questions entered beforehand
|
||||
*/
|
||||
public function hasPrepared(int $pollId): bool
|
||||
{
|
||||
return $this->find()
|
||||
->innerJoinWith('Slides')
|
||||
->where(['Slides.poll_id' => $pollId, 'Responses.participant_hash' => VoteService::PREPARED_HASH])
|
||||
->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of responding participants per slide of a poll.
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user