Merge pull request 'Allow resetting the whole poll from the dashboard' (#26) from feature/poll-reset into main
Reviewed-on: #26
This commit was merged in pull request #26.
This commit is contained in:
commit
a4e06a1577
8 files changed
+247
-15
No files matched your search
@@ -54,7 +54,7 @@ src/
|
||||
Controller/
|
||||
HomeController Startseite, Anlegen (/create), Bestätigung, Join, Recover
|
||||
AdminAppController Basis für /admin/{token}: löst Poll über Token-Hash auf (404 sonst), setzt Privacy-Header
|
||||
AdminController Dashboard, Settings, Present, State-JSON, Control, QR, PDF-Export, Token rotieren, Löschen
|
||||
AdminController Dashboard, Settings, Present, State-JSON, Control, QR, PDF-Export, Token rotieren, Zurücksetzen, Löschen
|
||||
SlidesController Folien-CRUD, Antworten offener Fragen bzw. Skala-Auswertung (`answers`), Sortieren (Drag & Drop/Pfeiltasten via `reorder`, JSON; erfordert JS), Antworten zurücksetzen,
|
||||
YouTube-Link prüfen (`youtubeCheck`, JSON)
|
||||
ParticipateController /p/{code}: Ansicht, State-JSON, Abstimmen; anonymes Cookie plenario_pid
|
||||
@@ -69,6 +69,7 @@ src/
|
||||
YouTubeService YouTube-Links/Timecodes parsen, Watch-/Embed-URLs, Prüfung per oEmbed (Http\Client)
|
||||
QaService Q&A: Phasen wechseln, Fragen nach Upvotes ranken, Fokus beim Besprechen
|
||||
SlideControlService Folien-Aktionen open/close/toggle/stage/question (Presenter und Einbettung gemeinsam)
|
||||
ResetService Antworten löschen + Ausgangszustand: einzelne Folie (`slide`) bzw. ganze Umfrage (`poll`)
|
||||
ReportService Daten für den PDF-Export: Ergebnisse aller interaktiven Folien, mit/ohne interne Inhalte
|
||||
View/PdfView.php Rendert Template als HTML (Layout `pdf`) und wandelt es mit Dompdf in ein PDF
|
||||
templates/ Deutsche UI, Layouts: default, present (Vollbild, dunkel), error, email
|
||||
@@ -161,8 +162,13 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures
|
||||
danach sieht der Presenter die Lösung inkl. „X von N komplett richtig“ und je Eintrag, wie oft er an der richtigen Stelle lag;
|
||||
Teilnehmende nur die Lösung mit eigenen Platzierungen und `order.isCorrect`. Tests: `OrderTest.php`, `OrderSlideTest.php`.
|
||||
|
||||
- **Zurücksetzen** (`ResetService`): Folie (`slides:reset`) = alle Antworten löschen und Zustand wie neu angelegt
|
||||
(Quiz `ready`, Q&A `collect`, alle anderen Typen wieder offen, Reihenfolge also nicht mehr aufgelöst). Umfrage
|
||||
(`admin:reset`, Dashboard → „Sicherheit“) = das für alle Folien plus Präsentation auf „noch nicht gestartet“
|
||||
(`Poll::restart()`); Folien, Einstellungen, Links und Code bleiben.
|
||||
Idempotent, in einer Transaktion. Tests: `PollResetTest.php`.
|
||||
- **Pause:** `current_slide_id = null` + `paused_slide_id` = Pause (Teilnehmende sehen „Kurze Pause“), ohne
|
||||
`paused_slide_id` = noch nicht gestartet. Immer über `Poll::showSlide()` / `showEmbeddedSlide()` / `pause()` setzen,
|
||||
`paused_slide_id` = noch nicht gestartet. Immer über `Poll::showSlide()` / `showEmbeddedSlide()` / `pause()` / `restart()` setzen,
|
||||
nie `current_slide_id` direkt. Presenter: P pausiert, ←/→ setzt bei der pausierten Folie fort.
|
||||
- **Einbettung** (`/e/{key}/{id}`, `EmbedController`): eigener `embed_key` statt Admin-Token (darf nur diese Folie zeigen,
|
||||
live schalten, pausieren und `SlideControlService`-Aktionen), wird beim ersten Dashboard-Aufruf erzeugt
|
||||
|
||||
@@ -63,6 +63,8 @@ return function (RouteBuilder $routes): void {
|
||||
->setPatterns($token)->setMethods(['POST']);
|
||||
$admin->connect('/rotate-embed-key', 'Admin::rotateEmbedKey', ['_name' => 'admin:rotate-embed'])
|
||||
->setPatterns($token)->setMethods(['POST']);
|
||||
$admin->connect('/reset', 'Admin::reset', ['_name' => 'admin:reset'])
|
||||
->setPatterns($token)->setMethods(['POST']);
|
||||
$admin->connect('/delete', 'Admin::delete', ['_name' => 'admin:delete'])
|
||||
->setPatterns($token)->setMethods(['POST']);
|
||||
$admin->connect('/present', 'Admin::present', ['_name' => 'admin:present'])->setPatterns($token);
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -236,6 +236,18 @@ $hasInternal = array_filter($slides, fn($slide) => $slide->isInteractive() && $s
|
||||
'confirm' => __('Neuen Admin-Link erzeugen? Der aktuelle Link funktioniert danach nicht mehr.'),
|
||||
]) ?>
|
||||
|
||||
<h3><?= __('Umfrage zurücksetzen') ?></h3>
|
||||
<p class="hint"><?= __('Löscht alle Antworten aller Folien und setzt Quiz, Fragerunden und Präsentation auf Anfang – z. B. für eine neue Gruppe. Folien, Einstellungen, Links und Code bleiben erhalten.') ?></p>
|
||||
<?php if ($responseCounts !== [] || $poll->current_slide_id !== null || $poll->isPaused()) : ?>
|
||||
<p class="hint"><?= $this->Html->link(__('Ergebnisse vorher als PDF sichern'), '#export') ?></p>
|
||||
<?= $this->Form->postLink(__('Umfrage zurücksetzen'), $url('admin:reset'), [
|
||||
'class' => 'button button--small button--danger',
|
||||
'confirm' => __('Alle Antworten aller Folien unwiderruflich löschen und die Umfrage auf Anfang setzen?'),
|
||||
]) ?>
|
||||
<?php else : ?>
|
||||
<p class="hint"><em><?= __('Noch nichts zurückzusetzen: Es gibt keine Antworten.') ?></em></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<h3><?= __('Umfrage löschen') ?></h3>
|
||||
<?= $this->Form->create(null, ['url' => $url('admin:delete')]) ?>
|
||||
<?= $this->Form->control('confirm_code', [
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Controller;
|
||||
|
||||
use App\Model\Entity\Slide;
|
||||
use App\Service\VoteService;
|
||||
use App\Test\TestCase\PlenarioTestTrait;
|
||||
use Cake\ORM\TableRegistry;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
/**
|
||||
* Resetting a whole poll from the dashboard (admin:reset).
|
||||
*/
|
||||
class PollResetTest extends TestCase
|
||||
{
|
||||
use IntegrationTestTrait;
|
||||
use PlenarioTestTrait;
|
||||
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses'];
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->enableCsrfToken();
|
||||
}
|
||||
|
||||
public function testResetDeletesAllResponsesAndStartsOver(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
[$other] = $this->createPoll('Andere');
|
||||
$choice = $this->createSlide($poll, Slide::TYPE_CHOICE);
|
||||
$quiz = $this->createSlide($poll, Slide::TYPE_QUIZ, ['is_voting_open' => false], ['Richtig', 'Falsch']);
|
||||
$order = $this->createSlide($poll, Slide::TYPE_ORDER, [], ['A', 'B', 'C']);
|
||||
$qa = $this->createSlide($poll, Slide::TYPE_QA);
|
||||
$foreign = $this->createSlide($other, Slide::TYPE_CHOICE);
|
||||
$votes = new VoteService();
|
||||
$hash = VoteService::participantHash(str_repeat('a', 32), $poll->id);
|
||||
|
||||
$poll = $this->goLive($poll, $choice);
|
||||
$votes->submit($poll, $choice, $hash, ['option_id' => $choice->slide_options[0]->id]);
|
||||
$other = $this->goLive($other, $foreign);
|
||||
$votes->submit($other, $foreign, VoteService::participantHash(str_repeat('a', 32), $other->id), [
|
||||
'option_id' => $foreign->slide_options[0]->id,
|
||||
]);
|
||||
|
||||
// Quiz played and finished, ordering revealed, Q&A in discussion.
|
||||
$quiz->setVotingOpen(true);
|
||||
$quiz->is_voting_open = false;
|
||||
$order->is_voting_open = false;
|
||||
$qa->stage = Slide::QA_DISCUSS;
|
||||
$qa->is_voting_open = false;
|
||||
$this->slidesTable()->saveManyOrFail([$quiz, $order, $qa]);
|
||||
$poll->pause();
|
||||
$this->pollsTable()->saveOrFail($poll);
|
||||
|
||||
$this->post("/admin/$token/reset");
|
||||
$this->assertRedirect(['_name' => 'admin', 'token' => $token]);
|
||||
$this->assertFlashMessage('Die Umfrage wurde zurückgesetzt: Alle Antworten sind gelöscht, die Präsentation beginnt wieder bei der ersten Folie.');
|
||||
|
||||
$responses = TableRegistry::getTableLocator()->get('Responses');
|
||||
$this->assertSame(0, $responses->find()->where(['slide_id IN' => [$choice->id, $quiz->id, $order->id, $qa->id]])->count());
|
||||
$this->assertSame(1, $responses->find()->where(['slide_id' => $foreign->id])->count(), 'other polls stay untouched');
|
||||
|
||||
$poll = $this->pollsTable()->get($poll->id);
|
||||
$this->assertNull($poll->current_slide_id);
|
||||
$this->assertNull($poll->paused_slide_id);
|
||||
$this->assertSame($foreign->id, $this->pollsTable()->get($other->id)->current_slide_id);
|
||||
|
||||
$slides = $this->slidesTable();
|
||||
$this->assertSame(Slide::QUIZ_READY, $slides->get($quiz->id)->quizPhase());
|
||||
$this->assertNull($slides->get($quiz->id)->voting_started_at);
|
||||
$this->assertTrue($slides->get($order->id)->is_voting_open);
|
||||
$this->assertFalse($slides->get($order->id)->isOrderRevealed());
|
||||
$this->assertSame(Slide::QA_COLLECT, $slides->get($qa->id)->qaStage());
|
||||
$this->assertTrue($slides->get($qa->id)->is_voting_open);
|
||||
$this->assertTrue($slides->get($choice->id)->is_voting_open);
|
||||
|
||||
// Idempotent: a second reset changes nothing and does not fail.
|
||||
$this->post("/admin/$token/reset");
|
||||
$this->assertRedirect(['_name' => 'admin', 'token' => $token]);
|
||||
$this->assertNull($this->pollsTable()->get($poll->id)->current_slide_id);
|
||||
}
|
||||
|
||||
public function testResetRequiresPost(): void
|
||||
{
|
||||
[, $token] = $this->createPoll();
|
||||
$this->get("/admin/$token/reset");
|
||||
$this->assertResponseCode(404);
|
||||
}
|
||||
|
||||
public function testDashboardOffersResetOnlyWithSomethingToReset(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$slide = $this->createSlide($poll, Slide::TYPE_CHOICE);
|
||||
$this->get("/admin/$token");
|
||||
$this->assertResponseNotContains("/admin/$token/reset\"");
|
||||
$this->assertResponseContains('Noch nichts zurückzusetzen');
|
||||
|
||||
$this->goLive($poll, $slide);
|
||||
$this->get("/admin/$token");
|
||||
$this->assertResponseContains("/admin/$token/reset\"");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user