Merge pull request 'Reset poll to "not started" and keep prepared Q&A questions' (#75) from feature/reset-not-started into main
Reviewed-on: #75
This commit was merged in pull request #75.
This commit is contained in:
commit
3c66597696
7 files changed
+119
-22
No files matched your search
@@ -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