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
@@ -178,7 +178,7 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures
|
||||
`QaService::MAX_PREPARED`), nur in `collect` sichtbar/änderbar. `QaService::syncPrepared()` gleicht sie idempotent ab (gleiche Texte
|
||||
behalten ihre id, entfernte verschwinden samt Upvotes, von Teilnehmenden schon gestellte werden nicht doppelt angelegt). Gespeichert
|
||||
als normale Fragen mit `participant_hash = VoteService::PREPARED_HASH` (kein gültiger HMAC → niemand kann sie bearbeiten/löschen,
|
||||
jeder darf sie unterstützen); sie zählen nicht als Teilnehmende. Zurücksetzen löscht sie wie alle Antworten, Duplizieren kopiert sie nicht.
|
||||
jeder darf sie unterstützen); sie zählen nicht als Teilnehmende. Zurücksetzen behält sie (außer die Checkbox beim Umfrage-Reset ist abgewählt), Duplizieren kopiert sie nicht.
|
||||
Tests: `QaPreparedTest.php`.
|
||||
Eigene Fragen bearbeiten/löschen (`vote=edit|delete` + `question_id`, `VoteService::editQuestion()`) nur in `collect`:
|
||||
danach könnten Upvotes bzw. die Besprechung an einem anderen Text hängen. Bearbeiten prüft Dubletten ohne die eigene Frage,
|
||||
@@ -203,7 +203,9 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures
|
||||
|
||||
- **Zurücksetzen** (`ResetService`) löscht **nur Antworten**: Folie (`slides:reset`) bzw. alle Folien der Umfrage
|
||||
(`admin:reset`, Dashboard → „Sicherheit“). Nur Quiz (`ready`) und Q&A (`collect`) springen zurück, weil ihre Phasen
|
||||
ohne Antworten keinen Sinn ergeben; offen/geschlossen anderer Folien, aktuelle Folie/Pause, Einstellungen bleiben.
|
||||
ohne Antworten keinen Sinn ergeben; offen/geschlossen anderer Folien und Einstellungen bleiben. Das Zurücksetzen der
|
||||
Umfrage setzt außerdem die Präsentation auf „nicht gestartet“ (`Poll::notStarted()`: weder live noch pausiert). Vorab eingetragene Q&A-Fragen bleiben standardmäßig erhalten (nur ihre Upvotes gehen weg):
|
||||
Folien-Reset behält sie immer, der Umfrage-Reset hat die Checkbox `keep_prepared` (nur sichtbar, wenn es welche gibt).
|
||||
Idempotent, in einer Transaktion. Tests: `PollResetTest.php`.
|
||||
- **Duplizieren** (`slides:duplicate`, POST): kopiert Fragetext (+ „(Kopie)“), Beschreibung, Einstellungen und Optionen
|
||||
inkl. `is_correct`, **nie Antworten**. Die Kopie landet direkt hinter dem Original und startet wie eine neue Folie
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -290,13 +290,22 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide-
|
||||
]) ?>
|
||||
|
||||
<h3><?= __('Umfrage zurücksetzen') ?></h3>
|
||||
<p class="hint"><?= __('Löscht alle Antworten aller Folien, z. B. für eine neue Gruppe. Folien und Einstellungen bleiben erhalten.') ?></p>
|
||||
<p class="hint"><?= __('Löscht alle Antworten aller Folien und setzt die Präsentation auf „nicht gestartet“ zurück, z. B. für eine neue Gruppe. Folien und Einstellungen bleiben erhalten.') ?></p>
|
||||
<?php if ($responseCounts !== []) : ?>
|
||||
<p class="hint"><?= $this->Html->link(__('Ergebnisse vorher als PDF sichern'), '#export') ?></p>
|
||||
<?= $this->Form->postButton(__('Alle Antworten löschen'), $url('admin:reset'), [
|
||||
<?= $this->Form->create(null, ['url' => $url('admin:reset')]) ?>
|
||||
<?php if ($hasPrepared) : ?>
|
||||
<?= $this->Form->control('keep_prepared', [
|
||||
'type' => 'checkbox',
|
||||
'checked' => true,
|
||||
'label' => __('Vorab eingetragene Fragen (Fragen & Antworten) behalten'),
|
||||
]) ?>
|
||||
<?php endif; ?>
|
||||
<?= $this->Form->button(__('Alle Antworten löschen'), [
|
||||
'class' => 'button button--small button--danger',
|
||||
'data-confirm' => __('Alle Antworten aller Folien unwiderruflich löschen?'),
|
||||
]) ?>
|
||||
<?= $this->Form->end() ?>
|
||||
<?php else : ?>
|
||||
<p class="hint"><em><?= __('Noch nichts zurückzusetzen: Es gibt keine Antworten.') ?></em></p>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -55,6 +55,7 @@ class PollResetTest extends TestCase
|
||||
$qa->stage = Slide::QA_DISCUSS;
|
||||
$qa->is_voting_open = false;
|
||||
$this->slidesTable()->saveManyOrFail([$quiz, $order, $qa]);
|
||||
$poll->showSlide($qa->id);
|
||||
$poll->pause();
|
||||
$this->pollsTable()->saveOrFail($poll);
|
||||
|
||||
@@ -66,10 +67,10 @@ class PollResetTest extends TestCase
|
||||
$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');
|
||||
|
||||
// The presentation stays where it is (paused on the choice slide).
|
||||
// The presentation is back to "not started".
|
||||
$poll = $this->pollsTable()->get($poll->id);
|
||||
$this->assertNull($poll->current_slide_id);
|
||||
$this->assertSame($choice->id, $poll->paused_slide_id);
|
||||
$this->assertNull($poll->paused_slide_id);
|
||||
|
||||
$slides = $this->slidesTable();
|
||||
$this->assertSame(Slide::QUIZ_READY, $slides->get($quiz->id)->quizPhase());
|
||||
@@ -82,7 +83,47 @@ class PollResetTest extends TestCase
|
||||
// Idempotent: a second reset changes nothing and does not fail.
|
||||
$this->post("/admin/$token/reset");
|
||||
$this->assertRedirect(['_name' => 'admin', 'token' => $token]);
|
||||
$this->assertSame($choice->id, $this->pollsTable()->get($poll->id)->paused_slide_id);
|
||||
$this->assertNull($this->pollsTable()->get($poll->id)->paused_slide_id);
|
||||
}
|
||||
|
||||
public function testResetStopsLivePresentation(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$this->createSlide($poll, Slide::TYPE_CHOICE);
|
||||
$second = $this->createSlide($poll, Slide::TYPE_CHOICE);
|
||||
$poll = $this->goLive($poll, $second);
|
||||
(new VoteService())->submit($poll, $second, VoteService::participantHash(str_repeat('a', 32), $poll->id), [
|
||||
'option_id' => $second->slide_options[0]->id,
|
||||
]);
|
||||
|
||||
$this->post("/admin/$token/reset");
|
||||
$reloaded = $this->pollsTable()->get($poll->id);
|
||||
$this->assertNull($reloaded->current_slide_id);
|
||||
$this->assertNull($reloaded->paused_slide_id);
|
||||
}
|
||||
|
||||
public function testResetKeepsPreparedQuestionsUnlessAsked(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$qa = $this->createSlide($poll, Slide::TYPE_QA);
|
||||
$responses = TableRegistry::getTableLocator()->get('Responses');
|
||||
$question = $responses->saveOrFail($responses->newEntity([
|
||||
'slide_id' => $qa->id,
|
||||
'participant_hash' => VoteService::PREPARED_HASH,
|
||||
'text_value' => 'Vorbereitet?',
|
||||
], ['accessibleFields' => ['*' => true]]));
|
||||
$responses->saveOrFail($responses->newEntity([
|
||||
'slide_id' => $qa->id,
|
||||
'participant_hash' => VoteService::participantHash(str_repeat('a', 32), $poll->id),
|
||||
'parent_id' => $question->id,
|
||||
], ['accessibleFields' => ['*' => true]]));
|
||||
|
||||
$this->post("/admin/$token/reset");
|
||||
$this->assertSame(1, $responses->find()->where(['slide_id' => $qa->id])->count());
|
||||
$this->assertSame(1, $responses->find()->where(['id' => $question->id])->count());
|
||||
|
||||
$this->post("/admin/$token/reset", ['keep_prepared' => '0']);
|
||||
$this->assertSame(0, $responses->find()->where(['slide_id' => $qa->id])->count());
|
||||
}
|
||||
|
||||
public function testResetRequiresPost(): void
|
||||
|
||||
Reference in new issue
Block a user