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>
81 lines
2.4 KiB
PHP
81 lines
2.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Model\Entity\Poll;
|
|
use App\Model\Entity\Slide;
|
|
use App\Model\Table\ResponsesTable;
|
|
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.
|
|
* Idempotent: resetting twice gives the same result.
|
|
*/
|
|
class ResetService
|
|
{
|
|
use LocatorAwareTrait;
|
|
|
|
protected SlidesTable $Slides;
|
|
|
|
protected ResponsesTable $Responses;
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct()
|
|
{
|
|
/** @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. 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
|
|
*/
|
|
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;
|
|
}
|
|
if ($slide->isQuiz()) {
|
|
$slide->is_voting_open = false;
|
|
$slide->voting_started_at = null;
|
|
$slide->voting_ends_at = null;
|
|
$this->Slides->saveOrFail($slide);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 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->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);
|
|
}
|
|
});
|
|
}
|
|
}
|